Notice to GitKraken users: A vulnerability has been found in the SSH key generation of GitKraken versions 7.6.0 to 8.0.0 (https://www.gitkraken.com/blog/weak-ssh-key-fix). If you use GitKraken and have generated a SSH key using one of these versions, please remove it both from your local workstation and from your LRZ GitLab profile.

21.10.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit bbd98c0b authored by Christina's avatar Christina
Browse files

finish sim before end time simplified version

parent e1bb6ac6
Pipeline #257298 passed with stages
in 136 minutes and 45 seconds
......@@ -288,7 +288,12 @@ public class Simulation {
c.postUpdate(simTimeInSec);
}
double stopTime = Math.min(runTimeInSec, this.simulationState.getStopTime());
double stopTime = runTimeInSec;
if (this.simulationState.isSimStop()) {
// get stopTime if the simulation should finish before finish time. New finish time = stop time
stopTime = this.simTimeInSec;
}
if (stopTime + startTimeInSec > simTimeInSec + 1e-7) {
// do nothing here. This is done after the Remote Control Hook
} else {
......
......@@ -16,7 +16,7 @@ public class SimulationState {
private final int step;
private final String name;
private final MainModel mainModel;
private double stopTime = Float.POSITIVE_INFINITY;
private boolean simStop = false;
protected SimulationState(final String name,
final Topography topography,
......@@ -76,11 +76,11 @@ public class SimulationState {
return Optional.ofNullable(mainModel);
}
public double getStopTime(){
return this.stopTime;
public void setSimStop(boolean stop){
this.simStop = stop;
}
public void setStopTime(double stopTime) {
this.stopTime = stopTime;
public boolean isSimStop() {
return simStop;
}
}
......@@ -45,6 +45,8 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
private int lastStep;
private boolean stopSimBeforeSimFinish;
protected DataProcessor() {
this(new String[] { });
}
......@@ -54,6 +56,7 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
this.data = new TreeMap<>(); // TreeMap to avoid sorting data later
this.lastStep = 0;
this.stopSimBeforeSimFinish = false;
}
......@@ -116,10 +119,13 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
public final void update(final SimulationState state) {
int step = state.getStep();
if (this.lastStep < step) {
if (this.lastStep < step) {
this.doUpdate(state);
this.lastStep = step;
}
// stop simulation if a criteria defined in your data processor is fulfilled
state.setSimStop(this.stopSimBeforeSimFinish);
}
public Optional<Model> getSubModel(SimulationState state, Class clazz){
......@@ -152,6 +158,10 @@ public abstract class DataProcessor<K extends DataKey<K>, V> {
return getClass().getSimpleName();
}
public void setStopSimBeforeSimFinish(boolean stopSimBeforeSimFinish) {
this.stopSimBeforeSimFinish = stopSimBeforeSimFinish;
}
@Override
public String toString() {
return id + ": " + getSimpleProcessorTypeName();
......
......@@ -21,9 +21,6 @@ public class PedStimulusCountingProcessor extends DataProcessor<TimestepKey, Inf
private Predicate<Pedestrian> filter_by_stimuli;
private Pattern filter_pattern = null;
private double stopIfPercentageIsInformed = 0.95;
private int numberOfAdditionalTimeFrames = 20;
private double dynamicFinishTime = -1.0;
private boolean dynamicFinishTimeSet = false;
public PedStimulusCountingProcessor() {
super("numberPedsInformed", "numberPedsAll", "percentageInformed");
......@@ -43,7 +40,6 @@ public class PedStimulusCountingProcessor extends DataProcessor<TimestepKey, Inf
}
stopIfPercentageIsInformed = attr.getStopIfPercentageIsInformed();
numberOfAdditionalTimeFrames = attr.getNumberOfAdditionalTimeFrames();
}
......@@ -55,19 +51,11 @@ public class PedStimulusCountingProcessor extends DataProcessor<TimestepKey, Inf
int numberPedsAll = (int) peds.stream().filter(p-> p.getFootstepHistory().getFootSteps().size() > 1).count();
numberPedsAll = Math.max(numberPedsAll,numberPedsInformed);
// test wihtout omnet: if (state.getSimTimeInSec() > 1.0){ numberPedsInformed = numberPedsAll; }
InformationDegree informationDegree = new InformationDegree(numberPedsInformed, numberPedsAll);
// force stop before simulation time defined in json is reached.
if ((!dynamicFinishTimeSet) && (informationDegree.getPercentageInformed() >= stopIfPercentageIsInformed)) {
dynamicFinishTime = state.getSimTimeInSec() + state.getScenarioStore().getAttributesSimulation().getSimTimeStepLength() * Math.max(numberOfAdditionalTimeFrames, 1);
dynamicFinishTimeSet = true;
}
if (dynamicFinishTimeSet){
state.setStopTime(dynamicFinishTime);
if (informationDegree.getPercentageInformed() >= stopIfPercentageIsInformed) {
setStopSimBeforeSimFinish(true);
}
putValue(new TimestepKey(state.getStep()), informationDegree);
......@@ -92,4 +80,6 @@ public class PedStimulusCountingProcessor extends DataProcessor<TimestepKey, Inf
}
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