Commit 66fe9454 authored by Christina's avatar Christina
Browse files

extended probability list - TBD

parent 85f5d96d
......@@ -50,9 +50,11 @@ public class TargetChangerController {
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
double probabilityToChangeTarget = targetChanger.getAttributes().getProbabilityToChangeTarget();
LinkedList<Double> probabilityToChangeTarget = targetChanger.getAttributes().getProbabilityToChangeTarget();
int trials = BINOMIAL_DISTRIBUTION_SUCCESS_VALUE; // I.e., possible outcomes are 0 and 1 when calling "sample()".
binomialDistribution = new BinomialDistribution(randomGenerator, trials, probabilityToChangeTarget);
// 0.5 = probabilityToChangeTarget
binomialDistribution = new BinomialDistribution(randomGenerator, trials, 0.5);
}
// Getters
......@@ -75,6 +77,8 @@ public class TargetChangerController {
if (hasAgentReachedTargetChangerArea(agent) && processedAgents.containsKey(agent.getId()) == false) {
logEnteringTimeOfAgent(agent, simTimeInSec);
int nextTargetListIndex = agent.getNextTargetListIndex();
int binomialDistributionSample = binomialDistribution.sample();
boolean changeTarget = (binomialDistributionSample == BINOMIAL_DISTRIBUTION_SUCCESS_VALUE);
......
......@@ -159,10 +159,12 @@ public class TargetChangerControllerTest {
@Test
public void updateChangesTargetListOfAffectedPedestrianIfProbabilityIsOne() {
LinkedList<Integer> nextTarget = createIntegerList(2);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
......@@ -187,7 +189,7 @@ public class TargetChangerControllerTest {
pedestrians.get(1).setNextTargetListIndex(nextTargetIndex);
LinkedList<Integer> nextTarget = createIntegerList(2);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
......@@ -207,7 +209,7 @@ public class TargetChangerControllerTest {
@Test
public void updateDoesNotChangeTargetListOfAffectedPedestrianIfProbabilityIsZero() {
LinkedList<Integer> nextTarget = createIntegerList(2);
double probability = 0.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
......@@ -229,7 +231,7 @@ public class TargetChangerControllerTest {
@Test
public void targetChangerWithListOfTargetsAndStaticTargets() {
LinkedList<Integer> nextTarget = createIntegerList(2, 1);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
pedestrians.forEach(p -> p.setTargets(createIntegerList(1)));
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
......@@ -251,7 +253,7 @@ public class TargetChangerControllerTest {
@Test
public void targetChangerWithListOfTargetsAndDynamicTargets() { //must choose first element
LinkedList<Integer> nextTarget = createIntegerList(1, 2);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
pedestrians.forEach(p -> p.setTargets(createIntegerList(1)));
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
......@@ -274,7 +276,7 @@ public class TargetChangerControllerTest {
@Test
public void updateAddsTargetPedestrianToTopographyIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(1);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
......@@ -296,7 +298,7 @@ public class TargetChangerControllerTest {
@Test
public void updateChangesTargetListOfAffectedPedestrianIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(1);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
......@@ -320,7 +322,7 @@ public class TargetChangerControllerTest {
@Test
public void updateModifiesFollowersIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(1);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
......@@ -342,7 +344,8 @@ public class TargetChangerControllerTest {
@Test
public void updateModifiesPedestrianWithExistingFollwersIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(1);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
// Add two new agents were one follows the other.
List<Pedestrian> newPedestrians = createTwoPedestrianWithTargetT1(3);
......@@ -377,7 +380,7 @@ public class TargetChangerControllerTest {
@Test
public void updateUseStaticTargetAsFallbackIfNoPedestrianIsFoundIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(3);
double probability = 1.0;
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
......
......@@ -4,7 +4,6 @@ import org.vadere.state.attributes.AttributesEmbedShape;
import org.vadere.util.geometry.shapes.VShape;
import java.util.LinkedList;
import java.util.List;
/**
* Attributes of "TargetChanger" object, used by "TargetChangerController" during simulation.
......@@ -36,7 +35,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
* Change target of a given pedestrian only with a certain probability between
* 0 and 1.
*/
private double probabilityToChangeTarget = 0.0;
private LinkedList<Double> probabilityToChangeTarget = new LinkedList<>();
// Constructors
public AttributesTargetChanger() {
......@@ -51,15 +50,18 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
this.id = id;
}
public AttributesTargetChanger(final VShape shape, final int id, double reachDistance, LinkedList<Integer> nextTarget, double probabilityToChangeTarget) {
public AttributesTargetChanger(final VShape shape, final int id, double reachDistance, LinkedList<Integer> nextTarget, LinkedList<Double> probabilitiesToChangeTarget) {
this.shape = shape;
this.id = id;
this.reachDistance = reachDistance;
this.nextTarget = nextTarget;
for (Double probabilityToChangeTarget : probabilitiesToChangeTarget){
if (probabilityToChangeTarget < 0.0 || probabilityToChangeTarget > 1.0) {
throw new IllegalArgumentException("Probability must be in range 0.0 to 1.0!");
if (probabilityToChangeTarget < 0.0 || probabilityToChangeTarget > 1.0) {
throw new IllegalArgumentException("Probability must be in range 0.0 to 1.0!");
}
}
this.probabilityToChangeTarget = probabilityToChangeTarget;
}
......@@ -85,7 +87,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
return nextTarget;
}
public double getProbabilityToChangeTarget() {
public LinkedList<Double> getProbabilityToChangeTarget() {
return probabilityToChangeTarget;
}
......@@ -113,9 +115,13 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
this.nextTarget = nextTarget;
}
public void setProbabilityToChangeTarget(double probabilityToChangeTarget) {
if (probabilityToChangeTarget < 0.0 || probabilityToChangeTarget > 1.0) {
throw new IllegalArgumentException("Probability must be in range 0.0 to 1.0!");
public void setProbabilityToChangeTarget(LinkedList<Double> probabilitiesToChangeTarget) {
for (Double probabilityToChangeTarget : probabilitiesToChangeTarget){
if (probabilityToChangeTarget < 0.0 || probabilityToChangeTarget > 1.0) {
throw new IllegalArgumentException("Probability must be in range 0.0 to 1.0!");
}
}
this.probabilityToChangeTarget = probabilityToChangeTarget;
}
......
Supports Markdown
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