Commit 67c16d94 authored by Christina's avatar Christina
Browse files

refactored + extended supermarket topography

parent de66d70e
Pipeline #237509 failed with stages
in 2 minutes and 44 seconds
supermarket_covid19
\ No newline at end of file
...@@ -42,6 +42,7 @@ public class TargetChangerController { ...@@ -42,6 +42,7 @@ public class TargetChangerController {
int seed; int seed;
BinomialDistribution binomialDistribution; BinomialDistribution binomialDistribution;
private Random random; private Random random;
private LinkedList<BinomialDistribution> binomialDistributions = null;
// Constructors // Constructors
public TargetChangerController(Topography topography, TargetChanger targetChanger, Random random) { public TargetChangerController(Topography topography, TargetChanger targetChanger, Random random) {
...@@ -55,17 +56,35 @@ public class TargetChangerController { ...@@ -55,17 +56,35 @@ public class TargetChangerController {
randomGenerator.setSeed(seed); randomGenerator.setSeed(seed);
LinkedList<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()".
// 0.5 = probabilityToChangeTarget binomialDistributions = getBinomialDistributions();
binomialDistribution = new BinomialDistribution(randomGenerator, trials, 0.5);
} }
// Getters // Getters
public Map<Integer, Agent> getProcessedAgents() { public Map<Integer, Agent> getProcessedAgents() {
return processedAgents; return processedAgents;
} }
public LinkedList<BinomialDistribution> getBinomialDistributions(){
if (binomialDistributions == null) {
LinkedList<BinomialDistribution> binomialDistributionsL = new LinkedList<>();
seed = this.random.nextInt();
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
for (Double probability : targetChanger.getAttributes().getProbabilityToChangeTarget()) {
binomialDistributionsL.add(new BinomialDistribution(randomGenerator, BINOMIAL_DISTRIBUTION_SUCCESS_VALUE, probability));
}
binomialDistributions = binomialDistributionsL;
}
return binomialDistributions;
}
// Public Methods // Public Methods
public void update(double simTimeInSec) { public void update(double simTimeInSec) {
for (DynamicElement element : getDynamicElementsNearTargetChangerArea()) { for (DynamicElement element : getDynamicElementsNearTargetChangerArea()) {
...@@ -86,7 +105,7 @@ public class TargetChangerController { ...@@ -86,7 +105,7 @@ public class TargetChangerController {
if (keepTargets.size() > 0) { if (keepTargets.size() > 0) {
if (targetChanger.getAttributes().isNextTargetIsPedestrian()) { if (targetChanger.getAttributes().isNextTargetIsPedestrian()) {
useDynamicTargetForAgentOrUseStaticAsFallback(agent); useDynamicTargetForAgentOrUseStaticAsFallback(agent, keepTargets);
} else { } else {
useStaticTargetForAgent(agent,keepTargets); useStaticTargetForAgent(agent,keepTargets);
} }
...@@ -101,33 +120,24 @@ public class TargetChangerController { ...@@ -101,33 +120,24 @@ public class TargetChangerController {
private LinkedList<Integer> getFilteredTargetList(){ private LinkedList<Integer> getFilteredTargetList(){
boolean keepTarget;
int targetId;
int binomialDistributionSample;
int binomialDistributionSample;
LinkedList<Integer> keepTargets = new LinkedList<>(); LinkedList<Integer> keepTargets = new LinkedList<>();
seed = this.random.nextInt();
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
int index = 0; int index = 0;
for( Double probability : targetChanger.getAttributes().getProbabilityToChangeTarget() ) { for( BinomialDistribution binomialDistribution : getBinomialDistributions() ) {
binomialDistribution = new BinomialDistribution(randomGenerator, BINOMIAL_DISTRIBUTION_SUCCESS_VALUE, probability);
binomialDistributionSample = binomialDistribution.sample(); binomialDistributionSample = binomialDistribution.sample();
keepTarget = (binomialDistributionSample == BINOMIAL_DISTRIBUTION_SUCCESS_VALUE);
if (keepTarget){ if (binomialDistributionSample == BINOMIAL_DISTRIBUTION_SUCCESS_VALUE){
if (targetChanger.getAttributes().getProbabilityToChangeTarget().size() == 1){ if (targetChanger.getAttributes().getProbabilityToChangeTarget().size() == 1){
keepTargets = targetChanger.getAttributes().getNextTarget(); keepTargets = targetChanger.getAttributes().getNextTarget();
break; break;
} }
else { else {
targetId = targetChanger.getAttributes().getNextTarget().get(index); keepTargets.add(targetChanger.getAttributes().getNextTarget().get(index));
keepTargets.add(targetId);
} }
} }
index += 1; index += 1;
...@@ -170,7 +180,7 @@ public class TargetChangerController { ...@@ -170,7 +180,7 @@ public class TargetChangerController {
} }
} }
private void useDynamicTargetForAgentOrUseStaticAsFallback(Agent agent) { private void useDynamicTargetForAgentOrUseStaticAsFallback(Agent agent, LinkedList<Integer> keepTargets) {
int nextTarget = (targetChanger.getAttributes().getNextTarget().size() > 0) int nextTarget = (targetChanger.getAttributes().getNextTarget().size() > 0)
? targetChanger.getAttributes().getNextTarget().get(0) ? targetChanger.getAttributes().getNextTarget().get(0)
: Attributes.ID_NOT_SET; : Attributes.ID_NOT_SET;
...@@ -190,7 +200,7 @@ public class TargetChangerController { ...@@ -190,7 +200,7 @@ public class TargetChangerController {
Pedestrian pedToFollow = (pedsWithFollowers.isEmpty()) ? pedsWithCorrectTargetId.get(0) : pedsWithFollowers.get(0); Pedestrian pedToFollow = (pedsWithFollowers.isEmpty()) ? pedsWithCorrectTargetId.get(0) : pedsWithFollowers.get(0);
agentFollowsOtherPedestrian(agent, pedToFollow); agentFollowsOtherPedestrian(agent, pedToFollow);
} else { } else {
LinkedList<Integer> keepTargets = getFilteredTargetList();
useStaticTargetForAgent(agent, keepTargets); useStaticTargetForAgent(agent, keepTargets);
} }
} }
...@@ -208,7 +218,6 @@ public class TargetChangerController { ...@@ -208,7 +218,6 @@ public class TargetChangerController {
} }
private void useStaticTargetForAgent(Agent agent, LinkedList<Integer> keepTargets) { private void useStaticTargetForAgent(Agent agent, LinkedList<Integer> keepTargets) {
agent.setTargets(keepTargets); agent.setTargets(keepTargets);
agent.setNextTargetListIndex(0); agent.setNextTargetListIndex(0);
agent.setIsCurrentTargetAnAgent(false); agent.setIsCurrentTargetAnAgent(false);
......
...@@ -3,6 +3,7 @@ package org.vadere.state.attributes.scenario; ...@@ -3,6 +3,7 @@ package org.vadere.state.attributes.scenario;
import org.vadere.state.attributes.AttributesEmbedShape; import org.vadere.state.attributes.AttributesEmbedShape;
import org.vadere.util.geometry.shapes.VShape; import org.vadere.util.geometry.shapes.VShape;
import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
/** /**
...@@ -35,7 +36,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape { ...@@ -35,7 +36,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
* Change target of a given pedestrian only with a certain probability between * Change target of a given pedestrian only with a certain probability between
* 0 and 1. * 0 and 1.
*/ */
private LinkedList<Double> probabilityToChangeTarget = new LinkedList<>(); private LinkedList<Double> probabilityToChangeTarget = new LinkedList<Double>(Arrays.asList(1.0));
// Constructors // Constructors
public AttributesTargetChanger() { public AttributesTargetChanger() {
......
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