Commit 402295c4 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck
Browse files

refactor org.vadere.simulator.util to ...utils, add ScenarioChecker to console.

parent 6d575903
......@@ -4,7 +4,7 @@
## Added
- Two new outputprocessors - mainly for the BHM - to evaluaet queueWidth (QueueWidthProcessor) and behavior (PedestrianBehaviorProcessor)
- In package `org.vadere.simulator.util`, added `TopographyChecker` to show user if the current topography contains problems. The
- In package `org.vadere.simulator.utils`, added `TopographyChecker` to show user if the current topography contains problems. The
`TopographyChecker` will check for overlapping `ScenarioElements` and check for inconsistence settings such as missing
TargetIDs for sources or inconsistenct speed ranges for pedestrians. See this [table](Documentation/changelLogImages/TopographyCheckerMessages.md) for supported warnings and erros
as well as this [picture](Documentation/changelLogImages/TopographyChecker.png) to see which kind of overlap produces erros or warnings.
......
......@@ -5,8 +5,8 @@ import org.vadere.gui.projectview.view.ScenarioPanel;
import org.vadere.gui.projectview.view.VDialogManager;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.util.ScenarioChecker;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioChecker;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import java.awt.event.ActionEvent;
import java.util.Observable;
......
......@@ -2,8 +2,8 @@ package org.vadere.gui.components.control;
import org.vadere.gui.components.utils.GuiScenarioCheckerMessageFormatter;
import org.vadere.gui.topographycreator.model.IDrawPanelModel;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerMessageFormatter;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessageFormatter;
import org.vadere.state.scenario.ScenarioElement;
import java.util.HashMap;
......
package org.vadere.gui.components.utils;
import org.vadere.gui.components.control.ScenarioCheckerMessageDocumentView;
import org.vadere.simulator.util.AbstractScenarioCheckerMessageFormatter;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerMessageType;
import org.vadere.state.types.ScenarioElementType;
import org.vadere.simulator.utils.scenariochecker.AbstractScenarioCheckerMessageFormatter;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessageType;
import java.util.Comparator;
import java.util.PriorityQueue;
public class GuiScenarioCheckerMessageFormatter extends AbstractScenarioCheckerMessageFormatter {
......
......@@ -69,7 +69,7 @@
},
"attributesSimulation" : {
"finishTime" : 70.0,
"simTimeStepLength" : 0.4,
"simTimeStepLength" : 1.4,
  • @hm-schuhba1 Why did you change the simTimeStepLength? For this test case I get the error in the GUI "Reason: simTimeStep parameter outside of allowed range [0.0 - 1.0] current value: 1.4" The other failing test cases in the TestStairs need correction in the topography (overlapping stuff).

    Edited by Daniel Lehmberg
  • This was a test and this should not be committed. I changed it back in 922fde6e

Please register or sign in to reply
"realTimeSimTimeRatio" : 0.1,
"writeSimulationData" : false,
"visualizationEnabled" : true,
......
......@@ -15,6 +15,7 @@ import org.vadere.simulator.entrypoints.cmd.commands.ProjectRunSubCommand;
import org.vadere.simulator.entrypoints.cmd.commands.ScenarioRunSubCommand;
import org.vadere.simulator.entrypoints.cmd.commands.SetLogLevelCommand;
import org.vadere.simulator.entrypoints.cmd.commands.SuqSubCommand;
import org.vadere.simulator.utils.scenariochecker.ScenarioChecker;
/**
* Provides the possibility to start VADERE in console mode.
......@@ -27,7 +28,7 @@ public class VadereConsole {
public static void main(String[] args) {
ArgumentParser parser = createArgumentParser();
// args = new String[]{"--loglevel", "OFF", "scenario-run", "-o", "/tmp", "-f", "/home/lphex/hm.d/vadere/VadereModelTests/TestOSM/scenarios/basic_2_density_discrete_ca.scenario"};
// args = new String[]{"--loglevel", "INFO", "scenario-run", "-o", "/tmp", "-f", "/home/lphex/hm.d/vadere/VadereModelTests/TestStairs/scenarios/stairs_diagonal_1_+1.scenario"};
// args = new String[]{"-h"};
try {
......@@ -78,6 +79,13 @@ public class VadereConsole {
.type(String.class)
.dest("scenario-file")
.help("Name of Scenario file");
projectRun.addArgument("--scenario-checker")
.required(false)
.type(String.class)
.dest("scenario-checker")
.choices(ScenarioChecker.CHECKER_OFF, ScenarioChecker.CHECKER_OFF)
.setDefault(ScenarioChecker.CHECKER_OFF)
.help("Turn Scenario Checker on or off.");
// Run Scenario
Subparser scenarioRun = subparsers
......@@ -96,6 +104,13 @@ public class VadereConsole {
.type(String.class)
.dest("scenario-file")
.help("Scenario file to run");
scenarioRun.addArgument("--scenario-checker")
.required(false)
.type(String.class)
.dest("scenario-checker")
.choices(ScenarioChecker.CHECKER_OFF, ScenarioChecker.CHECKER_OFF)
.setDefault(ScenarioChecker.CHECKER_ON)
.help("Turn Scenario Checker on or off.");
// Run SUQ
Subparser suqRun = subparsers
......
......@@ -8,16 +8,41 @@ import org.vadere.simulator.entrypoints.ScenarioFactory;
import org.vadere.simulator.entrypoints.cmd.SubCommandRunner;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.ScenarioRun;
import org.vadere.simulator.utils.scenariochecker.AbstractScenarioCheckerMessageFormatter;
import org.vadere.simulator.utils.scenariochecker.ConsoleScenarioCheckerMessageFormatter;
import org.vadere.simulator.utils.scenariochecker.ScenarioChecker;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.PriorityQueue;
public class ScenarioRunSubCommand implements SubCommandRunner {
private final static Logger logger = Logger.getLogger(ScenarioRunSubCommand.class);
private boolean checkScenario(final Scenario scenario, String scenarioCheckerSwitch){
if(scenarioCheckerSwitch.equals(ScenarioChecker.CHECKER_OFF)){
return true;
}
ScenarioChecker checker = new ScenarioChecker(scenario);
ConsoleScenarioCheckerMessageFormatter formatter = new ConsoleScenarioCheckerMessageFormatter(scenario);
PriorityQueue<ScenarioCheckerMessage> msg = checker.checkBuildingStep();
if (msg.size() > 0){
System.out.println(formatter.formatMessages(msg));
ScenarioCheckerMessage firstMsg = msg.peek();
if (firstMsg != null && firstMsg.isError()){
return false;
}
}
return true;
}
@Override
public void run(Namespace ns, ArgumentParser parser) {
Path outputDir = Paths.get(ns.getString("output-dir"));
String scenarioCheckerSwitch = ns.getString("scenario-checker");
if (!outputDir.toFile().exists()){
if ( ! outputDir.toFile().mkdirs() ) {
logger.error("Could not create all necessary directories: " + outputDir.toFile().toString());
......@@ -38,7 +63,11 @@ public class ScenarioRunSubCommand implements SubCommandRunner {
try {
Scenario scenario = ScenarioFactory.createScenarioWithScenarioFilePath(scenarioFile);
new ScenarioRun(scenario, outputDir.toFile().toString() , null).run();
if (checkScenario(scenario, scenarioCheckerSwitch)){
new ScenarioRun(scenario, outputDir.toFile().toString() , null).run();
} else {
System.exit(-1);
}
} catch (Exception e){
logger.error(e);
System.exit(-1);
......
package org.vadere.simulator.utils;
import org.vadere.util.lang.BundleManager;
import java.util.Locale;
import java.util.prefs.Preferences;
import javax.swing.*;
public class Messages {
private static final String BUNDLE_NAME = "i18n_simulation";
public static String getString(String key) {
return BundleManager.instance().getString(BUNDLE_NAME, key);
}
public static boolean languageIsGerman(){
return BundleManager.instance().languageIsGerman();
}
public static Locale getCurrentLocale(){
return BundleManager.instance().getCurrentLocale();
}
}
package org.vadere.simulator.util;
package org.vadere.simulator.utils.scenariochecker;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.util.AbstractScenarioCheckerMessageFormatter;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.utils.Messages;
import org.vadere.state.scenario.ScenarioElement;
public class ConsoleScenarioCheckerMessageFormatter extends AbstractScenarioCheckerMessageFormatter {
......@@ -14,11 +14,15 @@ public class ConsoleScenarioCheckerMessageFormatter extends AbstractScenarioChec
@Override
protected void writeHeader(ScenarioCheckerMessage msg) {
// sb.append(Messages.getString(msg.getMsgType().getLocalTypeId())))
sb.append(Messages.getString(currentType.getLocalTypeId())).append(":\n");
}
@Override
protected void writeMsg(ScenarioCheckerMessage msg) {
sb.append(" ")
.append(Messages.getString(msg.getReason().getLocalMessageId()))
.append(" ")
.append(msg.getReasonModifier())
.append("\n");
}
}
package org.vadere.simulator.util;
package org.vadere.simulator.utils.scenariochecker;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.util.checks.ScenarioCheckerTest;
import org.vadere.simulator.util.checks.simulation.SimulationTimeStepLengthCheck;
import org.vadere.simulator.util.checks.topography.PedestrianSpeedSetupCheck;
import org.vadere.simulator.util.checks.topography.StairTreadSanityCheck;
import org.vadere.simulator.util.checks.topography.TopographyOverlapCheck;
import org.vadere.simulator.util.checks.topography.UniqueSourceIdCheck;
import org.vadere.simulator.util.checks.topography.UnusedTargetsCheck;
import org.vadere.simulator.util.checks.topography.ValidTargetsInSourceCheck;
import org.vadere.simulator.utils.scenariochecker.checks.ScenarioCheckerTest;
import org.vadere.simulator.utils.scenariochecker.checks.simulation.SimulationTimeStepLengthCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.PedestrianSpeedSetupCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.StairTreadSanityCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.TopographyOverlapCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.UniqueSourceIdCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.UnusedTargetsCheck;
import org.vadere.simulator.utils.scenariochecker.checks.topography.ValidTargetsInSourceCheck;
import org.vadere.state.scenario.Topography;
import java.util.PriorityQueue;
public class ScenarioChecker {
public static final String CHECKER_ON = "on";
public static final String CHECKER_OFF = "off";
public static final String CHECKER_ERROR_ONLY = "error-only";
private final Topography topography;
private final Scenario scenario;
......
package org.vadere.simulator.util;
package org.vadere.simulator.utils.scenariochecker;
import org.jetbrains.annotations.NotNull;
......@@ -64,6 +64,10 @@ public class ScenarioCheckerMessage implements Comparable<ScenarioCheckerMessage
}
}
public boolean isError(){
return msgType.isErrorMsg();
}
public boolean hasTarget(){
return msgTarget != null;
}
......
package org.vadere.simulator.util;
package org.vadere.simulator.utils.scenariochecker;
import org.vadere.state.scenario.ScenarioElement;
......
package org.vadere.simulator.util;
package org.vadere.simulator.utils.scenariochecker;
import java.util.Arrays;
import java.util.HashSet;
......
package org.vadere.simulator.util;
package org.vadere.simulator.utils.scenariochecker;
import org.vadere.state.scenario.ScenarioElement;
......
package org.vadere.simulator.util;
package org.vadere.simulator.utils.scenariochecker;
/**
* Types of {@link ScenarioChecker} messages. The {@link #msgId} is used as messageId for locale
......
package org.vadere.simulator.util;
package org.vadere.simulator.utils.scenariochecker;
/**
* This enum collects all reasons for {@link ScenarioCheckerMessage}s. The label is the messageId
......
package org.vadere.simulator.util.checks;
package org.vadere.simulator.utils.scenariochecker.checks;
import org.vadere.simulator.util.ScenarioCheckerMessageBuilder;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessageBuilder;
public abstract class AbstractScenarioCheck implements ScenarioCheckerTest{
......
package org.vadere.simulator.util.checks;
package org.vadere.simulator.utils.scenariochecker.checks;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import java.util.PriorityQueue;
......
package org.vadere.simulator.util.checks;
package org.vadere.simulator.utils.scenariochecker.checks;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.checks.ScenarioCheckerTest;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.state.scenario.Topography;
import java.util.PriorityQueue;
......
package org.vadere.simulator.util.checks.simulation;
package org.vadere.simulator.utils.scenariochecker.checks.simulation;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerReason;
import org.vadere.simulator.util.checks.AbstractScenarioCheck;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.state.attributes.AttributesSimulation;
import java.util.PriorityQueue;
......
package org.vadere.simulator.util.checks.topography;
package org.vadere.simulator.utils.scenariochecker.checks.topography;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerReason;
import org.vadere.simulator.util.checks.AbstractScenarioCheck;
import org.vadere.simulator.util.checks.TopographyCheckerTest;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.simulator.utils.scenariochecker.checks.TopographyCheckerTest;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......
package org.vadere.simulator.util.checks.topography;
package org.vadere.simulator.utils.scenariochecker.checks.topography;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerReason;
import org.vadere.simulator.util.checks.AbstractScenarioCheck;
import org.vadere.simulator.util.checks.TopographyCheckerTest;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.simulator.utils.scenariochecker.checks.TopographyCheckerTest;
import org.vadere.state.scenario.Stairs;
import org.vadere.state.scenario.Topography;
......@@ -20,8 +20,8 @@ public class StairTreadSanityCheck extends AbstractScenarioCheck implements Topo
.topographyWarning()
.target(stairs)
.reason(ScenarioCheckerReason.STAIRS_TREAD_DIM_WRONG
, "(" + Stairs.MIN_TREAD_DEPTH + "m &lt; treadDepth &gt; " + Stairs.MAX_TREAD_DEPTH +
"m) current treadDepth is: " + String.format("%.3fm", stairs.getTreadDepth()))
, "[" + Stairs.MIN_TREAD_DEPTH + "m - " + Stairs.MAX_TREAD_DEPTH +
"m] current treadDepth is: " + String.format("%.3fm", stairs.getTreadDepth()))
.build()
);
}
......
package org.vadere.simulator.util.checks.topography;
package org.vadere.simulator.utils.scenariochecker.checks.topography;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerReason;
import org.vadere.simulator.util.checks.AbstractScenarioCheck;
import org.vadere.simulator.util.checks.TopographyCheckerTest;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.simulator.utils.scenariochecker.checks.TopographyCheckerTest;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.ScenarioElement;
import org.vadere.state.scenario.Source;
......
package org.vadere.simulator.util.checks.topography;
package org.vadere.simulator.utils.scenariochecker.checks.topography;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerReason;
import org.vadere.simulator.util.checks.AbstractScenarioCheck;
import org.vadere.simulator.util.checks.TopographyCheckerTest;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.simulator.utils.scenariochecker.checks.TopographyCheckerTest;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Topography;
......
package org.vadere.simulator.util.checks.topography;
package org.vadere.simulator.utils.scenariochecker.checks.topography;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerReason;
import org.vadere.simulator.util.checks.AbstractScenarioCheck;
import org.vadere.simulator.util.checks.TopographyCheckerTest;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.simulator.utils.scenariochecker.checks.TopographyCheckerTest;
import org.vadere.state.scenario.Topography;
import java.util.HashSet;
......
package org.vadere.simulator.util.checks.topography;
package org.vadere.simulator.utils.scenariochecker.checks.topography;
import org.vadere.simulator.util.ScenarioCheckerMessage;
import org.vadere.simulator.util.ScenarioCheckerReason;
import org.vadere.simulator.util.checks.AbstractScenarioCheck;
import org.vadere.simulator.util.checks.TopographyCheckerTest;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.simulator.utils.scenariochecker.checks.AbstractScenarioCheck;
import org.vadere.simulator.utils.scenariochecker.checks.TopographyCheckerTest;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Target;
import org.vadere.state.scenario.Topography;
......
......@@ -13,15 +13,15 @@
//import org.vadere.state.scenario.Agent;
//import org.vadere.state.scenario.Pedestrian;
//import org.vadere.state.scenario.Topography;
//import org.vadere.util.data.Row;
//import org.vadere.util.data.Table;
//import org.vadere.util.geometry.GeometryUtils;
//import org.vadere.util.geometry.shapes.VPoint;
//import org.vadere.util.geometry.shapes.VRectangle;
//import org.vadere.utils.data.Row;
//import org.vadere.utils.data.Table;
//import org.vadere.utils.geometry.GeometryUtils;
//import org.vadere.utils.geometry.shapes.VPoint;
//import org.vadere.utils.geometry.shapes.VRectangle;
//
//import java.net.URISyntaxException;
//import java.util.ArrayList;
//import java.util.List;
//import java.utils.ArrayList;
//import java.utils.List;
//
//import static junit.framework.Assert.assertEquals;
//import static junit.framework.Assert.assertTrue;
......
package org.vadere.simulator.util;
package org.vadere.simulator.utils;
import org.apache.commons.math3.util.Pair;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.vadere.simulator.projects.Scenario;
import org.vadere.state.attributes.scenario.AttributesObstacle;
import org.vadere.simulator.utils.scenariochecker.ScenarioChecker;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessage;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerMessageType;
import org.vadere.simulator.utils.scenariochecker.ScenarioCheckerReason;
import org.vadere.state.attributes.scenario.builder.AttributesAgentBuilder;
import org.vadere.state.attributes.scenario.builder.AttributesObstacleBuilder;
import org.vadere.state.attributes.scenario.builder.AttributesSourceBuilder;
......
package org.vadere.simulator.util;
package org.vadere.simulator.utils;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.attributes.scenario.AttributesObstacle;
......
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