Class SpatialIndex<A extends Agent>
java.lang.Object
com.eco.bio7.simulation.SpatialIndex<A>
- Type Parameters:
A- the class of the agents
A fast search of the agents near a position: the agents are sorted into the
cells of a grid (the positions when the index is built). A search looks only
into the cells near the position, so the neighbors of all agents cost about
n instead of n * n distances (e.g., a flock of thousands of boids). The
results are in the order of the list of the agents (the same results as
AgentModel.neighbors(Agent, double), in Java and in the HTML page).
SpatialIndex<Boid> index = index(radius); // in step(): the positions at the start of the step
for (Boid b : agents) {
for (Boid o : index.neighbors(b, radius)) {
...
}
}
A good cell size is the radius of the searches. Build the index again when
the agents have moved (e.g., once in each step).-
Constructor Summary
ConstructorsConstructorDescriptionSpatialIndex(List<A> agents, double cellSize) An index of the agents (their positions now) with the size of the cells (e.g., the radius of the searches). -
Method Summary
Modifier and TypeMethodDescriptionvoidforEachPair(double radius, BiConsumer<A, A> action) Calls the action for each pair of agents within the radius (once for a pair: a before b in the list).near(double px, double py, double pz, double radius) The agents within the radius of the point (in the order of the list).The nearest other agent within the radius (null if none; the first in the list for equal distances).The other agents within the radius of the agent (its position when the index was built; in the order of the list).intsize()The number of the agents in the index.
-
Constructor Details
-
SpatialIndex
-
-
Method Details
-
near
-
neighbors
-
nearest
-
forEachPair
Calls the action for each pair of agents within the radius (once for a pair: a before b in the list). -
size
public int size()The number of the agents in the index.
-