Commit d9c671aa authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

Merge branch 'devMe' into develop

parents 70338f71 26fdaf19
Pipeline #65831 failed with stages
......@@ -74,6 +74,7 @@ ProjectView.btnNewButton.text=New button
ProjectView.btnRunAllTests.text=Run all scenarios
ProjectView.mntmRunSelectetTests.text=Run selected scenario
ProjectView.mntmRunSelectedTests.text=Run selected scenarios
ProjectView.mntmSimulationResult.text=Show Simulation Result Dialog
ProjectView.btnPauseRunningTests.text=Pause running scenarios
ProjectView.btnRunSelectedTest.text=Run selected scenario
ProjectView.btnRunSelectedTest.toolTipText=Run selected scenario
......
......@@ -75,6 +75,7 @@ ProjectView.btnNewButton.text=Neuer Button
ProjectView.btnRunAllTests.text=Alle Szenarios ausf\u00FChren
ProjectView.mntmRunSelectetTests.text=Ausgew\u00E4hlte Szenarios ausf\u00FChren
ProjectView.mntmRunSelectedTests.text=Ausgew\u00E4hlte Szenarios ausf\u00FChren
ProjectView.mntmSimulationResult.text=Ergebnis Dialog anzeigen
ProjectView.btnPauseRunningTests.text=Laufende Szenarios pausieren
ProjectView.btnRunSelectedTest.text=Ausgew\u00E4hltes Szenario ausf\u00FChren
ProjectView.btnRunSelectedTest.toolTipText=Ausgew\u00E4hlten Szenario ausf\u00FChren
......
package org.vadere.gui.projectview.control;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.model.ProjectViewModel;
import java.awt.event.ActionEvent;
import java.util.prefs.Preferences;
import javax.swing.*;
public class ShowResultDialogAction extends AbstractAction {
ProjectViewModel model;
JCheckBoxMenuItem item;
public ShowResultDialogAction(final String name, final ProjectViewModel model, JCheckBoxMenuItem item) {
super(name);
this.model = model;
this.item = item;
}
@Override
public void actionPerformed(ActionEvent e) {
model.setShowSimulationResultDialog(item.getState());
Preferences.userNodeForPackage(VadereApplication.class).putBoolean("Project.simulationResult.show", item.getState());
}
}
......@@ -3,6 +3,7 @@ package org.vadere.gui.projectview.model;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Messages;
import org.vadere.gui.projectview.VadereApplication;
import org.vadere.gui.projectview.control.IOutputFileRefreshListener;
import org.vadere.gui.projectview.control.IProjectChangeListener;
import org.vadere.gui.projectview.view.ProjectView;
......@@ -21,6 +22,7 @@ import java.util.*;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
public class ProjectViewModel {
......@@ -42,6 +44,7 @@ public class ProjectViewModel {
private final Collection<IOutputFileRefreshListener> outputRefreshListeners;
private final Collection<IProjectChangeListener> projectChangeListeners;
private JLabel scenarioNameLabel; // to add or remove the "*" to indicate unsaved changes
private boolean showSimulationResultDialog;
public ProjectViewModel() {
this.outputTableModel = new OutputFileTableModel();
......@@ -50,6 +53,8 @@ public class ProjectViewModel {
this.projectChangeListeners = new LinkedList<>();
this.project = null;
this.refreshOutputExecutor = Executors.newSingleThreadExecutor();
this.showSimulationResultDialog = Preferences.userNodeForPackage(VadereApplication.class)
.getBoolean("Project.simulationResult.show", true);
}
public void deleteOutputFiles(final int[] rows) throws IOException {
......@@ -403,4 +408,11 @@ public class ProjectViewModel {
return currentScenario;
}
public boolean isShowSimulationResultDialog() {
return showSimulationResultDialog;
}
public void setShowSimulationResultDialog(boolean showSimulationResultDialog) {
this.showSimulationResultDialog = showSimulationResultDialog;
}
}
package org.vadere.gui.projectview.view;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.simulator.projects.ProjectFinishedListener;
import org.vadere.simulator.projects.SimulationResult;
import org.vadere.simulator.projects.VadereProject;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedList;
import javax.swing.*;
public class ProjectRunResultDialog implements ProjectFinishedListener {
private static Logger logger = LogManager.getLogger(ProjectRunResultDialog.class);
private final ProjectView projectView;
private final ProjectViewModel projectViewModel;
public ProjectRunResultDialog(ProjectView projectView, ProjectViewModel projectViewModel) {
this.projectView = projectView;
this.projectViewModel = projectViewModel;
}
@Override
public void preProjectRun(VadereProject project) {
}
@Override
public void postProjectRun(VadereProject project) {
LinkedList<SimulationResult> simulationResultList = project.getSimulationResults();
StringBuilder sb = new StringBuilder();
for (SimulationResult res : simulationResultList) {
sb.append(res.getScenarioName()).append(":\n")
.append(" Runtime: ").append(res.getRunTimeAsString()).append("\n")
.append(" Overlaps: ").append(res.getTotalOverlaps()).append("\n")
.append(" State: ").append(res.getState()).append("\n\n");
}
if (projectViewModel.isShowSimulationResultDialog()) {
SwingUtilities.invokeLater(() -> {
JDialog dialog = new ResultDialog(projectView, simulationResultList);
dialog.setVisible(true);
});
} else {
logger.info(sb.toString());
}
}
class ResultDialog extends JDialog {
private final String[] columnNames = {"Scenario_Name",
"Runtime",
"Overlaps",
"State"};
Button btnOk, btnCsv;
private JTable table;
JPanel main;
JScrollPane scrollPane;
JPanel btnPane;
LinkedList<SimulationResult> data;
public ResultDialog(ProjectView projectView, LinkedList<SimulationResult> data) {
super(projectView);
this.data = data;
main = new JPanel();
main.setLayout(new BoxLayout(main, BoxLayout.PAGE_AXIS));
table = new JTable(getData(data), columnNames);
table.setFillsViewportHeight(true);
table.doLayout();
scrollPane = new JScrollPane(table);
main.add(scrollPane);
btnOk = new Button("Close");
btnOk.addActionListener(this::btnOKListener);
btnCsv = new Button("Export csv");
btnPane = new JPanel();
btnCsv.addActionListener(this::btnCsvListener);
btnPane.setLayout(new BoxLayout(btnPane, BoxLayout.LINE_AXIS));
btnPane.add(Box.createHorizontalGlue());
btnPane.add(btnOk);
btnPane.add(Box.createRigidArea(new Dimension(10, 0)));
btnPane.add(btnCsv);
Container c = getContentPane();
c.add(main, BorderLayout.CENTER);
c.add(btnPane, BorderLayout.PAGE_END);
setTitle("Simulation Result");
setSize(600, 200);
}
public Object[][] getData(LinkedList<SimulationResult> data) {
Object[][] res = new Object[data.size()][4];
int rowIdx = 0;
for (SimulationResult d : data) {
res[rowIdx] = d.getAsTableRow();
rowIdx++;
}
return res;
}
private void btnOKListener(ActionEvent actionEvent) {
setVisible(false);
}
private void btnCsvListener(ActionEvent actionEvent) {
StringBuilder sj = new StringBuilder();
SimulationResult.addCsvHeader(sj, ';');
data.forEach(i -> i.addCsvRow(sj, ';'));
FileDialog fd = new FileDialog(this, "Bitte eine Datei waehlen!", FileDialog.SAVE);
fd.setVisible(true);
Path p = (Paths.get(fd.getDirectory()).resolve(fd.getFile()));
fd.setVisible(false);
try (OutputStreamWriter writer =
new OutputStreamWriter(new FileOutputStream(p.toString(), false), StandardCharsets.UTF_8)) {
writer.write(sj.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
setVisible(false);
}
}
}
package org.vadere.gui.projectview.view;
import org.apache.commons.codec.language.bm.Lang;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.gui.components.utils.Language;
......@@ -32,6 +31,7 @@ import org.vadere.gui.projectview.control.ActionSeeDiscardChanges;
import org.vadere.gui.projectview.control.ActionShowAboutDialog;
import org.vadere.gui.projectview.control.IOutputFileRefreshListener;
import org.vadere.gui.projectview.control.IProjectChangeListener;
import org.vadere.gui.projectview.control.ShowResultDialogAction;
import org.vadere.gui.projectview.model.ProjectViewModel;
import org.vadere.gui.projectview.model.ProjectViewModel.OutputBundle;
import org.vadere.gui.projectview.model.ProjectViewModel.ScenarioBundle;
......@@ -42,7 +42,6 @@ import org.vadere.simulator.projects.ProjectFinishedListener;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.SingleScenarioFinishedListener;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.io.IOOutput;
import org.vadere.util.io.IOUtils;
import java.awt.*;
......@@ -103,7 +102,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
private ScenarioPanel scenarioJPanel;
private boolean scenariosRunning = false;
private Set<Action> projectSpecificActions = new HashSet<>(); // actions that should only be enabled, when a project is loaded
private ProjectRunResultDialog projectRunResultDialog;
// ####################### Part of the control this should also be part of another class
// ##################
......@@ -225,6 +224,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
model.getProject().addProjectFinishedListener(this);
model.getProject().addSingleScenarioFinishedListener(this);
model.getProject().addProjectFinishedListener(scenarioJPanel);
model.getProject().addProjectFinishedListener(projectRunResultDialog);
});
}
......@@ -303,6 +303,7 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
model.addOutputFileRefreshListener(this);
model.addProjectChangeListener(this);
this.model = model;
projectRunResultDialog = new ProjectRunResultDialog(this, model);
setTitle("Vadere GUI");
setBounds(100, 100, 1000, 600);
......@@ -384,6 +385,15 @@ public class ProjectView extends JFrame implements ProjectFinishedListener, Sing
addToProjectSpecificActions(saveProjectAsAction);
mnFile.add(mntmSaveAs);
// Checkbox menu item to turn off result dialog of project run.
mnFile.addSeparator();
boolean showDialogDefault = Preferences.userNodeForPackage(VadereApplication.class)
.getBoolean("Project.simulationResult.show", false);
JCheckBoxMenuItem showResultDialogMenu = new JCheckBoxMenuItem(Messages.getString("ProjectView.mntmSimulationResult.text"), null, showDialogDefault);
Action showResultDialogMenuAction = new ShowResultDialogAction(Messages.getString("ProjectView.mntmSimulationResult.text"), model, showResultDialogMenu);
showResultDialogMenu.setAction(showResultDialogMenuAction);
mnFile.add(showResultDialogMenu);
JMenuItem mntmExit = new JMenuItem(closeApplicationAction);
mnFile.addSeparator();
mnFile.add(mntmExit);
......
......@@ -7,6 +7,14 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "density.txt",
"processors" : [ 1 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out.txt",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "out1.txt",
"processors" : [ 4 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianDensityCountingProcessor",
......@@ -19,6 +27,20 @@
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor",
"attributes" : {
"pedRadius" : 0.2
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 3
}
} ],
"isTimestamped" : true
},
......
......@@ -11,6 +11,14 @@
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.PedestrianIdOutputFile",
"filename" : "waitingTimes.txt",
"processors" : [ 2 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out.txt",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "out1.txt",
"processors" : [ 4 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
......@@ -28,6 +36,20 @@
"type" : "RECTANGLE"
}
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor",
"attributes" : {
"pedRadius" : 0.2
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 3
}
} ],
"isTimestamped" : true
},
......@@ -59,7 +81,7 @@
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"optimizationType" : "DISCRETE",
"optimizationType" : "NELDER_MEAD",
"movementType" : "ARBITRARY",
"dynamicStepLength" : false,
"updateType" : "EVENT_DRIVEN",
......
......@@ -13,12 +13,12 @@
"processors" : [ 2 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "tests.txt",
"processors" : [ 4 ]
"filename" : "out.txt",
"processors" : [ 5 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "postvis.trajectories",
"processors" : [ 3 ]
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out1.txt",
"processors" : [ 6 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianWaitingTimeProcessor",
......@@ -27,9 +27,9 @@
"attributes" : {
"waitingArea" : {
"x" : 1.0,
"y" : 3.0,
"y" : 3.5,
"width" : 9.5,
"height" : 10.5,
"height" : 10.0,
"type" : "RECTANGLE"
}
}
......@@ -38,24 +38,28 @@
"id" : 2,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeProcessor",
"attributes" : {
"pedestrianStartTimeProcessorId" : 5
"pedestrianStartTimeProcessorId" : 4
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
"id" : 3
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.tests.TestPedestrianWaitingTimeProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesTestPedestrianWaitingTimeProcessor",
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 4
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"expectedResult" : "FAIL",
"pedestrianWaitingTimeProcessorId" : 1,
"maximalWaitingTime" : 0.0,
"minimalWaitingTime" : 0.0
"pedestrianOverlapProcessorId" : 6
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 5
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 6,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor",
"attributes" : {
"pedRadius" : 0.2
}
} ],
"isTimestamped" : true
},
......@@ -113,7 +117,7 @@
"finishTime" : 100.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.0,
"writeSimulationData" : true,
"writeSimulationData" : false,
"visualizationEnabled" : true,
"printFPS" : false,
"needsBoundary" : false,
......
{
"name" : "narrow_passage_discrete_ca_fail",
"name" : "narrow_passage_discrete_CA_fail",
"description" : "",
"release" : "0.4",
"processWriters" : {
......@@ -9,8 +9,12 @@
"processors" : [ 1, 2 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "test-evacuationTimes.txt",
"filename" : "out.txt",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "out1.txt",
"processors" : [ 4 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianPositionProcessor",
......@@ -19,25 +23,19 @@
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianTargetIdProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.tests.TestPedestrianEvacuationTimeProcessor",
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 3,
"attributesType" : "org.vadere.state.attributes.processor.AttributesTestPedestrianEvacuationTimeProcessor",
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"expectedResult" : "FAIL",
"pedestrianEvacuationTimeProcessorId" : 4,
"maximalEvacuationTime" : 21.0,
"minimalEvacuationTime" : 0.0
"pedestrianOverlapProcessorId" : 4
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianEvacuationTimeProcessor",
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeProcessor",
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianOverlapProcessor",
"attributes" : {
"pedestrianStartTimeProcessorId" : 5
"pedRadius" : 0.2
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 5
} ],
"isTimestamped" : true
},
......
{
"name" : "rimea_09_public_room_2_exits_nelder_mead",
"name" : "rimea_09_public_room_2_exits_NELDER_MEAD",
"description" : "",
"release" : "0.4",
"processWriters" : {
......@@ -270,4 +270,4 @@
"attributesCar" : null
}
}
}
\ No newline at end of file
}
......@@ -11,6 +11,7 @@ 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;
......@@ -65,9 +66,10 @@ public class Simulation {
private final Topography topography;
private final ProcessorManager processorManager;
private final SourceControllerFactory sourceControllerFactory;
private SimulationResult simulationResult;
public Simulation(MainModel mainModel, double startTimeInSec, final String name, ScenarioStore scenarioStore,
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager) {
List<PassiveCallback> passiveCallbacks, Random random, ProcessorManager processorManager, SimulationResult simulationResult) {
this.name = name;
this.mainModel = mainModel;
this.scenarioStore = scenarioStore;
......@@ -79,6 +81,7 @@ public class Simulation {
this.runTimeInSec = attributesSimulation.getFinishTime();
this.startTimeInSec = startTimeInSec;
this.simTimeInSec = startTimeInSec;
this.simulationResult = simulationResult;
this.models = mainModel.getSubmodels();
this.sourceControllerFactory = mainModel.getSourceControllerFactory();
......@@ -229,6 +232,7 @@ public class Simulation {
if (Thread.interrupted()) {
runSimulation = false;
simulationResult.setState("Simulation interrupted");
logger.info("Simulation interrupted.");
}
}
......
......@@ -26,7 +26,7 @@ import java.util.Random;
public abstract class SourceController {
protected final double NO_EVENT = Double.MAX_VALUE;
private final double SPAWN_BUFFER_SIZE = 0.001;
public static final double SPAWN_BUFFER_SIZE = 0.01;
protected final Source source;
private final DynamicElementFactory dynamicElementFactory;
......
......@@ -3,5 +3,5 @@ package org.vadere.simulator.projects;
public interface ProjectFinishedListener {
void preProjectRun(final VadereProject project);
void postProjectRun(final VadereProject scenario);
void postProjectRun(final VadereProject project);
}
......@@ -51,6 +51,8 @@ public class ScenarioRun implements Runnable {
private final RunnableFinishedListener finishedListener;
private SimulationResult simulationResult;
public ScenarioRun(final Scenario scenario, RunnableFinishedListener scenarioFinishedListener) {
this(scenario, IOUtils.OUTPUT_DIR, scenarioFinishedListener);
}
......@@ -66,6 +68,7 @@ public class ScenarioRun implements Runnable {
this.dataProcessingJsonManager = scenario.getDataProcessingJsonManager();
this.setOutputPaths(Paths.get(outputDir), overwriteTimestampSetting); // TODO [priority=high] [task=bugfix] [Error?] this is a relative path. If you start the application via eclipse this will be VadereParent/output
this.finishedListener = scenarioFinishedListener;
this.simulationResult = new SimulationResult(scenario.getName()); <