The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit b82e83bc authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "TargetChangerController", added optimization to avoid unnecessary...

In "TargetChangerController", added optimization to avoid unnecessary calculations of dynamic floor fields
parent d56dc536
Pipeline #165720 passed with stages
in 123 minutes and 4 seconds
...@@ -134,8 +134,13 @@ public class TargetChangerController { ...@@ -134,8 +134,13 @@ public class TargetChangerController {
.collect(Collectors.toList()); .collect(Collectors.toList());
if (pedsWithCorrectTargetId.size() > 0) { if (pedsWithCorrectTargetId.size() > 0) {
// Maybe, choose randomly in the long run. // Try to use a pedestrian which has already some followers
Pedestrian pedToFollow = pedsWithCorrectTargetId.get(0); // to avoid calculating multiple dynamic floor fields.
List<Pedestrian> pedsWithFollowers = pedsWithCorrectTargetId.stream()
.filter(pedestrian -> pedestrian.getFollowers().isEmpty() == false)
.collect(Collectors.toList());
Pedestrian pedToFollow = (pedsWithFollowers.isEmpty()) ? pedsWithCorrectTargetId.get(0) : pedsWithFollowers.get(0);
agentFollowsOtherPedestrian(agent, pedToFollow); agentFollowsOtherPedestrian(agent, pedToFollow);
} else { } else {
useStaticTargetForAgent(agent); useStaticTargetForAgent(agent);
......
...@@ -52,7 +52,7 @@ public class TargetChangerControllerTest { ...@@ -52,7 +52,7 @@ public class TargetChangerControllerTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
topography = new Topography(); topography = new Topography();
pedestrians = createTwoPedestrianWithTargetT1(); pedestrians = createTwoPedestrianWithTargetT1(1);
targets = createTwoTargets(); targets = createTwoTargets();
simTimeInSec = 0; simTimeInSec = 0;
...@@ -64,7 +64,7 @@ public class TargetChangerControllerTest { ...@@ -64,7 +64,7 @@ public class TargetChangerControllerTest {
} }
} }
private List<Pedestrian> createTwoPedestrianWithTargetT1() { private List<Pedestrian> createTwoPedestrianWithTargetT1(int startId) {
int seed = 0; int seed = 0;
Random random = new Random(seed); Random random = new Random(seed);
...@@ -73,11 +73,11 @@ public class TargetChangerControllerTest { ...@@ -73,11 +73,11 @@ public class TargetChangerControllerTest {
LinkedList<Integer> targetsPed2 = new LinkedList<>(); LinkedList<Integer> targetsPed2 = new LinkedList<>();
targetsPed2.add(1); targetsPed2.add(1);
Pedestrian pedestrian1 = new Pedestrian(new AttributesAgent(1), random); Pedestrian pedestrian1 = new Pedestrian(new AttributesAgent(startId), random);
pedestrian1.setPosition(new VPoint(1, 1)); pedestrian1.setPosition(new VPoint(1, 1));
pedestrian1.setTargets(targetsPed1); pedestrian1.setTargets(targetsPed1);
Pedestrian pedestrian2 = new Pedestrian(new AttributesAgent(2), random); Pedestrian pedestrian2 = new Pedestrian(new AttributesAgent(startId + 1), random);
pedestrian2.setPosition(new VPoint(5, 2)); pedestrian2.setPosition(new VPoint(5, 2));
pedestrian2.setTargets(targetsPed2); pedestrian2.setTargets(targetsPed2);
...@@ -259,6 +259,41 @@ public class TargetChangerControllerTest { ...@@ -259,6 +259,41 @@ public class TargetChangerControllerTest {
assertEquals(pedestrians.get(1).getId(), followers.get(0).getId()); assertEquals(pedestrians.get(1).getId(), followers.get(0).getId());
} }
@Test
public void updateModifiesPedestrianWithExistingFollwersIfTargetIsDynamic() {
int nextTarget = 1;
double probability = 1.0;
// Add two new agents were one follows the other.
List<Pedestrian> newPedestrians = createTwoPedestrianWithTargetT1(3);
LinkedList<Agent> follower = new LinkedList<>();
follower.add(newPedestrians.get(1));
newPedestrians.get(0).setPosition(new VPoint(1, 2));
newPedestrians.get(1).setPosition(new VPoint(1, 3));
newPedestrians.get(0).setFollowers(follower);
for (Pedestrian pedestrian : newPedestrians) {
topography.addElement(pedestrian);
}
AttributesTargetChanger attributesTargetChanger = createAttributesWithFixedRectangle();
attributesTargetChanger.setNextTarget(nextTarget);
attributesTargetChanger.setNextTargetIsPedestrian(true);
attributesTargetChanger.setProbabilityToChangeTarget(probability);
TargetChanger targetChanger = new TargetChanger(attributesTargetChanger);
TargetChangerController controllerUnderTest = createTargetChangerController(targetChanger);
assertEquals(0, pedestrians.get(0).getFollowers().size());
assertEquals(1, newPedestrians.get(0).getFollowers().size());
controllerUnderTest.update(simTimeInSec);
assertEquals(0, pedestrians.get(0).getFollowers().size());
assertEquals(2, newPedestrians.get(0).getFollowers().size());
}
@Test @Test
public void updateUseStaticTargetAsFallbackIfNoPedestrianIsFoundIfTargetIsDynamic() { public void updateUseStaticTargetAsFallbackIfNoPedestrianIsFoundIfTargetIsDynamic() {
int nextTarget = 3; int nextTarget = 3;
......
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