Commit 8b975532 authored by Christina's avatar Christina
Browse files

adapted UnitTests TargetChangerController

parent 8d8dbadb
Pipeline #238185 failed with stages
in 5 minutes and 53 seconds
......@@ -2,9 +2,7 @@ package org.vadere.simulator.control.scenarioelements;
import org.apache.commons.math3.distribution.BinomialDistribution;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.jcodec.common.DictionaryCompressor;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.scenario.AttributesTargetChanger;
import org.vadere.state.scenario.*;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
......@@ -37,10 +35,11 @@ public class TargetChangerController {
// Member Variables
public final TargetChanger targetChanger;
private LinkedList<Double> probabilitiesToChangeTarget;
private Topography topography;
private Map<Integer, Agent> processedAgents;
int seed;
BinomialDistribution binomialDistribution;
//BinomialDistribution binomialDistribution;
private Random random;
private LinkedList<BinomialDistribution> binomialDistributions = null;
......@@ -51,12 +50,10 @@ public class TargetChangerController {
this.processedAgents = new HashMap<>();
this.random = random;
seed = random.nextInt();
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
LinkedList<Double> probabilityToChangeTarget = targetChanger.getAttributes().getProbabilityToChangeTarget();
this.probabilitiesToChangeTarget = targetChanger.getAttributes().getProbabilitiesToChangeTarget();
seed = random.nextInt();
binomialDistributions = getBinomialDistributions();
}
......@@ -71,11 +68,11 @@ public class TargetChangerController {
if (binomialDistributions == null) {
LinkedList<BinomialDistribution> binomialDistributionsL = new LinkedList<>();
seed = this.random.nextInt();
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
randomGenerator.setSeed(this.seed);
for (Double probability : targetChanger.getAttributes().getProbabilityToChangeTarget()) {
for (Double probability : this.probabilitiesToChangeTarget) {
binomialDistributionsL.add(new BinomialDistribution(randomGenerator, BINOMIAL_DISTRIBUTION_SUCCESS_VALUE, probability));
}
binomialDistributions = binomialDistributionsL;
......@@ -103,6 +100,8 @@ public class TargetChangerController {
LinkedList<Integer> keepTargets = getFilteredTargetList();
int aa = keepTargets.size();
if (keepTargets.size() > 0) {
if (targetChanger.getAttributes().isNextTargetIsPedestrian()) {
useDynamicTargetForAgentOrUseStaticAsFallback(agent, keepTargets);
......@@ -132,7 +131,7 @@ public class TargetChangerController {
if (binomialDistributionSample == BINOMIAL_DISTRIBUTION_SUCCESS_VALUE){
if (targetChanger.getAttributes().getProbabilityToChangeTarget().size() == 1){
if (targetChanger.getAttributes().getProbabilitiesToChangeTarget().size() == 1){
keepTargets = targetChanger.getAttributes().getNextTarget();
break;
}
......
......@@ -160,12 +160,12 @@ public class TargetChangerControllerTest {
public void updateChangesTargetListOfAffectedPedestrianIfProbabilityIsOne() {
LinkedList<Integer> nextTarget = createIntegerList(2);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......@@ -189,11 +189,11 @@ public class TargetChangerControllerTest {
pedestrians.get(1).setNextTargetListIndex(nextTargetIndex);
LinkedList<Integer> nextTarget = createIntegerList(2);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......@@ -209,11 +209,11 @@ public class TargetChangerControllerTest {
@Test
public void updateDoesNotChangeTargetListOfAffectedPedestrianIfProbabilityIsZero() {
LinkedList<Integer> nextTarget = createIntegerList(2);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(0.0)); // must be 0
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......@@ -231,12 +231,12 @@ public class TargetChangerControllerTest {
@Test
public void targetChangerWithListOfTargetsAndStaticTargets() {
LinkedList<Integer> nextTarget = createIntegerList(2, 1);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
pedestrians.forEach(p -> p.setTargets(createIntegerList(1)));
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......@@ -253,12 +253,12 @@ public class TargetChangerControllerTest {
@Test
public void targetChangerWithListOfTargetsAndDynamicTargets() { //must choose first element
LinkedList<Integer> nextTarget = createIntegerList(1, 2);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
pedestrians.forEach(p -> p.setTargets(createIntegerList(1)));
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
attributesTargetChanger.setNextTargetIsPedestrian(true);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
......@@ -276,12 +276,12 @@ public class TargetChangerControllerTest {
@Test
public void updateAddsTargetPedestrianToTopographyIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(1);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setNextTargetIsPedestrian(true);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......@@ -298,12 +298,12 @@ public class TargetChangerControllerTest {
@Test
public void updateChangesTargetListOfAffectedPedestrianIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(1);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setNextTargetIsPedestrian(true);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......@@ -322,12 +322,12 @@ public class TargetChangerControllerTest {
@Test
public void updateModifiesFollowersIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(1);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setNextTargetIsPedestrian(true);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......@@ -344,7 +344,7 @@ public class TargetChangerControllerTest {
@Test
public void updateModifiesPedestrianWithExistingFollwersIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(1);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
// Add two new agents were one follows the other.
......@@ -363,7 +363,7 @@ public class TargetChangerControllerTest {
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setNextTargetIsPedestrian(true);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......@@ -380,12 +380,12 @@ public class TargetChangerControllerTest {
@Test
public void updateUseStaticTargetAsFallbackIfNoPedestrianIsFoundIfTargetIsDynamic() {
LinkedList<Integer> nextTarget = createIntegerList(3);
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0,1.0,0.5)); // must be 1
LinkedList<Double> probability = new LinkedList<Double>(Arrays.asList(1.0)); // must be 1
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setNextTargetIsPedestrian(true);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
attributesTargetChanger.setProbabilitiesToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
......
......@@ -36,7 +36,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
* Change target of a given pedestrian only with a certain probability between
* 0 and 1.
*/
private LinkedList<Double> probabilityToChangeTarget = new LinkedList<Double>(Arrays.asList(1.0));
private LinkedList<Double> probabilitiesToChangeTarget = new LinkedList<Double>(Arrays.asList(1.0));
// Constructors
public AttributesTargetChanger() {
......@@ -63,7 +63,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
}
}
this.probabilityToChangeTarget = probabilityToChangeTarget;
this.probabilitiesToChangeTarget = this.probabilitiesToChangeTarget;
}
// Getters
......@@ -88,8 +88,8 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
return nextTarget;
}
public LinkedList<Double> getProbabilityToChangeTarget() {
return probabilityToChangeTarget;
public LinkedList<Double> getProbabilitiesToChangeTarget() {
return probabilitiesToChangeTarget;
}
// Setters
......@@ -116,7 +116,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
this.nextTarget = nextTarget;
}
public void setProbabilityToChangeTarget(LinkedList<Double> probabilitiesToChangeTarget) {
public void setProbabilitiesToChangeTarget(LinkedList<Double> probabilitiesToChangeTarget) {
for (Double probabilityToChangeTarget : probabilitiesToChangeTarget){
......@@ -124,7 +124,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
throw new IllegalArgumentException("Probability must be in range 0.0 to 1.0!");
}
}
this.probabilityToChangeTarget = probabilityToChangeTarget;
this.probabilitiesToChangeTarget = probabilitiesToChangeTarget;
}
}
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