10.12., 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit b8b9ceb7 authored by Christina's avatar Christina

use strategyLayer

parent 55f3dd9e
Pipeline #313319 passed with stages
in 134 minutes and 35 seconds
......@@ -88,14 +88,6 @@
"edgeLength" : 1.5,
"displayMesh" : false
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.ReadAndSetControllerInput",
"id" : 11,
"attributesType" : "org.vadere.state.attributes.processor.AttributesReadAndSetControllerInput",
"attributes" : {
"controllerInputFile" : "Scenarios/Demos/Density_controller/scenarios/TwoCorridors_forced_controller_input.csv",
"useFile" : true
}
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
......@@ -176,8 +168,8 @@
}
},
"attributesStrategy" : {
"useStrategyModel" : false,
"strategyModel" : "RouteChoiceThreeCorridors"
"useStrategyModel" : true,
"strategyModel" : "ReadSetControllerInputs"
},
"topography" : {
"attributes" : {
......
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.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;
@Override
public void initialize(double simTimeInSec) {
String fileName = "Scenarios/Demos/Density_controller/scenarios/TwoCorridors_forced_controller_input.csv";
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;
}
}
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import org.vadere.simulator.control.simulation.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesReadAndSetControllerInput;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
/**
* @author Christina Mayr
* reads and sets controller input defined in an external file
*/
@DataProcessorClass()
public class ReadAndSetControllerInput extends DataProcessor<TimestepKey, Double> {
private double[][] controllerInputs;
public ReadAndSetControllerInput() {
super("percentageLeftRealized");
setAttributes(new AttributesReadAndSetControllerInput());
}
@Override
public void preLoop(SimulationState state) {
String fileName = getAttributes().getControllerInputFile();
// fileName = "Scenarios/Demos/Density_controller/scenarios/TwoCorridors_forced_controller_input.csv";
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] );
int i = 0;
}
@Override
protected void doUpdate(SimulationState state) {
}
@Override
public AttributesReadAndSetControllerInput getAttributes() {
if (super.getAttributes() == null) {
setAttributes(new AttributesReadAndSetControllerInput());
}
return (AttributesReadAndSetControllerInput)super.getAttributes();
}
}
package org.vadere.state.attributes.processor;
public class AttributesReadAndSetControllerInput extends AttributesProcessor {
private String controllerInputFile = null;
private boolean useFile = false;
public String getControllerInputFile() {
return controllerInputFile;
}
public void setControllerInputFile(String controllerInputFile) {
this.controllerInputFile = controllerInputFile;
}
public boolean isUseFile() {
return useFile;
}
public void setUseFile(boolean useFile) {
this.useFile = useFile;
}
}
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