Commit 75b80a13 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

fix LinkedCellGrid

* remove duplicated 'move' call in osm sequential update schema.
* add 'dirtyFlag' to topography LinkedCellGrid for pedestrians and
  cars. For instance the BHM model does not update the LinkedCellGrid
  in one simulation step.
parent 1a596a8a
Pipeline #83174 failed with stages
in 108 minutes and 15 seconds
......@@ -63,5 +63,6 @@ public class OfflineTopographyController {
for (Car car : this.topography.getElements(Car.class)) {
this.topography.getSpatialMap(Car.class).addObject(car);
}
this.topography.setRecomputeCells(false);
}
}
......@@ -306,6 +306,10 @@ public class Simulation {
for (Model m : models) {
m.update(simTimeInSec);
if (topography.isRecomputeCells()){
// rebuild CellGrid if model does not manage the CellGrid state while updating
topographyController.update(simTimeInSec); //rebuild CellGrid
}
}
if (topographyController.getTopography().hasTeleporter()) {
......
......@@ -128,6 +128,7 @@ public class BehaviouralHeuristicsModel implements MainModel {
}
}
}
topography.setRecomputeCells(true);
}
@Override
......
......@@ -74,6 +74,20 @@ public interface UpdateSchemeOSM extends DynamicElementRemoveListener<Pedestrian
}
}
/**
* Moves the pedestrian inside the topography. The pedestrian object already has the new
* location (Vpoint to) stored within its position attribute. This method only informs the
* topography object of the change in state.
*
* !IMPORTANT! this function must be called ONLY ONCE for each pedestrian for each position. To
* allow preformat selection of a pedestrian the managing destructure is not idempotent (cannot
* be applied multiple time without changing result).
*
* @param topography manages simulation data
* @param pedestrian moving pedestrian. This object's position is already set.
* @param from old position
* @param to new position (same as #pedestrian.getPosition())
*/
default void movePedestrian(@NotNull final Topography topography, @NotNull final PedestrianOSM pedestrian, @NotNull final VPoint from, @NotNull final VPoint to) {
pedestrian.setPosition(to);
synchronized (topography) {
......@@ -81,6 +95,19 @@ public interface UpdateSchemeOSM extends DynamicElementRemoveListener<Pedestrian
}
}
/**
* Prepare move of pedestrian inside the topography. The pedestrian object already has the new
* location (Vpoint to) stored within its position attribute. This method only informs the
* topography object of the change in state.
*
* !IMPORTANT! this function calls movePedestrian which must be called ONLY ONCE for each
* pedestrian for each position. To allow preformat selection of a pedestrian the managing
* destructure is not idempotent (cannot be applied multiple time without changing result).
*
* @param topography manages simulation data
* @param pedestrian moving pedestrian. This object's position is already set.
* @param stepTime time in seconds used for the step.
*/
default void makeStep(@NotNull final Topography topography, @NotNull final PedestrianOSM pedestrian, final double stepTime) {
VPoint currentPosition = pedestrian.getPosition();
VPoint nextPosition = pedestrian.getNextPosition();
......
......@@ -46,7 +46,6 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM {
makeStep(topography, pedestrian, timeStepInSec);
}
topography.moveElement(pedestrian, oldPosition);
} else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep());
}
......
......@@ -72,6 +72,7 @@ public class Topography implements DynamicElementMover{
private transient final DynamicElementContainer<Pedestrian> pedestrians;
private transient final DynamicElementContainer<Car> cars;
private boolean recomputeCells;
private AttributesAgent attributesPedestrian;
private AttributesCar attributesCar;
......@@ -116,6 +117,7 @@ public class Topography implements DynamicElementMover{
this.pedestrians = new DynamicElementContainer<>(bounds, CELL_SIZE);
this.cars = new DynamicElementContainer<>(bounds, CELL_SIZE);
recomputeCells = false;
this.obstacleDistanceFunction = p -> obstacles.stream().map(obs -> obs.getShape()).map(shape -> shape.distance(p)).min(Double::compareTo).orElse(Double.MAX_VALUE);
......@@ -231,6 +233,14 @@ public class Topography implements DynamicElementMover{
((DynamicElementContainer<T>) getContainer(element.getClass())).moveElement(element, oldPosition);
}
public boolean isRecomputeCells() {
return recomputeCells;
}
public void setRecomputeCells(boolean recomputeCells) {
this.recomputeCells = recomputeCells;
}
public List<Source> getSources() {
return sources;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment