JuliaDynamics / Agents.jl

Agent-based modeling framework in Julia
https://juliadynamics.github.io/Agents.jl/stable/
MIT License
712 stars 114 forks source link

"MethodError: no method matching..." with default agent attribute values. #983

Closed jlambvo closed 4 months ago

jlambvo commented 4 months ago

Following the new 6.0.0 macro for defining agents, I'd like to be able to add agents with default values for all additional attributes. However, I get a no matching method error unless I supply at least one keyword argument for additional attributes, or positional arguments for all. If I supply one karg, defaults are applied for other attributes.

Is this expected behavior?

Minimum working example mostly copied and pasted from source comments:

using Agents
using Graphs
@agent struct Agent(GraphAgent)
    w::Float64 = 0.1
    k::Bool = false
end
model = StandardABM(Agent, GraphSpace(complete_digraph(5)))

add_agent!(model; w = 0.5, k = true)
add_agent!(model; w = 0.5)
add_agent!(model; k = true)
add_agent!(model)

See my results:

image

Tortar commented 4 months ago

No, this is not intended, thank you for reporting it, it should be fixed as soon as #984 is merged