Skip to content

Commit

Permalink
Also removes an agent from the neighborhood search if it is removed e…
Browse files Browse the repository at this point in the history
…xplicitly
  • Loading branch information
schroedtert authored and Ozaq committed Jul 26, 2023
1 parent e3cbe08 commit c4dcae8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libsimulator/src/NeighborhoodSearch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,21 @@ class NeighborhoodSearch
vec.push_back(item);
}

void RemoveAgent(const Value& item)
{
for(auto& [_, agents] : _grid) {
const auto iter =
std::find_if(std::begin(agents), std::end(agents), [item](auto& agent) {
return agent.id == item.id;
});
if(iter != std::end(agents)) {
agents.erase(iter);
return;
}
}
throw SimulationError("Unknown agent id {}", item.id);
}

void Update(const std::vector<Value>& items)
{
_grid.clear();
Expand Down
1 change: 1 addition & 0 deletions libsimulator/src/Simulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ void TypedSimulation<T>::RemoveAgent(GenericAgent::ID id)
throw SimulationError("Unknown agent id {}", id);
}
_agents.erase(iter);
_neighborhoodSearch.RemoveAgent(*iter);
}

template <typename T>
Expand Down

0 comments on commit c4dcae8

Please sign in to comment.