Commit de66d70e authored by Christina's avatar Christina
Browse files

refactored

parent ef3d810b
Pipeline #237232 failed with stages
in 2 minutes and 3 seconds
...@@ -81,43 +81,10 @@ public class TargetChangerController { ...@@ -81,43 +81,10 @@ public class TargetChangerController {
if (hasAgentReachedTargetChangerArea(agent) && processedAgents.containsKey(agent.getId()) == false) { if (hasAgentReachedTargetChangerArea(agent) && processedAgents.containsKey(agent.getId()) == false) {
logEnteringTimeOfAgent(agent, simTimeInSec); logEnteringTimeOfAgent(agent, simTimeInSec);
boolean changeTarget = false;
boolean keepTarget;
int targetId;
int binomialDistributionSample;
LinkedList<Integer> keepTargets = new LinkedList<>(); LinkedList<Integer> keepTargets = getFilteredTargetList();
seed = this.random.nextInt(); if (keepTargets.size() > 0) {
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
int index = 0;
for( Double probability : targetChanger.getAttributes().getProbabilityToChangeTarget() ) {
binomialDistribution = new BinomialDistribution(randomGenerator, BINOMIAL_DISTRIBUTION_SUCCESS_VALUE, probability);
binomialDistributionSample = binomialDistribution.sample();
keepTarget = (binomialDistributionSample == BINOMIAL_DISTRIBUTION_SUCCESS_VALUE);
if (keepTarget){
changeTarget = true;
if (targetChanger.getAttributes().getProbabilityToChangeTarget().size() == 1){
keepTargets = targetChanger.getAttributes().getNextTarget();
break;
}
else {
targetId = targetChanger.getAttributes().getNextTarget().get(index);
keepTargets.add(targetId);
}
}
index += 1;
}
if (changeTarget) {
if (targetChanger.getAttributes().isNextTargetIsPedestrian()) { if (targetChanger.getAttributes().isNextTargetIsPedestrian()) {
useDynamicTargetForAgentOrUseStaticAsFallback(agent); useDynamicTargetForAgentOrUseStaticAsFallback(agent);
} else { } else {
...@@ -132,6 +99,44 @@ public class TargetChangerController { ...@@ -132,6 +99,44 @@ public class TargetChangerController {
} }
} }
private LinkedList<Integer> getFilteredTargetList(){
boolean keepTarget;
int targetId;
int binomialDistributionSample;
LinkedList<Integer> keepTargets = new LinkedList<>();
seed = this.random.nextInt();
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
int index = 0;
for( Double probability : targetChanger.getAttributes().getProbabilityToChangeTarget() ) {
binomialDistribution = new BinomialDistribution(randomGenerator, BINOMIAL_DISTRIBUTION_SUCCESS_VALUE, probability);
binomialDistributionSample = binomialDistribution.sample();
keepTarget = (binomialDistributionSample == BINOMIAL_DISTRIBUTION_SUCCESS_VALUE);
if (keepTarget){
if (targetChanger.getAttributes().getProbabilityToChangeTarget().size() == 1){
keepTargets = targetChanger.getAttributes().getNextTarget();
break;
}
else {
targetId = targetChanger.getAttributes().getNextTarget().get(index);
keepTargets.add(targetId);
}
}
index += 1;
}
return keepTargets;
}
private Collection<DynamicElement> getDynamicElementsNearTargetChangerArea() { private Collection<DynamicElement> getDynamicElementsNearTargetChangerArea() {
final Rectangle2D areaBounds = targetChanger.getShape().getBounds2D(); final Rectangle2D areaBounds = targetChanger.getShape().getBounds2D();
final VPoint areaCenter = new VPoint(areaBounds.getCenterX(), areaBounds.getCenterY()); final VPoint areaCenter = new VPoint(areaBounds.getCenterX(), areaBounds.getCenterY());
...@@ -185,8 +190,8 @@ public class TargetChangerController { ...@@ -185,8 +190,8 @@ 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> usedTargets = targetChanger.getAttributes().getNextTarget(); LinkedList<Integer> keepTargets = getFilteredTargetList();
useStaticTargetForAgent(agent, usedTargets); useStaticTargetForAgent(agent, keepTargets);
} }
} }
......
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