Skip to content
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

Error if deletion of agent fails #1073

Merged
merged 7 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Agents"
uuid = "46ada45e-f475-11e8-01d0-f70cc89e6671"
authors = ["George Datseris", "Tim DuBois", "Aayush Sabharwal", "Ali Vahdati", "Adriano Meligrana"]
version = "6.1.5"
version = "6.1.6"

[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Expand Down
1 change: 1 addition & 0 deletions src/spaces/continuous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function remove_agent_from_space!(
)
prev = abmspace(model).grid.stored_ids[cell_index...]
ai = findfirst(i -> i == a.id, prev)
isnothing(ai) && error(lazy"Tried to remove agent with ID $(a.id) from the space, but that agent is not on the space")
deleteat!(prev, ai)
return a
end
Expand Down
10 changes: 6 additions & 4 deletions src/spaces/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ end
#######################################################################################
random_position(model::ABM{<:GraphSpace}) = rand(abmrng(model), 1:nv(model))

function remove_agent_from_space!(agent::AbstractAgent, model::ABM{<:GraphSpace})
agentpos = agent.pos
function remove_agent_from_space!(a::AbstractAgent, model::ABM{<:GraphSpace})
agentpos = a.pos
ids = ids_in_position(agentpos, model)
deleteat!(ids, findfirst(a -> a == agent.id, ids))
return model
ai = findfirst(id -> id == a.id, ids)
isnothing(ai) && error(lazy"Tried to remove agent with ID $(a.id) from the space, but that agent is not on the space")
deleteat!(ids, ai)
return a
end

function add_agent_to_space!(agent::AbstractAgent, model::ABM{<:GraphSpace})
Expand Down
Loading