Commit 83e99917 authored by Christina's avatar Christina

add fuzzy control logic

parent 680a5897
Pipeline #300673 failed with stages
in 2 minutes and 16 seconds
......@@ -455,4 +455,4 @@
},
"stimulusInfos" : [ ]
}
}
\ No newline at end of file
}
......@@ -35,6 +35,29 @@
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>net.sourceforge.jFuzzyLogic</groupId>
<artifactId>jFuzzyLogic</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>../lib/jFuzzyLogic.jar</file>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.nativelibs4java</groupId>
<artifactId>maven-javacl-plugin</artifactId>
......@@ -107,6 +130,8 @@
<platform.dependency>windows-x86_64</platform.dependency>
</properties>-->
<dependencies>
<dependency>
<groupId>commons-codec</groupId>
......@@ -115,6 +140,12 @@
</dependency>
<!-- module dependencies -->
<dependency>
<groupId>net.sourceforge.jFuzzyLogic</groupId>
<artifactId>jFuzzyLogic</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>state</artifactId>
......
package org.vadere.simulator.models.strategy;
import net.sourceforge.jFuzzyLogic.plot.JFuzzyChart;
import net.sourceforge.jFuzzyLogic.rule.Rule;
import org.vadere.simulator.control.strategy.models.navigation.INavigationModel;
import org.vadere.simulator.projects.dataprocessing.ProcessorManager;
import org.vadere.state.scenario.Pedestrian;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import net.sourceforge.jFuzzyLogic.FIS; // http://jfuzzylogic.sourceforge.net/html/index.html
public class RouteChoiceThreeCorridors implements INavigationModel {
......@@ -14,12 +19,26 @@ public class RouteChoiceThreeCorridors implements INavigationModel {
public void update(double simTimeInSec, Collection<Pedestrian> pedestrians, ProcessorManager processorManager) {
String fileName = "/home/christina/repos/vadere/VadereSimulator/src/org/vadere/simulator/models/strategy/fcl/tipper.fcl";
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);
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) );
densities.add(getDensityFromDataProcessor(5, processorManager));
densities.add(getDensityFromDataProcessor(6, processorManager));
densities.add(getDensityFromDataProcessor(7, processorManager));
double density = getDensityFromDataProcessor(8, processorManager);
......@@ -29,7 +48,7 @@ public class RouteChoiceThreeCorridors implements INavigationModel {
LinkedList<Integer> factorsNorm = new LinkedList<Integer>();
double sum = 0;
if (density > maxDensity){
if (density > maxDensity) {
for (Double d : densities) {
remainingCapacity = maxDensity - d;
......@@ -41,8 +60,7 @@ public class RouteChoiceThreeCorridors implements INavigationModel {
sum += fac;
}
}
else{
} else {
factors.add(0.0);
factors.add(0.0);
factors.add(1.0);
......@@ -50,27 +68,47 @@ public class RouteChoiceThreeCorridors implements INavigationModel {
}
List<Pedestrian> newAgents = pedestrians.stream().filter(p-> p.getFootstepHistory().getFootSteps().size() == 0).collect(Collectors.toList());
List<Pedestrian> newAgents = pedestrians.stream().filter(p -> p.getFootstepHistory().getFootSteps().size() == 0).collect(Collectors.toList());
int numberOfNewAgents = (int) newAgents.size();
int[] target = {2001,2002,2003};
int c = 0;
for (Double f : factors){
int n = (int) (f/sum*numberOfNewAgents);
for (int i = 0; i < n; i++){
factorsNorm.add( target[c] );
System.out.println(simTimeInSec);
/* if (numberOfNewAgents > 0) {
if (numberOfNewAgents == 1){ sum = 1.0;}
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;
}
}
c += 1;
}
LinkedList<Integer> nextTargets = new LinkedList<Integer>();
c = 0;
for (Pedestrian pedestrian : newAgents) {
nextTargets.add(factorsNorm.get(c));
pedestrian.setTargets(nextTargets);
c+=1;
}
System.out.println(" ---- > Number " + numberOfNewAgents + ", targets " + factorsNorm);
LinkedList<Integer> nextTargets = new LinkedList<Integer>();
c = 0;
for (Pedestrian pedestrian : newAgents) {
nextTargets.add(factorsNorm.get(c));
pedestrian.setTargets(nextTargets);
c += 1;
}
}*/
}
......
/*
Example: A tip calculation FIS (fuzzy inference system)
Calculates tip based on 'servie' and 'food'
If you want to about this example (and fuzzy logic), please
read Matlab's tutorial on fuzzy logic toolbox
http://www.mathworks.com/access/helpdesk/help/pdf_doc/fuzzy/fuzzy.pdf
Pablo Cingolani
pcingola@users.sourceforge.net
*/
FUNCTION_BLOCK tipper // Block definition (there may be more than one block per file)
VAR_INPUT // Define input variables
density : REAL;
densityCor1 : REAL;
densityCor2 : REAL;
densityCor3 : REAL;
END_VAR
VAR_OUTPUT // Define output variable
corridor : REAL;
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);
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);
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);
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);
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);
METHOD : COG; // Use 'Center Of Gravity' defuzzification method
DEFAULT := 0; // Default value is 0 (if no rule activates defuzzifier)
END_DEFUZZIFY
RULEBLOCK No1
AND : MIN; // Use 'min' for 'and' (also implicit use 'max' for 'or' to fulfill DeMorgan's Law)
ACT : MIN; // Use 'min' activation method
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;
END_RULEBLOCK
END_FUNCTION_BLOCK
......@@ -17,6 +17,9 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
......@@ -118,6 +121,20 @@
<!-- global dependencies! -->
<dependencies>
<!--<dependency>
<groupId>net.sourceforge.jFuzzyLogic</groupId>
<artifactId>jFuzzyLogic</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/jFuzzyLogic.jar</systemPath>
</dependency>-->
<!-- https://mvnrepository.com/artifact/net.sourceforge.jFuzzyLogic/jFuzzyLogic -->
<!-- <dependency>-->
<!-- <groupId>net.sourceforge.jFuzzyLogic</groupId>-->
<!-- <artifactId>jFuzzyLogic</artifactId>-->
<!-- <version>1.2.1</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
......
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