Commit ddc84cce authored by Christina Maria Mayr's avatar Christina Maria Mayr
Browse files

Added further attributes to strategyModel

parent dbcf835e
......@@ -145,7 +145,9 @@
},
"attributesStrategy" : {
"useStrategyModel" : true,
"strategyModel" : "RouteChoiceThreeCorridors"
"strategyModel" : "RouteChoiceThreeCorridors",
"arguments" : [ ],
"requiredDataProcessorIds" : [ ]
},
"topography" : {
"attributes" : {
......
......@@ -145,7 +145,9 @@
},
"attributesStrategy" : {
"useStrategyModel" : false,
"strategyModel" : "RouteChoiceThreeCorridors"
"strategyModel" : "RouteChoiceThreeCorridors",
"arguments" : [ ],
"requiredDataProcessorIds" : [ ]
},
"topography" : {
"attributes" : {
......
......@@ -169,7 +169,9 @@
},
"attributesStrategy" : {
"useStrategyModel" : false,
"strategyModel" : "RouteChoiceThreeCorridors"
"strategyModel" : "RouteChoiceThreeCorridors",
"arguments" : [ ],
"requiredDataProcessorIds" : [ ]
},
"topography" : {
"attributes" : {
......
{
"name" : "TwoCorridors_forced_controller",
"description" : "",
"release" : "1.14",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
"filename" : "postvis.traj",
"processors" : [ 1, 2 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "overlaps.csv",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "overlapCount.txt",
"processors" : [ 4 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "evacuationTime.txt",
"processors" : [ 5 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepOutputFile",
"filename" : "AreaDensityCounting.txt",
"processors" : [ 8 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepKeyIdOutputFile",
"filename" : "MeshDensityCounting.txt",
"processors" : [ 9 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "Mesh.txt",
"processors" : [ 10 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepProcessor",
"id" : 1
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepTargetIDProcessor",
"id" : 2
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 3
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 3
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.EvacuationTimeProcessor",
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesEvacuationTimeProcessor",
"attributes" : {
"pedestrianEvacuationTimeProcessorId" : 6
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianEvacuationTimeProcessor",
"id" : 6,
"attributesType" : "org.vadere.state.attributes.processor.AttributesPedestrianEvacuationTimeProcessor",
"attributes" : {
"pedestrianStartTimeProcessorId" : 7
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianStartTimeProcessor",
"id" : 7
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.AreaDensityCountingProcessor",
"id" : 8,
"attributesType" : "org.vadere.state.attributes.processor.AttributesAreaDensityCountingProcessor",
"attributes" : {
"measurementAreaId" : 1000
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.MeshDensityCountingProcessor",
"id" : 9,
"attributesType" : "org.vadere.state.attributes.processor.AttributesMeshDensityCountingProcessor",
"attributes" : {
"meshProcessorId" : 10
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.MeshProcessor",
"id" : 10,
"attributesType" : "org.vadere.state.attributes.processor.AttributesMeshProcessor",
"attributes" : {
"measurementAreaId" : 1,
"edgeLength" : 1.5,
"displayMesh" : false
}
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
},
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 4,
"numberOfCircles" : 1,
"optimizationType" : "NELDER_MEAD",
"varyStepDirection" : true,
"movementType" : "ARBITRARY",
"stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"minStepLength" : 0.1,
"minimumStepLength" : true,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : true,
"updateType" : "EVENT_DRIVEN",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompactSoftshell",
"obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompactSoftshell",
"submodels" : [ ]
},
"org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell" : {
"pedPotentialIntimateSpaceWidth" : 0.45,
"pedPotentialPersonalSpaceWidth" : 1.2,
"pedPotentialHeight" : 50.0,
"obstPotentialWidth" : 0.8,
"obstPotentialHeight" : 6.0,
"intimateSpaceFactor" : 1.2,
"personalSpacePower" : 1,
"intimateSpacePower" : 1
},
"org.vadere.state.attributes.models.AttributesFloorField" : {
"createMethod" : "HIGH_ACCURACY_FAST_MARCHING",
"potentialFieldResolution" : 0.1,
"obstacleGridPenalty" : 0.1,
"targetAttractionStrength" : 1.0,
"cacheType" : "NO_CACHE",
"cacheDir" : "",
"timeCostAttributes" : {
"standardDeviation" : 0.7,
"type" : "UNIT",
"obstacleDensityWeight" : 3.5,
"pedestrianSameTargetDensityWeight" : 3.5,
"pedestrianOtherTargetDensityWeight" : 3.5,
"pedestrianWeight" : 3.5,
"queueWidthLoading" : 1.0,
"pedestrianDynamicWeight" : 6.0,
"loadingType" : "CONSTANT",
"width" : 0.2,
"height" : 1.0
}
}
},
"attributesSimulation" : {
"finishTime" : 160.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.1,
"writeSimulationData" : true,
"visualizationEnabled" : true,
"printFPS" : false,
"digitsPerCoordinate" : 2,
"useFixedSeed" : false,
"fixedSeed" : 2617225706430579811,
"simulationSeed" : 0
},
"attributesPsychology" : {
"usePsychologyLayer" : false,
"psychologyLayer" : {
"perception" : "SimplePerceptionModel",
"cognition" : "SimpleCognitionModel"
}
},
"attributesStrategy" : {
"useStrategyModel" : true,
"strategyModel" : "ReadSetControllerInputs",
"arguments" : [ "Scenarios/Demos/Density_controller/scenarios/TwoCorridors_forced_controller_input.csv" ],
"requiredDataProcessorIds" : [ 10 ]
},
"topography" : {
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : 60.0,
"height" : 51.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true,
"referenceCoordinateSystem" : null
},
"obstacles" : [ {
"shape" : {
"x" : 15.0,
"y" : 10.5,
"width" : 15.5,
"height" : 30.0,
"type" : "RECTANGLE"
},
"id" : 6
}, {
"shape" : {
"x" : 0.5,
"y" : 10.5,
"width" : 12.5,
"height" : 30.0,
"type" : "RECTANGLE"
},
"id" : 7
}, {
"shape" : {
"x" : 32.5,
"y" : 10.5,
"width" : 27.0,
"height" : 30.0,
"type" : "RECTANGLE"
},
"id" : 3
} ],
"measurementAreas" : [ {
"shape" : {
"x" : 30.5,
"y" : 10.5,
"width" : 2.0,
"height" : 10.0,
"type" : "RECTANGLE"
},
"id" : 1000
}, {
"shape" : {
"x" : 0.5,
"y" : 0.5,
"width" : 59.0,
"height" : 50.0,
"type" : "RECTANGLE"
},
"id" : 1
} ],
"stairs" : [ ],
"targets" : [ {
"id" : 1,
"absorbing" : true,
"shape" : {
"x" : 44.5,
"y" : 40.5,
"width" : 15.0,
"height" : 10.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 2001,
"absorbing" : false,
"shape" : {
"x" : 13.0,
"y" : 13.4,
"width" : 2.0,
"height" : 1.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 2002,
"absorbing" : false,
"shape" : {
"x" : 30.5,
"y" : 13.6,
"width" : 2.0,
"height" : 1.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"targetChangers" : [ {
"id" : 4,
"shape" : {
"x" : 39.5,
"y" : 0.5,
"width" : 5.0,
"height" : 10.0,
"type" : "RECTANGLE"
},
"reachDistance" : 0.0,
"changeAlgorithmType" : "SELECT_LIST",
"nextTarget" : [ 2001, 1 ],
"probabilityToChangeTarget" : [ 0.5 ]
} ],
"absorbingAreas" : [ ],
"sources" : [ {
"id" : 2,
"shape" : {
"x" : 44.5,
"y" : 0.5,
"width" : 15.0,
"height" : 10.0,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 100,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 0.0,
"spawnAtRandomPositions" : true,
"spawnAtGridPositionsCA" : false,
"useFreeSpaceOnly" : true,
"targetIds" : [ 2002, 1 ],
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN",
"attributesPedestrian" : null
} ],
"dynamicElements" : [ ],
"attributesPedestrian" : {
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"walkingDirectionCalculation" : "BY_TARGET_CENTER",
"walkingDirectionSameIfAngleLessOrEqual" : 45.0
},
"teleporter" : null,
"attributesCar" : {
"id" : -1,
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"walkingDirectionCalculation" : "BY_TARGET_CENTER",
"walkingDirectionSameIfAngleLessOrEqual" : 45.0,
"length" : 4.5,
"width" : 1.7,
"direction" : {
"x" : 1.0,
"y" : 0.0
}
}
},
"stimulusInfos" : [ ]
}
}
\ No newline at end of file
......@@ -169,7 +169,9 @@
},
"attributesStrategy" : {
"useStrategyModel" : false,
"strategyModel" : "RouteChoiceThreeCorridors"
"strategyModel" : "RouteChoiceThreeCorridors",
"arguments" : [ ],
"requiredDataProcessorIds" : [ ]
},
"topography" : {
"attributes" : {
......
......@@ -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 {
......
package org.vadere.simulator.models.strategy;
import com.github.cschen1205.fuzzylogic.Clause;
import com.github.cschen1205.fuzzylogic.FuzzySet;
import com.github.cschen1205.fuzzylogic.Rule;
import com.github.cschen1205.fuzzylogic.RuleInferenceEngine;
import com.github.cschen1205.fuzzylogic.memberships.FuzzyGrade;
import com.github.cschen1205.fuzzylogic.memberships.FuzzyReverseGrade;
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;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
// https://github.com/cschen1205/java-fuzzy-logic
public class ReadSetControllerInputs implements INavigationModel {
private double[][] controllerInputs;
private int counter = 0;
private String filePath;
@Override
public void initialize(double simTimeInSec) {
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]);
}
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 numberRight = newAgents.size() - numberLeft;
LinkedList<Integer> targets = new LinkedList<Integer>();
for (int i = 0; i < numberLeft; i++) {
targets.add(2001);
}
for (int i = 0; i < numberRight; i++) {
targets.add(2002);
}
int c = 0;
for (Pedestrian pedestrian : newAgents) {
LinkedList<Integer> nextTargets = new LinkedList<Integer>();
nextTargets.add(targets.get(c));
nextTargets.add(1);
pedestrian.setTargets(nextTargets);
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;
......