-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing type signature in remove_all_from_space!
method for discrete space?
#1104
Comments
No, And yes, definitely the above method is only valid for discrete spaces. |
Maybe I'm missing something. This is what happens: using Agents
struct DummySpace <: Agents.AbstractSpace
ids::Vector{Int}
end
DummySpace() = DummySpace(Int[])
Agents.random_position(::ABM{<:DummySpace}) = nothing
function Agents.add_agent_to_space!(agent::Agents.AbstractAgent, model::ABM{<:DummySpace})
space = Agents.abmspace(model)
push!(space.ids, agent.id)
return agent
end
function Agents.remove_agent_from_space!(agent::Agents.AbstractAgent, model::ABM{<:DummySpace})
space = Agents.abmspace(model)
ai = findfirst(i -> i == agent.id, space.ids)
deleteat!(space.ids, ai)
return agent
end
@agent struct DummyAgent(NoSpaceAgent)
pos::Nothing
end
model = StandardABM(DummyAgent, DummySpace(); agent_step! = (a, m) -> a)
add_agent!(DummyAgent, model)
add_agent!(DummyAgent, model)
add_agent!(DummyAgent, model)
remove_all!(model) This is where the wrong method is hit:
|
https://github.com/JuliaDynamics/Agents.jl/blob/main/src/core/space_interaction_API.jl#L153-L157 Right, I see now. We've created this for performance, as it is faster to remove all agents at once rather than looping over and removing each individual agent. However, the function function remove_all_from_space!(model)
for a in allagents(model); remove_agent_from_space!(a, model); end
end Do you mind putting in a quick PR? |
In the dev docs under the section of optional extensions teh function |
Sure, I'll get it done soon! |
Is this method supposed to be a generic fallback or not? If not (as I would guess) it should probably be restricted to
model::ABM{<:DiscreteSpace}
.Agents.jl/src/spaces/discrete.jl
Lines 304 to 308 in 24bd774
When defining a new space, and absent this fallback, it seems like the mandatory interface to be defined would also include
remove_all_from_space!
. However, this is currently not listed in the docs. Therefore, when I implemented a new space and did not define a method for this function, I hit the method above.The text was updated successfully, but these errors were encountered: