Store pointer in Neighbourhood Search grid instead of Agents#1594
Merged
Conversation
Contributor
Author
Ozaq
reviewed
Jun 2, 2026
Ozaq
approved these changes
Jun 3, 2026
Contributor
Ozaq
left a comment
There was a problem hiding this comment.
Looks good!
Please clean up the commits as we can merge this.
5054404 to
5d624e2
Compare
Instead of saving agent copies on grid we moved to storing const pointers Agents are now conationed in deque no longer vector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Currently, the Neighbourhood Search stores all agents on a 2D-grid.
This is done by storing a copy of the Agent in a vector per grid point.
Essentially, this means that all agents are stored 2 times: once in the overall vector containing the agents and once on the grid inside Neighbourhood search.
If a model or another function requests all agents within a certain range, the agents are copied again into a new vector that is returned.
In this PR, I propose to store not the agent itself on the grid but rather a pointer to that agent. This removes the additional copy of alle agents in the neighbourhood system.
To make sure that theses references are valid during an iteration cycle, the container holding the agents is changed from a
std::vectorto astd::deque. In general, the container holding the agents is now defined inGenericAgent.hppand used throughout the codebase.I also removed the
AddAgentcall to the neighbourhood system, since the neighbourhood system is updated in the iteration cycle anyhow. One possibility, where the neighbourhood system would be empty is ifAgentsInPolygonorAgentsInRangeis called, therefore a grid update is performed prior to getting the neighbours. Potentially, a state variable could be useful if these functions are called often.I also added a performance test with 15k agents in a large geometry, as well as a notebook that can be used to draw box plots for the timing results of various program components.
Optionally, I also added a function that gets the pointers of the agents in a certain range instead of a copy of the agent, I also include it in my benchmark comparison.
Preview: https://PedestrianDynamics.github.io/jupedsim/pull-requests/1594/