Commit 272e9bdf authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

osmGPU small improvements.

parent d8e644f4
......@@ -29,8 +29,6 @@ import org.vadere.simulator.models.potential.fields.PotentialFieldObstacle;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesFloorField;
import org.vadere.state.attributes.models.AttributesOSM;
import org.vadere.state.attributes.models.AttributesPotentialCompact;
import org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.DynamicElementRemoveListener;
......
......@@ -297,4 +297,8 @@ public class PedestrianOSM extends Pedestrian {
throw new RuntimeException("clone is not supported for PedestrianOSM; it seems hard to implement.");
}
@Override
public String toString() {
return "id = " + getId() + " memory " + super.toString();
}
}
......@@ -34,6 +34,7 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
while (pedestrianEventsQueue.peek().getTimeOfNextStep() < currentTimeInSec) {
PedestrianOSM ped = pedestrianEventsQueue.poll();
update(ped, currentTimeInSec);
//System.out.println(ped.getId());
pedestrianEventsQueue.add(ped);
}
}
......@@ -70,14 +71,19 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
* Compares the time of the next possible move.
*/
private class ComparatorPedestrianOSM implements Comparator<PedestrianOSM> {
@Override
public int compare(PedestrianOSM ped1, PedestrianOSM ped2) {
// TODO [priority=low] [task=refactoring] use Double.compare() oder compareTo()
if (ped1.getTimeOfNextStep() < ped2.getTimeOfNextStep()) {
return -1;
} else {
return 1;
int timeCompare = Double.compare(ped1.getTimeOfNextStep(), ped2.getTimeOfNextStep());
if(timeCompare != 0) {
return timeCompare;
}
else {
if(ped1.getId() < ped2.getId()) {
return -1;
}
else {
return 1;
}
}
}
}
......
package org.vadere.simulator.models.osm.updateScheme;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.state.scenario.Topography;
......@@ -11,6 +13,8 @@ import java.util.List;
public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
private final static Logger logger = LogManager.getLogger(UpdateSchemeEventDrivenParallel.class);
private final Topography topography;
private LinkedCellsGrid<PedestrianOSM> linkedCellsGrid;
private boolean[][] locked;
......@@ -25,23 +29,36 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
@Override
public void update(final double timeStepInSec, final double currentTimeInSec) {
/*for(PedestrianOSM pedestrianOSM : topography.getElements(PedestrianOSM.class)) {
pedestrianOSM.clearStrides();
}
if(!pedestrianEventsQueue.isEmpty()) {
// event driven update ignores time credits!
while (pedestrianEventsQueue.peek().getTimeOfNextStep() < currentTimeInSec) {
PedestrianOSM ped = pedestrianEventsQueue.poll();
update(ped, currentTimeInSec);
pedestrianEventsQueue.add(ped);
}
}*/
double maxStepSize = 0;
double maxDesiredSpeed = 0;
for(PedestrianOSM pedestrianOSM : topography.getElements(PedestrianOSM.class)) {
pedestrianOSM.clearStrides();
maxStepSize = Math.max(pedestrianOSM.getStepSize(), maxStepSize);
maxDesiredSpeed = Math.max(pedestrianOSM.getDesiredSpeed(), maxDesiredSpeed);
}
int counter = 1;
// event driven update ignores time credits
do{
linkedCellsGrid = new LinkedCellsGrid<>(new VRectangle(topography.getBounds()), pedestrianPotentialWidth + maxStepSize);
double stepSize = Math.max(maxStepSize, maxDesiredSpeed * timeStepInSec);
linkedCellsGrid = new LinkedCellsGrid<>(new VRectangle(topography.getBounds()), 2*(pedestrianPotentialWidth + stepSize));
locked = new boolean[linkedCellsGrid.getGridWidth()][linkedCellsGrid.getGridHeight()];
for(PedestrianOSM pedestrianOSM : topography.getElements(PedestrianOSM.class)) {
linkedCellsGrid.addObject(pedestrianOSM);
}
List<PedestrianOSM> parallelUpdatablePeds = new ArrayList<>();
List<PedestrianOSM> unUpdatablePedsd = new ArrayList<>();
......@@ -51,23 +68,29 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
if(!locked[gridPos[0]][gridPos[1]]) {
parallelUpdatablePeds.add(ped);
for(int y = -1; y <= 1; y++) {
for(int x = -1; x <= 1; x++) {
locked[gridPos[0]+x][gridPos[1]+y] = true;
}
}
}
else {
unUpdatablePedsd.add(ped);
}
}
for(int y = -1; y <= 1; y++) {
for(int x = -1; x <= 1; x++) {
int col = Math.min(locked.length-1, Math.max(0, gridPos[0]+x));
int row = Math.min(locked[0].length-1, Math.max(0, gridPos[1]+y));
locked[col][row] = true;
}
}
}
logger.info("update " + parallelUpdatablePeds.size() + " in parallel in round " + counter + ".");
parallelUpdatablePeds.parallelStream().forEach(ped -> {
//logger.info(ped.getTimeOfNextStep());
//System.out.println(ped.getId());
update(ped, currentTimeInSec);
});
pedestrianEventsQueue.addAll(unUpdatablePedsd);
pedestrianEventsQueue.addAll(parallelUpdatablePeds);
counter++;
} while (!pedestrianEventsQueue.isEmpty() && pedestrianEventsQueue.peek().getTimeOfNextStep() < currentTimeInSec);
}
......
......@@ -35,7 +35,7 @@ public interface UpdateSchemeOSM extends DynamicElementRemoveListener<Pedestrian
case EVENT_DRIVEN: return new UpdateSchemeEventDriven(topography);
case SHUFFLE: return new UpdateSchemeShuffle(topography, random);
//TODO: magic number!
case EVENT_DRIVEN_PARALLEL: return new UpdateSchemeEventDrivenParallel(topography, 0.5);
case EVENT_DRIVEN_PARALLEL: return new UpdateSchemeEventDrivenParallel(topography, 0.6);
default: throw new IllegalArgumentException(updateType + " is not supported.");
}
}
......
Supports Markdown
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