Commit e4ec0e4c authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Deleted Git merge artifacts suffixed with ".orig".

parent c7a831d5
{
"name" : "rimea_14_select_route_pso",
"description" : "",
<<<<<<< HEAD:VadereModelTests/TestOSM/scenarios/rimea_14_selectRoute_osm1.scenario
"release" : "0.3",
=======
"release" : "0.6",
>>>>>>> master:VadereModelTests/TestOSM/scenarios/rimea_14_select_route_pso.scenario
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "postvis.trajectories",
"processors" : [ 1 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
"id" : 1
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.MaxOverlapProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesMaxOverlapProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 2
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 2
}
} ],
"isTimestamped" : true
},
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesFloorField" : {
"createMethod" : "HIGH_ACCURACY_FAST_MARCHING",
"potentialFieldResolution" : 0.1,
"obstacleGridPenalty" : 0.1,
"targetAttractionStrength" : 1.0,
"timeCostAttributes" : {
"standardDeviation" : 0.7,
"type" : "UNIT",
"obstacleDensityWeight" : 3.5,
"pedestrianSameTargetDensityWeight" : 3.5,
"pedestrianOtherTargetDensityWeight" : 3.5,
"pedestrianWeight" : 3.5,
"queueWidthLoading" : 1.0,
"pedestrianDynamicWeight" : 6.0,
"loadingType" : "CONSTANT"
}
},
"org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 18,
"numberOfCircles" : 1,
"varyStepDirection" : false,
"stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"optimizationType" : "PSO",
"movementType" : "ARBITRARY",
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN",
"seeSmallWalls" : false,
"minimumStepLength" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompactSoftshell",
"obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompactSoftshell",
"submodels" : [ ]
},
"org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell" : {
"pedPotentialIntimateSpaceWidth" : 0.45,
"pedPotentialPersonalSpaceWidth" : 1.2,
"pedPotentialHeight" : 50.0,
"obstPotentialWidth" : 0.8,
"obstPotentialHeight" : 6.0,
"intimateSpaceFactor" : 1.2,
"personalSpacePower" : 1,
"intimateSpacePower" : 1
}
},
"attributesSimulation" : {
"finishTime" : 100.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.0,
"writeSimulationData" : true,
"visualizationEnabled" : true,
"printFPS" : false,
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : 1,
"simulationSeed" : 1
},
"topography" : {
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : 25.0,
"height" : 35.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true
},
"obstacles" : [ {
"shape" : {
"x" : 12.0,
"y" : 9.0,
"width" : 4.0,
"height" : 19.0,
"type" : "RECTANGLE"
},
"id" : -1
}, {
"shape" : {
"x" : 0.4,
"y" : 0.5,
"width" : 24.8,
"height" : 6.5,
"type" : "RECTANGLE"
},
"id" : -1
}, {
"shape" : {
"x" : 18.0,
"y" : 4.2,
"width" : 7.2,
"height" : 26.8,
"type" : "RECTANGLE"
},
"id" : -1
}, {
"shape" : {
"x" : 0.0,
"y" : 9.0,
"width" : 10.0,
"height" : 19.0,
"type" : "RECTANGLE"
},
"id" : -1
}, {
"shape" : {
"x" : 5.6,
"y" : 18.8,
"width" : 0.1,
"height" : 0.1,
"type" : "RECTANGLE"
},
"id" : -1
}, {
"shape" : {
"x" : 7.0,
"y" : 30.0,
"width" : 18.2,
"height" : 4.5,
"type" : "RECTANGLE"
},
"id" : -1
} ],
"stairs" : [ {
"shape" : {
"x" : 10.0,
"y" : 24.0,
"width" : 2.0,
"height" : 4.0,
"type" : "RECTANGLE"
},
"id" : 10,
"treadCount" : 12,
"upwardDirection" : {
"x" : 0.0,
"y" : 1.0
}
}, {
"shape" : {
"x" : 10.0,
"y" : 9.0,
"width" : 2.0,
"height" : 4.0,
"type" : "RECTANGLE"
},
"id" : 11,
"treadCount" : 12,
"upwardDirection" : {
"x" : 0.0,
"y" : -1.0
}
} ],
"targets" : [ {
"id" : 1,
"absorbing" : true,
"shape" : {
"x" : 0.5,
"y" : 7.1,
"width" : 1.5,
"height" : 1.8,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"sources" : [ {
"id" : -1,
"shape" : {
"x" : 1.0,
"y" : 29.0,
"width" : 5.0,
"height" : 5.0,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 100,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 0.0,
"spawnAtRandomPositions" : true,
"useFreeSpaceOnly" : true,
"targetIds" : [ 1 ],
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN"
} ],
"dynamicElements" : [ ],
"attributesPedestrian" : {
"radius" : 0.195,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0
},
"attributesCar" : null
},
"eventInfos" : [ ]
}
}
\ No newline at end of file
package org.vadere.simulator.control;
import org.vadere.simulator.control.events.EventController;
import org.vadere.simulator.control.factory.SourceControllerFactory;
import org.vadere.simulator.models.DynamicElementFactory;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.models.Model;
import org.vadere.simulator.models.osm.PedestrianOSM;
import org.vadere.simulator.models.potential.PotentialFieldModel;
import org.vadere.simulator.models.potential.fields.IPotentialField;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.simulator.projects.SimulationResult;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.json.EventInfo;
import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.events.types.Event;
import org.vadere.state.events.types.EventTimeframe;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
import org.vadere.util.logging.Logger;
import java.awt.geom.Rectangle2D;
import java.util.*;
public class Simulation {
private static Logger logger = Logger.getLogger(Simulation.class);
private final AttributesSimulation attributesSimulation;
private final AttributesAgent attributesAgent;
private final Collection<SourceController> sourceControllers;
private final Collection<TargetController> targetControllers;
private TeleporterController teleporterController;
private TopographyController topographyController;
private DynamicElementFactory dynamicElementFactory;
private final List<PassiveCallback> passiveCallbacks;
private List<Model> models;
private boolean runSimulation = false;
private boolean paused = false;
/**
* current simulation time (seconds)
*/
private double simTimeInSec = 0;
/**
* time (seconds) where the simulation starts
*/
private double startTimeInSec = 0;
/**
* time (seconds) that should be simulated, i.e. the final time is startTimeInSec + runTimeInSec
*/
private double runTimeInSec = 0;
private long lastFrameInMs = 0;
private int step = 0;
private SimulationState simulationState;
private String name;
private final ScenarioStore scenarioStore;
private final MainModel mainModel;
/** Hold the topography in an extra field for convenience. */
private final Topography topography;
private final ProcessorManager processorManager;
private final SourceControllerFactory sourceControllerFactory;
<<<<<<< HEAD
private final EventController eventController;
=======
private SimulationResult simulationResult;
>>>>>>> master
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager, SimulationResult simulationResult) {
this.name = name;
this.mainModel = mainModel;
this.scenarioStore = scenarioStore;
this.attributesSimulation = scenarioStore.getAttributesSimulation();
this.attributesAgent = scenarioStore.getTopography().getAttributesPedestrian();
this.sourceControllers = new LinkedList<>();
this.targetControllers = new LinkedList<>();
this.topography = scenarioStore.getTopography();
this.runTimeInSec = attributesSimulation.getFinishTime();
this.startTimeInSec = startTimeInSec;
this.simTimeInSec = startTimeInSec;
this.simulationResult = simulationResult;
this.models = mainModel.getSubmodels();
this.sourceControllerFactory = mainModel.getSourceControllerFactory();
// TODO [priority=normal] [task=bugfix] - the attributesCar are missing in initialize' parameters
this.dynamicElementFactory = mainModel;
this.processorManager = processorManager;
this.passiveCallbacks = passiveCallbacks;
this.topographyController = new TopographyController(topography, dynamicElementFactory);
<<<<<<< HEAD
this.eventController = new EventController(scenarioStore);
IPotentialFieldTarget pft = null;
if(mainModel instanceof PotentialFieldModel) {
pft = ((PotentialFieldModel) mainModel).getPotentialFieldTarget();
}
=======
// ::start:: this code is to visualize the potential fields. It may be refactored later.
if(attributesSimulation.isVisualizationEnabled()) {
IPotentialFieldTarget pft = null;
IPotentialField pt = null;
if(mainModel instanceof PotentialFieldModel) {
pft = ((PotentialFieldModel) mainModel).getPotentialFieldTarget();
pt = (pos, agent) -> {
if(agent instanceof PedestrianOSM) {
return ((PedestrianOSM)agent).getPotential(pos);
}
else {
return 0.0;
}
};
}
for (PassiveCallback pc : this.passiveCallbacks) {
pc.setPotentialFieldTarget(pft);
pc.setPotentialField(pt);
}
}
// ::end::
>>>>>>> master
for (PassiveCallback pc : this.passiveCallbacks) {
pc.setTopography(topography);
}
// create source and target controllers
for (Source source : topography.getSources()) {
SourceController sc = this.sourceControllerFactory
.create(topography, source, dynamicElementFactory, attributesAgent, random);
sourceControllers.add(sc);
}
for (Target target : topography.getTargets()) {
targetControllers.add(new TargetController(topography, target));
}
if (topography.hasTeleporter()) {
this.teleporterController = new TeleporterController(
topography.getTeleporter(), topography);
}
}
private void preLoop() {
if (topographyController == null) {
logger.error("No topography loaded.");
return;
}
simulationState = initialSimulationState();
topographyController.preLoop(simTimeInSec);
runSimulation = true;
simTimeInSec = startTimeInSec;
for (Model m : models) {
m.preLoop(simTimeInSec);
}
for (PassiveCallback c : passiveCallbacks) {
c.preLoop(simTimeInSec);
}
if (attributesSimulation.isWriteSimulationData()) {
processorManager.preLoop(this.simulationState);
}
}
private void postLoop() {
simulationState = new SimulationState(name, topography, scenarioStore, simTimeInSec, step, mainModel);
topographyController.postLoop(this.simTimeInSec);
for (Model m : models) {
m.postLoop(simTimeInSec);
}
for (PassiveCallback c : passiveCallbacks) {
c.postLoop(simTimeInSec);
}
if (attributesSimulation.isWriteSimulationData()) {
processorManager.postLoop(this.simulationState);
}
}
/**
* Starts simulation and runs main loop until stopSimulation flag is set.
*/
public void run() {
try {
if (attributesSimulation.isWriteSimulationData()) {
processorManager.setMainModel(mainModel);
processorManager.initOutputFiles();
}
preLoop();
while (runSimulation) {
synchronized (this) {
while (paused) {
try {
wait();
} catch (Exception e) {
paused = false;
Thread.currentThread().interrupt();
logger.warn("interrupt while paused.");
}
}
}
if (attributesSimulation.isVisualizationEnabled()) {
sleepTillStartOfNextFrame();
}
for (PassiveCallback c : passiveCallbacks) {
c.preUpdate(simTimeInSec);
}
assert assertAllPedestrianInBounds();
updateCallbacks(simTimeInSec);
updateWriters(simTimeInSec);
if (attributesSimulation.isWriteSimulationData()) {
processorManager.update(this.simulationState);
}
for (PassiveCallback c : passiveCallbacks) {
c.postUpdate(simTimeInSec);
}
if (runTimeInSec + startTimeInSec > simTimeInSec + 1e-7) {
simTimeInSec += Math.min(attributesSimulation.getSimTimeStepLength(), runTimeInSec + startTimeInSec - simTimeInSec);
} else {
runSimulation = false;
}
//remove comment to fasten simulation for evacuation simulations
//if (topography.getElements(Pedestrian.class).size() == 0){
// runSimulation = false;
//}
if (Thread.interrupted()) {
runSimulation = false;
simulationResult.setState("Simulation interrupted");
logger.info("Simulation interrupted.");
}
}
} finally {
// this is necessary to free the resources (files), the SimulationWriter and processor are writing in!
postLoop();
if (attributesSimulation.isWriteSimulationData()) {
processorManager.writeOutput();
}
logger.info("Finished writing all output files");
}
}
private boolean assertAllPedestrianInBounds() {
Rectangle2D.Double bounds = topography.getBounds();
Collection<Pedestrian> peds = topography.getElements(Pedestrian.class);
return peds.stream().map(ped -> ped.getPosition()).allMatch(pos -> bounds.contains(pos.getX(), pos.getY()));
}
private SimulationState initialSimulationState() {
SimulationState state =
new SimulationState(name, topography.clone(), scenarioStore, simTimeInSec, step, mainModel);
return state;
}
private void updateWriters(double simTimeInSec) {
SimulationState simulationState =
new SimulationState(name, topography, scenarioStore, simTimeInSec, step, mainModel);
this.simulationState = simulationState;
}
private void updateCallbacks(double simTimeInSec) {
List<Event> events = eventController.getEventsForTime(simTimeInSec);
// TODO Why are target controllers readded in each simulation loop?
this.targetControllers.clear();
for (Target target : this.topographyController.getTopography().getTargets()) {
targetControllers.add(new TargetController(this.topographyController.getTopography(), target));
}
for (SourceController sourceController : this.sourceControllers) {
sourceController.update(simTimeInSec);
}
for (TargetController targetController : this.targetControllers) {
targetController.update(simTimeInSec);
}
topographyController.update(simTimeInSec);
step++;
for (Model m : models) {
m.update(events);
}
if (topographyController.getTopography().hasTeleporter()) {
teleporterController.update(simTimeInSec);
}
}
public synchronized void pause() {
paused = true;
}
public synchronized boolean isPaused() {
return paused;
}
public synchronized boolean isRunning() {
return runSimulation && !isPaused();
}
public synchronized void resume() {
paused = false;
notify();
}
/**
* If visualization is enabled, wait until time elapsed since last frame
* matches a given time span. This ensures that the speed of the simulation
* is not mainly determined by hardware performance.
*/
private void sleepTillStartOfNextFrame() {
// Preferred time span between two frames.
long desireDeltaTimeInMs = (long) (attributesSimulation
.getSimTimeStepLength()
* attributesSimulation.getRealTimeSimTimeRatio() * 1000.0);
// Remaining time until next simulation step has to be started.
long waitTime = desireDeltaTimeInMs
- (System.currentTimeMillis() - lastFrameInMs);
lastFrameInMs = System.currentTimeMillis();
if (waitTime > 0) {
try {
Thread.sleep(waitTime);
} catch (InterruptedException e) {
runSimulation = false;