-
-
Notifications
You must be signed in to change notification settings - Fork 69
Closed
Labels
enhancementRelease notes labelRelease notes labelsprintA task that might be good to tackle during sprints!A task that might be good to tackle during sprints!
Milestone
Description
What's the problem this feature will solve?
Mesa-Geo uses RTree for spatial indexing of GeoAgents. When such indexing is not necessary (e.g., no neighborhood queries are needed), it could be a performance bottleneck, especially if there's a huge number of GeoAgents. See wang-boyu/agents-and-networks-in-python#2.
On the other hand, when indexing is actually needed, it happens only when adding agents:
Lines 292 to 308 in a12f735
| def add_agents(self, agents): | |
| """Add a list of GeoAgents to the layer without checking their crs. | |
| GeoAgents must have the same crs to avoid incorrect spatial indexing results. | |
| To change the crs of a GeoAgent, use `GeoAgent.to_crs()` method. Refer to | |
| `GeoSpace._check_agent()` as an example. | |
| This function may also be called with a single GeoAgent. | |
| Args: | |
| agents: List of GeoAgents, or a single GeoAgent, to be added into the layer. | |
| """ | |
| if isinstance(agents, GeoAgent): | |
| agent = agents | |
| self.idx.insert(id(agent), agent.geometry.bounds, None) | |
| self.idx.agents[id(agent)] = agent | |
| else: | |
| self._recreate_rtree(agents) |
Whenever agents move and need re-index, users need to manually call GeoSpace._recreate_rtree(). For example:
mesa-geo/examples/geo_sir/model.py
Line 109 in a12f735
| self.space._recreate_rtree() # Recalculate spatial tree, because agents are moving |
Describe the solution you'd like
- Do not perform spatial indexing when it is not needed.
- When spatial indexing is needed, automatically keep track of agents' movements and re-index accordingly.
Metadata
Metadata
Assignees
Labels
enhancementRelease notes labelRelease notes labelsprintA task that might be good to tackle during sprints!A task that might be good to tackle during sprints!