Skip to content

Store pointer in Neighbourhood Search grid instead of Agents#1594

Merged
Ozaq merged 2 commits into
PedestrianDynamics:masterfrom
pitsteinbach:agent-container
Jun 3, 2026
Merged

Store pointer in Neighbourhood Search grid instead of Agents#1594
Ozaq merged 2 commits into
PedestrianDynamics:masterfrom
pitsteinbach:agent-container

Conversation

@pitsteinbach
Copy link
Copy Markdown
Contributor

@pitsteinbach pitsteinbach commented May 29, 2026

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::vector to a std::deque. In general, the container holding the agents is now defined in GenericAgent.hpp and used throughout the codebase.

I also removed the AddAgent call 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 if AgentsInPolygon or AgentsInRange is 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/

github-actions Bot added a commit that referenced this pull request May 29, 2026
@pitsteinbach
Copy link
Copy Markdown
Contributor Author

Timing comparison for the changes implemented in this PR compared to the master branch.

30-35 % speed-up in the neighbourhood search program part.
The agent removal is not considerably slower, however it is a very small part of the overall compute time.

The influence on the overall runtime is very small, however the memory footprint is considerably smaller.

Open for discussion on which part of the PR, we want to use!

evac_15k_timng_comp

github-actions Bot added a commit that referenced this pull request May 29, 2026
github-actions Bot added a commit that referenced this pull request May 29, 2026
github-actions Bot added a commit that referenced this pull request May 29, 2026
Comment thread libsimulator/src/NeighborhoodSearch.hpp Outdated
Comment thread libsimulator/src/GenericAgent.hpp
Comment thread libsimulator/src/Simulation.cpp Outdated
Comment thread libsimulator/src/Simulation.cpp Outdated
github-actions Bot added a commit that referenced this pull request Jun 3, 2026
github-actions Bot added a commit that referenced this pull request Jun 3, 2026
github-actions Bot added a commit that referenced this pull request Jun 3, 2026
github-actions Bot added a commit that referenced this pull request Jun 3, 2026
@pitsteinbach pitsteinbach requested a review from Ozaq June 3, 2026 11:04
Copy link
Copy Markdown
Contributor

@Ozaq Ozaq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Please clean up the commits as we can merge this.

Instead of saving agent copies on grid we moved to storing const pointers
Agents are now conationed in deque no longer vector
@Ozaq Ozaq force-pushed the agent-container branch from 5d624e2 to 6708493 Compare June 3, 2026 13:16
github-actions Bot added a commit that referenced this pull request Jun 3, 2026
@Ozaq Ozaq merged commit 53ed876 into PedestrianDynamics:master Jun 3, 2026
54 checks passed
@Ozaq Ozaq deleted the agent-container branch June 3, 2026 14:05
github-actions Bot pushed a commit that referenced this pull request Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants