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 e4fafdba authored by Christina's avatar Christina
Browse files

Merge branch 'master' into test123

parents 63262081 5584bcec
Pipeline #258397 passed with stages
in 140 minutes and 59 seconds
......@@ -225,6 +225,8 @@ SettingsDialog.chbShowPedestrianIds.text=Show PedestrianIds
SettingsDialog.chbShowPedestrianInOutGroup.text=Show Pedestrian In/Outgroup
PostVis.chShowEvacTimeColor.text=Coloring by Evacuation Times
PostVis.chShowCriteriaColor.text=Coloring by Predicate
PostVis.ShowContactsErrorMessage.text=Contacts were not processed for this scenario. To process contacts for scenarios add PedestriansNearbyProcessor and a corresponding file contacts.txt to data output.
PostVis.additional.border.text=PostVis
PostVis.btnPlay.tooltip=Play (Space)
......@@ -311,6 +313,7 @@ SettingsDialog.chbLogo.text=Show the Vadere logo
ProjectView.btnShowWalkingDirection.tooltip=Show the walking direction of all pedestrians
ProjectView.btnShowGroupInformation.tooltip=Draw pedestrians within one group with same shape and color
ProjectView.btnShowPedestrian.tooltip=Show Pedestrians
ProjectView.btnShowContacts.tooltip=Show Contacts
ProjectView.btnShowPotentialfield.tooltip=Show Potential Field (only possible after adding potential field file)
ProjectView.btnShowTrajectories.tooltip=Show Trajectories
ProjectView.btnShowGrid.tooltip=Show Grid
......
......@@ -33,6 +33,7 @@ public class DefaultSimulationConfig extends DefaultConfig {
private boolean showStairs = true;
private boolean showPedestrians = true;
private boolean showContacts = true;
private boolean contactsRecorded = false;
private boolean showWalkdirection = false;
private boolean showTargetPotentialField = false;
private boolean showTargetPotentielFieldMesh = false;
......@@ -109,6 +110,13 @@ public class DefaultSimulationConfig extends DefaultConfig {
return showContacts;
}
public boolean isContactsRecorded() {
return contactsRecorded;
}
public void setContactsRecorded(boolean contactsRecorded) {
this.contactsRecorded = contactsRecorded;
}
public boolean isShowWalkdirection() {
return showWalkdirection;
......
......@@ -104,6 +104,7 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
this.simTimeStepLength = scenario.getAttributesSimulation().getSimTimeStepLength();
this.trajectories = new TableTrajectoryFootStep(trajectories);
if (contactTrajectories != null) {
this.config.setContactsRecorded(true);
this.contactData = new ContactData(contactTrajectories);
}
this.visTime = 0;
......
......@@ -33,6 +33,7 @@ import org.vadere.gui.postvisualization.control.ActionVisualizationMenu;
import org.vadere.gui.postvisualization.control.Player;
import org.vadere.gui.postvisualization.model.PostvisualizationModel;
import org.vadere.gui.projectview.control.ActionDeselect;
import org.vadere.gui.projectview.view.ProjectView;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.io.IOOutput;
import org.vadere.util.config.VadereConfig;
......@@ -178,6 +179,7 @@ public class PostvisualizationWindow extends JPanel implements Observer, DropTar
public void actionPerformed(ActionEvent e) {
model.config.setShowPedestrians(!model.config.isShowPedestrians());
model.notifyObservers();
}
}, "ProjectView.btnShowPedestrian.tooltip");
......@@ -187,8 +189,13 @@ public class PostvisualizationWindow extends JPanel implements Observer, DropTar
model) {
@Override
public void actionPerformed(ActionEvent e) {
model.config.setShowContacts(!model.config.isShowContacts());
model.notifyObservers();
if (!model.config.isContactsRecorded()) {
JOptionPane.showMessageDialog(ProjectView.getMainWindow(),
Messages.getString("PostVis.ShowContactsErrorMessage.text"));
} else {
model.config.setShowContacts(!model.config.isShowContacts());
model.notifyObservers();
}
}
}, "ProjectView.btnShowContacts.tooltip");
......
......@@ -74,9 +74,13 @@ public class RemoteManager implements RunnableFinishedListener {
throw new TraCIException("Cannot create Scenario from given file.");
}
if (simCfg != null) {
scenario.getAttributesSimulation().setFixedSeed(simCfg.getSeed());
scenario.getAttributesSimulation().setUseFixedSeed(true);
logger.infof("received seed from traci client '%s'", Long.toString(simCfg.getSeed()));
if (simCfg.isUseVadereSeed()){
logger.infof("use Vadere Seed. (ignoring traci seed)", Long.toString(simCfg.getSeed()));
} else {
scenario.getAttributesSimulation().setFixedSeed(simCfg.getSeed());
scenario.getAttributesSimulation().setUseFixedSeed(true);
logger.infof("received seed from traci client '%s'", Long.toString(simCfg.getSeed()));
}
}
currentSimulationRun = new RemoteScenarioRun(scenario, outputDir, this, scenarioPath, scenarioCache);
}
......@@ -143,6 +147,10 @@ public class RemoteManager implements RunnableFinishedListener {
return true;
}
public double getSimulationStoppedEarlyAtTime(){
return currentSimulationRun.getSimulationStoppedEarlyAtTime();
}
public boolean isClientCloseCommandReceived() {
return clientCloseCommandReceived;
}
......
......@@ -17,6 +17,7 @@ public class RemoteScenarioRun extends ScenarioRun implements RemoteRunListener
private final ReentrantLock lock;
private List<Subscription> subscriptions;
private boolean lastSimulationStep;
private double simulationStoppedEarlyAtTime;
public RemoteScenarioRun(Scenario scenario, Path outputDir, RunnableFinishedListener scenarioFinishedListener, Path scenarioPath, ScenarioCache scenarioCache) {
......@@ -25,6 +26,7 @@ public class RemoteScenarioRun extends ScenarioRun implements RemoteRunListener
this.waitForLoopEnd = new Object();
this.lock = new ReentrantLock();
this.lastSimulationStep = false;
this.simulationStoppedEarlyAtTime = Double.MAX_VALUE;
addRemoteManagerListener(this);
}
......@@ -72,8 +74,16 @@ public class RemoteScenarioRun extends ScenarioRun implements RemoteRunListener
}
}
@Override
public void simulationStoppedEarlyListener(double time) {
simulationStoppedEarlyAtTime = time;
}
public boolean isLastSimulationStep() {
return lastSimulationStep;
}
public double getSimulationStoppedEarlyAtTime() {
return simulationStoppedEarlyAtTime;
}
}
......@@ -98,6 +98,15 @@ public class ControlCommandHandler extends CommandHandler<ControlVar> {
});
cmd.setResponse(response);
// check RemoteManager if simulation is ended prematurely. This can happen if the
// a finish state is reached earlier than the given simulation time. In this case
// inform the TraCI client about this instead of giving it the Subscription results.
if (remoteManager.getSimulationStoppedEarlyAtTime() != Double.MAX_VALUE){
double stoppedAtTime = remoteManager.getSimulationStoppedEarlyAtTime();
logger.infof("Stop simulation at %f. Inform TraCI client with simEndReach Response.", stoppedAtTime);
cmd.setResponse(TraCISimTimeResponse.simEndReached());
}
logger.debug("process_simStep done.");
return cmd;
}
......
......@@ -22,10 +22,11 @@ public class SimulationCfg {
private String outputScalarFile;
private String outputVecFile;
private long seed;
private boolean useVadereSeed;
public SimulationCfg(CompoundObject obj) {
if (obj.size() != 9) {
throw new TraCIException("Expected at least 9 elements");
if (obj.size() != 10) {
throw new TraCIException("Expected at least 10 elements");
}
configName = (String) obj.getData(0, TraCIDataType.STRING);
experiment = (String) obj.getData(1, TraCIDataType.STRING);
......@@ -36,6 +37,12 @@ public class SimulationCfg {
outputScalarFile = (String) obj.getData(6, TraCIDataType.STRING);
outputVecFile = (String) obj.getData(7, TraCIDataType.STRING);
seed = Long.valueOf((int) obj.getData(8, TraCIDataType.INTEGER));
int useVadereSeedVal = (Integer) obj.getData(9, TraCIDataType.U_BYTE);
if (useVadereSeedVal == 1){
useVadereSeed = true;
} else {
useVadereSeed = false;
}
}
public static CompoundObject asCompoundObject(String configName,
......@@ -46,11 +53,13 @@ public class SimulationCfg {
String repetition,
String outputScalarFile,
String outputVecFile,
long seed) {
long seed,
boolean useVadereSeed) {
return CompoundObjectBuilder.builder()
.rest()
.add(TraCIDataType.STRING, 8)
.add(TraCIDataType.INTEGER)
.add(TraCIDataType.U_BYTE)
.build(configName,
experiment,
dateTime,
......@@ -59,7 +68,8 @@ public class SimulationCfg {
repetition,
outputScalarFile,
outputVecFile,
seed);
seed,
useVadereSeed);
}
public String outputPath() {
......@@ -151,25 +161,34 @@ public class SimulationCfg {
this.seed = seed;
}
public boolean isUseVadereSeed() {
return useVadereSeed;
}
public void setUseVadereSeed(boolean useVadereSeed) {
this.useVadereSeed = useVadereSeed;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SimulationCfg that = (SimulationCfg) o;
return seed == that.seed &&
configName.equals(that.configName) &&
experiment.equals(that.experiment) &&
dateTime.equals(that.dateTime) &&
resultRootDir.equals(that.resultRootDir) &&
iterationVariables.equals(that.iterationVariables) &&
repetition.equals(that.repetition) &&
outputScalarFile.equals(that.outputScalarFile) &&
outputVecFile.equals(that.outputVecFile);
useVadereSeed == that.useVadereSeed &&
Objects.equals(configName, that.configName) &&
Objects.equals(experiment, that.experiment) &&
Objects.equals(dateTime, that.dateTime) &&
Objects.equals(resultRootDir, that.resultRootDir) &&
Objects.equals(iterationVariables, that.iterationVariables) &&
Objects.equals(repetition, that.repetition) &&
Objects.equals(outputScalarFile, that.outputScalarFile) &&
Objects.equals(outputVecFile, that.outputVecFile);
}
@Override
public int hashCode() {
return Objects.hash(configName, experiment, dateTime, resultRootDir, iterationVariables, repetition, outputScalarFile, outputVecFile, seed);
return Objects.hash(configName, experiment, dateTime, resultRootDir, iterationVariables, repetition, outputScalarFile, outputVecFile, seed, useVadereSeed);
}
@Override
......@@ -184,6 +203,7 @@ public class SimulationCfg {
", outputScalarFile='" + outputScalarFile + '\'' +
", outputVecFile='" + outputVecFile + '\'' +
", seed=" + seed +
", useVadereSeed=" + useVadereSeed +
'}';
}
}
......@@ -61,6 +61,7 @@ public class ControlCommandHandlerTest extends CommandHandlerTest {
TraCISimStepCommand rawCmd = (TraCISimStepCommand) getFirstCommand(TraCISimStepCommand.build(targetTime));
RemoteManager rm = mock(RemoteManager.class, Mockito.RETURNS_DEEP_STUBS);
when(rm.nextStep(targetTime)).thenReturn(true);
when(rm.getSimulationStoppedEarlyAtTime()).thenReturn(Double.MAX_VALUE);
TraCICommand cmd = ctrCmdHandler.process_simStep(rawCmd, rm);
testTraCICommand(cmd, traciCmd, cmdType);
......
......@@ -9,4 +9,9 @@ public interface RemoteRunListener {
void simulationStepFinishedListener();
void lastSimulationStepFinishedListener();
/**
* Notify RemoteManger about early shutdown. This is used to gracefully stop TraCI connection.
*/
void simulationStoppedEarlyListener(double time);
}
......@@ -288,6 +288,22 @@ public class Simulation {
c.postUpdate(simTimeInSec);
}
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 {
// inform Remote Control Hook that simulation is stopped before
// static runTimeInSec is reached.
isRunSimulation = false;
remoteRunListeners.forEach(e-> e.simulationStoppedEarlyListener(simTimeInSec));
if (stopTime < runTimeInSec) {
logger.info("Run simulation until time t=" + stopTime +"s is reached."); }
}
// Single step hook
// Remote Control Hook
......@@ -315,14 +331,11 @@ public class Simulation {
}
}
if (runTimeInSec + startTimeInSec > simTimeInSec + 1e-7) {
if (stopTime + startTimeInSec > simTimeInSec + 1e-7) {
simTimeInSec += Math.min(attributesSimulation.getSimTimeStepLength(), runTimeInSec + startTimeInSec - simTimeInSec);
} else {
isRunSimulation = false;
}
//remove comment to fasten simulation for evacuation simulations
//if (topography.getElements(Pedestrian.class).size() == 0){
// isRunSimulation = false;
......
......@@ -16,6 +16,7 @@ public class SimulationState {
private final int step;
private final String name;
private final MainModel mainModel;
private boolean simStop = false;
protected SimulationState(final String name,
final Topography topography,
......@@ -29,7 +30,6 @@ public class SimulationState {
this.step = step;
this.scenarioStore = scenarioStore;
this.mainModel = mainModel;
}
@Deprecated
......@@ -75,4 +75,12 @@ public class SimulationState {
public Optional<MainModel> getMainModel() {
return Optional.ofNullable(mainModel);
}
public void setSimStop(boolean stop){
this.simStop = stop;
}
public boolean isSimStop() {
return simStop;
}
}
package org.vadere.simulator.control.simulation;
public class SimulationStop {
}
......@@ -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();
......
......@@ -5,6 +5,7 @@ import org.vadere.simulator.control.simulation.SimulationState;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.datakey.EventtimePedestrianIdKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.AttributesSimulation;
import org.vadere.state.attributes.processor.AttributesPedStimulusCountingProcessor;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.simulation.InformationDegree;
......@@ -19,6 +20,7 @@ public class PedStimulusCountingProcessor extends DataProcessor<TimestepKey, Inf
private Predicate<Pedestrian> filter_by_stimuli;
private Pattern filter_pattern = null;
private double stopIfPercentageIsInformed = 0.95;
public PedStimulusCountingProcessor() {
super("numberPedsInformed", "numberPedsAll", "percentageInformed");
......@@ -37,6 +39,8 @@ public class PedStimulusCountingProcessor extends DataProcessor<TimestepKey, Inf
filter_by_stimuli = ped -> ped.getKnowledgeBase().knowsAbout(getAttributes().getInformationFilter());
}
stopIfPercentageIsInformed = attr.getStopIfPercentageIsInformed();
}
@Override
......@@ -47,10 +51,16 @@ 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);
InformationDegree informationDegree = new InformationDegree(numberPedsInformed, numberPedsAll);
// force stop before simulation time defined in json is reached.
if (informationDegree.getPercentageInformed() >= stopIfPercentageIsInformed) {
setStopSimBeforeSimFinish(true);
}
putValue(new TimestepKey(state.getStep()), informationDegree);
}
@Override
......@@ -70,4 +80,6 @@ public class PedStimulusCountingProcessor extends DataProcessor<TimestepKey, Inf
}
......@@ -4,6 +4,8 @@ public class AttributesPedStimulusCountingProcessor extends AttributesProcessor
private String informationFilter = "";
private boolean isRegexFilter = false;
private double stopIfPercentageIsInformed = 0.95;
private int numberOfAdditionalTimeFrames = 20;
public String getInformationFilter() {
return informationFilter;
......@@ -23,5 +25,11 @@ public class AttributesPedStimulusCountingProcessor extends AttributesProcessor
isRegexFilter = regexFilter;
}
public int getNumberOfAdditionalTimeFrames() {
return numberOfAdditionalTimeFrames;
}
public double getStopIfPercentageIsInformed() {
return stopIfPercentageIsInformed;
}
}
......@@ -29,5 +29,7 @@ public class InformationDegree {
return valueLine;
}
public double getPercentageInformed() {
return percentageInformed;
}
}
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