In January 2021 we will introduce a 10 GB quota for project repositories. Higher limits for individual projects will be available on request. Please see https://doku.lrz.de/display/PUBLIC/GitLab for more information.

Commit fa4fe01e authored by Christina's avatar Christina

extended strategyModel

parent b8b9ceb7
......@@ -3,6 +3,7 @@ package org.vadere.simulator.control.strategy.helpers;
import org.vadere.simulator.control.strategy.models.IStrategyModel;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.state.attributes.AttributesStrategyModel;
import org.vadere.util.reflection.DynamicClassInstantiator;
public class StrategyModelBuilder {
......@@ -17,6 +18,8 @@ public class StrategyModelBuilder {
DynamicClassInstantiator<IStrategyModel> instantiator = new DynamicClassInstantiator<>();
IStrategyModel strategyModel = instantiator.createObject(fullyQualifiedClassName);
strategyModel.build(scenarioStore.getAttributesStrategyModel());
return strategyModel;
}
else{
......
package org.vadere.simulator.control.strategy.models;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.state.attributes.AttributesStrategyModel;
import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
import java.util.LinkedList;
public interface IStrategyModel {
/*
* @param pedestrians The pedestrians to update
*/
void update(double simTimeInSec, Collection<Pedestrian> pedestrians, ProcessorManager processorManager);
void build(AttributesStrategyModel attr);
void initialize(double simTimeInSec);
}
......@@ -2,6 +2,7 @@ package org.vadere.simulator.control.strategy.models.navigation;
import org.vadere.simulator.control.strategy.models.IStrategyModel;
import org.vadere.state.attributes.AttributesStrategyModel;
public interface INavigationModel extends IStrategyModel {
......
......@@ -10,6 +10,7 @@ import com.github.cschen1205.fuzzylogic.memberships.FuzzyTriangle;
import org.vadere.simulator.control.strategy.models.navigation.INavigationModel;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.processor.AreaDensityCountingProcessor;
import org.vadere.state.attributes.AttributesStrategyModel;
import org.vadere.state.scenario.Pedestrian;
import java.io.IOException;
......@@ -25,32 +26,31 @@ public class ReadSetControllerInputs implements INavigationModel {
private double[][] controllerInputs;
private int counter = 0;
private String filePath;
@Override
public void initialize(double simTimeInSec) {
String fileName = "Scenarios/Demos/Density_controller/scenarios/TwoCorridors_forced_controller_input.csv";
String fileName = this.filePath;
try {
this.controllerInputs = Files.lines(Paths.get(fileName)).map(s -> s.split(" ")).map(s -> Arrays.stream(s).mapToDouble(Double::parseDouble).toArray()).toArray(double[][]::new);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println( this.controllerInputs[0][0] );
System.out.println(this.controllerInputs[0][0]);
}
public void update(double simTimeInSec, Collection<Pedestrian> pedestrians, ProcessorManager processorManager) {
double percentageLeft = controllerInputs[counter][1];
List<Pedestrian> newAgents = pedestrians.stream().filter(p -> p.getFootstepHistory().getFootSteps().size() == 0).collect(Collectors.toList());
int numberLeft = (int) (newAgents.size()*percentageLeft);
int numberLeft = (int) (newAgents.size() * percentageLeft);
int numberRight = newAgents.size() - numberLeft;
LinkedList<Integer> targets = new LinkedList<Integer>();
......@@ -68,10 +68,16 @@ public class ReadSetControllerInputs implements INavigationModel {
nextTargets.add(targets.get(c));
nextTargets.add(1);
pedestrian.setTargets(nextTargets);
c+=1;
c += 1;
}
counter += 1;
}
@Override
public void build(AttributesStrategyModel attr) {
filePath = attr.getArguments().get(0); // first element contains path to file
}
}
......@@ -6,6 +6,7 @@ import com.github.cschen1205.fuzzylogic.memberships.*;
import org.vadere.simulator.control.strategy.models.navigation.INavigationModel;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.simulator.projects.dataprocessing.processor.AreaDensityCountingProcessor;
import org.vadere.state.attributes.AttributesStrategyModel;
import org.vadere.state.scenario.Pedestrian;
import java.util.*;
......@@ -22,6 +23,7 @@ public class RouteChoiceThreeCorridors implements INavigationModel {
private FuzzySet density1;
private FuzzySet density2;
private FuzzySet density3;
private AttributesStrategyModel attributesStrategyModel;
@Override
......@@ -123,7 +125,10 @@ public class RouteChoiceThreeCorridors implements INavigationModel {
}
@Override
public void build(AttributesStrategyModel attr) {
attributesStrategyModel = attr;
}
private double getDensityFromDataProcessor(int processorId, ProcessorManager processorManager) {
......
......@@ -5,6 +5,7 @@ import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.utils.scenariochecker.checks.ScenarioCheckerTest;
import org.vadere.simulator.utils.scenariochecker.checks.dataProcessors.CheckAreasInAreaDensityVoronoiProcessor;
import org.vadere.simulator.utils.scenariochecker.checks.dataProcessors.DataProcessorsLinkedToMeasurementArea;
import org.vadere.simulator.utils.scenariochecker.checks.dataProcessors.StrategyModelDataProcessorCheck;
import org.vadere.simulator.utils.scenariochecker.checks.models.CellularAutomatonSetupCheck;
import org.vadere.simulator.utils.scenariochecker.checks.simulation.GroupSetupCheck;
import org.vadere.simulator.utils.scenariochecker.checks.simulation.SimulationTimeStepLengthCheck;
......@@ -65,6 +66,7 @@ public class ScenarioChecker {
ret.addAll(runCheck(new TopographyOffsetCheck()));
ret.addAll(runCheck(new DataProcessorsLinkedToMeasurementArea()));
ret.addAll(runCheck(new CheckAreasInAreaDensityVoronoiProcessor()));
ret.addAll(runCheck(new StrategyModelDataProcessorCheck()));
ret.addAll(runCheck(new GroupSetupCheck()));
ret.addAll(runCheck(new CellularAutomatonSetupCheck()));
return ret;
......
......@@ -48,13 +48,17 @@ public enum ScenarioCheckerReason {
AREAS_DENSITY_VORONOI_PROCESSOR_MISMATCH("ScenarioChecker.processor.checkAreasInAreaDensityVoronoiProcessor.mismatch"),
MEASUREMENT_AREA_NOT_RECTANGULAR("ScenarioChecker.processor.measurementArea.hasToBeRectangular"),
// Missing dataprocessors which are necessary in the strategyModel
DATAPROCESSOR_MISSING("ScenarioChecker.processor.strategyModelDataProcessorCheck."),
// Group attributes
GROUP_SETUP_IGNORED("ScenarioChecker.simAttr.GroupSetup.ignored"),
// Model reasons
CA_SPAWNING("ScenarioChecker.models.ca.spawning.setup.err");
private String msgId;
ScenarioCheckerReason(String msgId) {
......
package org.vadere.simulator.utils.scenariochecker.checks.dataProcessors;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.dataprocessing.processor.DataProcessor;
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.AttributesStrategyModel;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
/**
* @author Christina Mayr
* Warnings if data processors used in strategy model are not defined in data output
*/
public class StrategyModelDataProcessorCheck extends AbstractScenarioCheck {
@Override
public PriorityQueue<ScenarioCheckerMessage> runScenarioCheckerTest(Scenario scenario) {
PriorityQueue<ScenarioCheckerMessage> messages = new PriorityQueue<>();
AttributesStrategyModel attr = scenario.getScenarioStore().getAttributesStrategyModel();
if (attr.isUseStrategyModel()) {
LinkedList<Integer> requiredDataProcessorIds = attr.getRequiredDataProcessorIds();
List<DataProcessor<?, ?>> processors = scenario.getDataProcessingJsonManager().getDataProcessors();
for (Integer i : requiredDataProcessorIds) {
try {
DataProcessor<?, ?> p = processors.get(i - 1); // processor id = (index +1)
} catch (Exception e) {
messages.add(msgBuilder.dataProcessorAttrError()
.reason(ScenarioCheckerReason.DATAPROCESSOR_MISSING,
String.format(" [Strategy model requires data processor id: %d. Processor not defined.]", i)).build());
}
}
}
return messages;
}
}
package org.vadere.state.attributes;
import java.util.LinkedList;
import java.util.Objects;
public class AttributesStrategyModel extends Attributes {
......@@ -11,16 +12,23 @@ public class AttributesStrategyModel extends Attributes {
private boolean useStrategyModel;
private String strategyModel;
private LinkedList<String> arguments = new LinkedList<>();
private LinkedList<Integer> requiredDataProcessorIds = new LinkedList<>();
// Constructors
public AttributesStrategyModel(){
this.useStrategyModel = false;
this.strategyModel = null;
this.arguments = new LinkedList<>();
this.requiredDataProcessorIds = new LinkedList<>();
}
public AttributesStrategyModel(boolean useStrategyModel, String strategyModel) {
public AttributesStrategyModel(boolean useStrategyModel, String strategyModel, LinkedList<String> arguments, LinkedList<Integer> requiredDataProcessorIds) {
this.useStrategyModel = useStrategyModel;
this.strategyModel = strategyModel;
this.arguments = arguments;
this.requiredDataProcessorIds = requiredDataProcessorIds;
}
// getter and setters
......@@ -39,6 +47,22 @@ public class AttributesStrategyModel extends Attributes {
public void setUseStrategyModel(boolean useStrategyModel) {
this.useStrategyModel = useStrategyModel;
}
public LinkedList<String> getArguments() {
return arguments;
}
public void setArguments(LinkedList<String> arguments) {
this.arguments = arguments;
}
public LinkedList<Integer> getRequiredDataProcessorIds() {
return requiredDataProcessorIds;
}
public void setRequiredDataProcessorIds(LinkedList<Integer> requiredDataProcessorIds) {
this.requiredDataProcessorIds = requiredDataProcessorIds;
}
}
......
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