Commit 274f6b33 authored by Christina's avatar Christina

use density instead of counts and added rule base

parent 83e99917
Pipeline #300968 failed with stages
in 2 minutes and 37 seconds
......@@ -41,28 +41,32 @@
"id" : 5,
"attributesType" : "org.vadere.state.attributes.processor.AttributesAreaDensityCountingProcessor",
"attributes" : {
"measurementAreaId" : 2001
"measurementAreaId" : 2001,
"countsInsteadOfDensity" : false
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.AreaDensityCountingProcessor",
"id" : 6,
"attributesType" : "org.vadere.state.attributes.processor.AttributesAreaDensityCountingProcessor",
"attributes" : {
"measurementAreaId" : 2002
"measurementAreaId" : 2002,
"countsInsteadOfDensity" : false
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.AreaDensityCountingProcessor",
"id" : 7,
"attributesType" : "org.vadere.state.attributes.processor.AttributesAreaDensityCountingProcessor",
"attributes" : {
"measurementAreaId" : 2003
"measurementAreaId" : 2003,
"countsInsteadOfDensity" : false
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.AreaDensityCountingProcessor",
"id" : 8,
"attributesType" : "org.vadere.state.attributes.processor.AttributesAreaDensityCountingProcessor",
"attributes" : {
"measurementAreaId" : 1000
"measurementAreaId" : 1000,
"countsInsteadOfDensity" : false
}
} ],
"isTimestamped" : false,
......@@ -157,15 +161,6 @@
"referenceCoordinateSystem" : null
},
"obstacles" : [ {
"shape" : {
"x" : 55.0,
"y" : 3.5,
"width" : 25.0,
"height" : 36.5,
"type" : "RECTANGLE"
},
"id" : 2
}, {
"shape" : {
"x" : 35.0,
"y" : 3.5,
......@@ -192,6 +187,36 @@
"type" : "RECTANGLE"
},
"id" : 7
}, {
"shape" : {
"type" : "POLYGON",
"points" : [ {
"x" : 55.0,
"y" : 40.0
}, {
"x" : 79.5,
"y" : 40.0
}, {
"x" : 79.5,
"y" : 3.5
}, {
"x" : 74.4,
"y" : 3.5
}, {
"x" : 74.4,
"y" : 20.0
}, {
"x" : 59.9,
"y" : 20.0
}, {
"x" : 59.9,
"y" : 3.5
}, {
"x" : 54.9,
"y" : 3.5
} ]
},
"id" : 8
} ],
"measurementAreas" : [ {
"shape" : {
......@@ -308,6 +333,23 @@
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 2004,
"absorbing" : true,
"shape" : {
"x" : 62.4,
"y" : 17.4,
"width" : 9.0,
"height" : 2.5,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"targetChangers" : [ {
"id" : 4,
......@@ -361,7 +403,7 @@
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.NegativeExponentialDistribution",
"distributionParameters" : [ 0.6 ],
"spawnNumber" : 1,
"spawnNumber" : 5,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 1000.0,
......@@ -455,4 +497,4 @@
},
"stimulusInfos" : [ ]
}
}
}
\ No newline at end of file
......@@ -215,6 +215,8 @@ public class Simulation {
m.preLoop(simTimeInSec);
}
strategyModel.initialize(simTimeInSec);
for (PassiveCallback c : passiveCallbacks) {
c.preLoop(simTimeInSec);
}
......
......@@ -13,5 +13,5 @@ public interface IStrategyModel {
void update(double simTimeInSec, Collection<Pedestrian> pedestrians, ProcessorManager processorManager);
void initialize(double simTimeInSec);
}
......@@ -15,143 +15,71 @@ import net.sourceforge.jFuzzyLogic.FIS; // http://jfuzzylogic.sourceforge.net/ht
public class RouteChoiceThreeCorridors implements INavigationModel {
private FIS fis;
public void update(double simTimeInSec, Collection<Pedestrian> pedestrians, ProcessorManager processorManager) {
@Override
public void initialize(double simTimeInSec) {
// load FuzzyControllLanguage file which stores the logic of the controller (heuristics)
String fileName = "/home/christina/repos/vadere/VadereSimulator/src/org/vadere/simulator/models/strategy/fcl/tipper.fcl";
this.fis = FIS.load(fileName, true); // Load from 'FCL' file
}
FIS fis = FIS.load(fileName, true); // Load from 'FCL' file
fis.setVariable("density", 30); // Set inputs
fis.setVariable("densityCor1", 70);
fis.setVariable("densityCor2", 70);
fis.setVariable("densityCor3", 70);
fis.evaluate(); // Evaluate
System.out.println("Output value:" + fis.getVariable("corridor").getValue()); // Show output variable
// Show each rule (and degree of support)
for( Rule r : fis.getFunctionBlock("tipper").getFuzzyRuleBlock("No1").getRules() ) System.out.println(r);
public void update(double simTimeInSec, Collection<Pedestrian> pedestrians, ProcessorManager processorManager) {
if (simTimeInSec > 0.0) {
// get data from dataprocessors if necessary
LinkedList<Double> densities = new LinkedList<Double>();
densities.add(getDensityFromDataProcessor(5, processorManager));
densities.add(getDensityFromDataProcessor(6, processorManager));
densities.add(getDensityFromDataProcessor(7, processorManager));
double density = getDensityFromDataProcessor(8, processorManager);
System.out.println(simTimeInSec);
double maxDensity = 10.0;
double remainingCapacity;
LinkedList<Double> factors = new LinkedList<Double>();
LinkedList<Integer> factorsNorm = new LinkedList<Integer>();
double sum = 0;
if (density > maxDensity) {
for (Double d : densities) {
remainingCapacity = maxDensity - d;
double fac = 0;
if (remainingCapacity > 0) {
fac = 1;
}
factors.add(fac);
sum += fac;
}
} else {
factors.add(0.0);
factors.add(0.0);
factors.add(1.0);
sum = 1.0;
}
double densityCor1 = getDensityFromDataProcessor(5, processorManager);
double densityCor2 = getDensityFromDataProcessor(6, processorManager);
double densityCor3 = getDensityFromDataProcessor(7, processorManager);
double density = getDensityFromDataProcessor(8, processorManager);
LinkedList<Integer> nextTargets = new LinkedList<Integer>();
int target = getTargetFromFuzzyController(density,densityCor1,densityCor2,densityCor3);
List<Pedestrian> newAgents = pedestrians.stream().filter(p -> p.getFootstepHistory().getFootSteps().size() == 0).collect(Collectors.toList());
int numberOfNewAgents = (int) newAgents.size();
System.out.println(simTimeInSec);
/* if (numberOfNewAgents > 0) {
if (numberOfNewAgents == 1){ sum = 1.0;}
for (Pedestrian pedestrian : newAgents) {
nextTargets.add(target);
pedestrian.setTargets(nextTargets);
}
int[] target = {2001, 2002, 2003};
int c;
}
boolean check = false;
}
while (!check) {
c = 0;
for (Double f : factors) {
int n = (int) (f / sum * numberOfNewAgents);
for (int i = 0; i < n; i++) {
System.out.println("Add " + target[c] );
factorsNorm.add(target[c]);
if (factorsNorm.size() >= numberOfNewAgents) {
check = true;
break;
}
}
c += 1;
}
}
private int getTargetFromFuzzyController(double density,double densityCor1,double densityCor2,double densityCor3) {
fis.setVariable("density", density); // Set inputs
fis.setVariable("densityCor1", densityCor1);
fis.setVariable("densityCor2", densityCor2);
fis.setVariable("densityCor3", densityCor3);
fis.evaluate(); // Evaluate
System.out.println(" ---- > Number " + numberOfNewAgents + ", targets " + factorsNorm);
double corridor = fis.getVariable("corridor").getValue();
int result = (int) Math.round(corridor);
LinkedList<Integer> nextTargets = new LinkedList<Integer>();
System.out.println("Densities: " + density + " " + densityCor1 + " " + densityCor2 +" " + densityCor3); // Show output variable
c = 0;
for (Pedestrian pedestrian : newAgents) {
nextTargets.add(factorsNorm.get(c));
pedestrian.setTargets(nextTargets);
c += 1;
}
}*/
System.out.println("Output value:" + corridor + ", rounded :" + result); // Show output variable
}
// Show each rule (and degree of support)
//for( Rule r : fis.getFunctionBlock("streamControl").getFuzzyRuleBlock("No1").getRules() ) System.out.println(r);
return result;
}
// @Override
// public void update(double simTimeInSec, Collection<Pedestrian> pedestrians, ProcessorManager processorManager) {
// if (simTimeInSec > 0.0) {
// // get data from dataprocessors if necessary
// double density1 = getDensityFromDataProcessor(5, processorManager);
// double density2 = getDensityFromDataProcessor(6, processorManager);
// double density3 = getDensityFromDataProcessor(7, processorManager);
// double density = getDensityFromDataProcessor(8, processorManager);
//
// LinkedList<Integer> nextTargets = new LinkedList<Integer>();
// int newTarget = 2003;
//
// if (density > 10.0){
// newTarget = 2002;}
//
// if (density > 20.0){
// newTarget = 2001;}
//
// for (Pedestrian pedestrian : pedestrians) {
// if (pedestrian.getFootstepHistory().size() == 0) {
// nextTargets.add(newTarget);
// pedestrian.setTargets(nextTargets);
// }
// }
//
// }
// }
private double getDensityFromDataProcessor(int processorId, ProcessorManager processorManager) {
double density = -1.0;
if (processorManager != null) {
TreeMap data = (TreeMap) processorManager.getProcessor(processorId).getData();
if (data.size() > 0) {
density = (double) (int) data.lastEntry().getValue();
density = (double) data.lastEntry().getValue();
}
}
return density;
......
......@@ -10,7 +10,7 @@
pcingola@users.sourceforge.net
*/
FUNCTION_BLOCK tipper // Block definition (there may be more than one block per file)
FUNCTION_BLOCK streamControl // Block definition (there may be more than one block per file)
VAR_INPUT // Define input variables
density : REAL;
......@@ -24,34 +24,34 @@ VAR_OUTPUT // Define output variable
END_VAR
FUZZIFY density
TERM low := (0, 1) (10, 0) ;
TERM medium := (8, 0) (10,1) (20,1) (22,0);
TERM high := (20, 0) (100, 1);
TERM low := (0, 1) (0.25, 0) ;
TERM medium := (0.2, 0) (0.3,1) (0.4,0);
TERM high := (0.3, 0) (4.5, 1);
END_FUZZIFY
FUZZIFY densityCor1
TERM low := (0, 1) (10, 0) ;
TERM medium := (8, 0) (10,1) (20,1) (22,0);
TERM high := (20, 0) (100, 1);
TERM low := (0, 1) (0.25, 0) ;
TERM medium := (0.2, 0) (0.3,1) (0.4,0);
TERM high := (0.3, 0) (4.5, 1);
END_FUZZIFY
FUZZIFY densityCor2
TERM low := (0, 1) (10, 0) ;
TERM medium := (8, 0) (10,1) (20,1) (22,0);
TERM high := (20, 0) (100, 1);
TERM low := (0, 1) (0.25, 0) ;
TERM medium := (0.2, 0) (0.3,1) (0.4,0);
TERM high := (0.3, 0) (4.5, 1);
END_FUZZIFY
FUZZIFY densityCor3
TERM low := (0, 1) (10, 0) ;
TERM medium := (8, 0) (10,1) (20,1) (22,0);
TERM high := (20, 0) (100, 1);
TERM low := (0, 1) (0.25, 0) ;
TERM medium := (0.2, 0) (0.3,1) (0.4,0);
TERM high := (0.3, 0) (4.5, 1);
END_FUZZIFY
DEFUZZIFY corridor //
TERM use1 := (0,0) (1,1) (2,0);
TERM use2 := (1,0) (2,1) (3,0);
TERM use3 := (2,0) (3,1) (4,0);
TERM sendAway := (3,0) (4,1) (5,0);
TERM use3 := (2000,0) (2001,1) (2002,0);
TERM use2 := (2001,0) (2002,1) (2003,0);
TERM use1 := (2002,0) (2003,1) (2004,0);
TERM sendAway := (2003,0) (2004,1) (2005,0);
METHOD : COG; // Use 'Center Of Gravity' defuzzification method
DEFAULT := 0; // Default value is 0 (if no rule activates defuzzifier)
END_DEFUZZIFY
......@@ -62,7 +62,10 @@ RULEBLOCK No1
ACCU : MAX; // Use 'max' accumulation method
RULE 1 : IF density IS high AND densityCor1 is high AND densityCor2 is high AND densityCor3 is high THEN corridor IS sendAway;
RULE 2 : If density IS low OR density is medium AND densityCor1 IS low OR densityCor1 is medium THEN corridor IS use1;
RULE 2 : If densityCor1 IS high AND densityCor2 is low THEN corridor is use2;
RULE 3 : If densityCor1 IS high AND densityCor2 is high THEN corridor is use3;
RULE 3 : If densityCor1 IS low OR densityCor1 IS medium THEN corridor is use1;
END_RULEBLOCK
END_FUNCTION_BLOCK
package org.vadere.simulator.projects.dataprocessing.processor;
import org.vadere.simulator.control.simulation.SimulationState;
import org.vadere.simulator.projects.dataprocessing.datakey.NoDataKey;
import org.vadere.simulator.projects.dataprocessing.datakey.TimestepKey;
import org.vadere.state.attributes.processor.AttributesAreaDensityCountingProcessor;
import org.vadere.state.attributes.processor.AttributesProcessor;
......@@ -20,7 +21,7 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
*/
@DataProcessorClass(label = "AreaDensityCountingProcessor")
public class AreaDensityCountingProcessor extends AreaDataProcessor<Integer> {
public class AreaDensityCountingProcessor extends AreaDataProcessor<Double> {
public AreaDensityCountingProcessor() {
super("areaDensityCounting");
......@@ -45,14 +46,20 @@ public class AreaDensityCountingProcessor extends AreaDataProcessor<Integer> {
}
}
this.putValue(new TimestepKey(state.getStep()), pedCount);
double result;
if (getAttributes().getCountsInsteadOfDensity()) { result = pedCount; }
else {
double measurementAreaSize = getMeasurementArea().asPolygon().getArea();
result = pedCount/measurementAreaSize; }
this.putValue(new TimestepKey(state.getStep()),result);
}
@Override
public AttributesProcessor getAttributes() {
public AttributesAreaDensityCountingProcessor getAttributes() {
if(super.getAttributes() == null) {
setAttributes(new AttributesAreaDensityCountingProcessor());
}
return super.getAttributes();
return (AttributesAreaDensityCountingProcessor) super.getAttributes();
}
}
......@@ -5,5 +5,26 @@ package org.vadere.state.attributes.processor;
*/
public class AttributesAreaDensityCountingProcessor extends AttributesAreaProcessor {
boolean countsInsteadOfDensity = true;
private int measurementAreaId = -1;
public boolean getCountsInsteadOfDensity()
{
return countsInsteadOfDensity;
}
public void setCountsInsteadOfDensity(boolean countsInsteadOfDensity)
{
this.countsInsteadOfDensity = countsInsteadOfDensity;
}
public int getMeasurementAreaId() {
return this.measurementAreaId;
}
public void setMeasurementAreaId(int measurementAreaId) {
checkSealed();
this.measurementAreaId = measurementAreaId;
}
}
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