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

In "OSMBehaviorController", fixed severe bug in method "findSwapCandidate()"...

In "OSMBehaviorController", fixed severe bug in method "findSwapCandidate()" and added TODO comment to write unit tests
parent b9ab52b6
Pipeline #173463 passed with stages
in 126 minutes and 34 seconds
...@@ -58,13 +58,13 @@ public class OSMBehaviorController { ...@@ -58,13 +58,13 @@ public class OSMBehaviorController {
VPoint currentPosition = pedestrian.getPosition(); VPoint currentPosition = pedestrian.getPosition();
VPoint nextPosition = pedestrian.getNextPosition(); VPoint nextPosition = pedestrian.getNextPosition();
// start time // start time
double stepStartTime = pedestrian.getTimeOfNextStep(); double stepStartTime = pedestrian.getTimeOfNextStep();
// end time // end time
double stepEndTime = pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep(); double stepEndTime = pedestrian.getTimeOfNextStep() + pedestrian.getDurationNextStep();
assert stepEndTime >= stepStartTime && stepEndTime >= 0.0 && stepStartTime >= 0.0 : stepEndTime + "<" + stepStartTime; assert stepEndTime >= stepStartTime && stepEndTime >= 0.0 && stepStartTime >= 0.0 : stepEndTime + "<" + stepStartTime;
if (nextPosition.equals(currentPosition)) { if (nextPosition.equals(currentPosition)) {
pedestrian.setTimeCredit(0); pedestrian.setTimeCredit(0);
...@@ -134,36 +134,40 @@ public class OSMBehaviorController { ...@@ -134,36 +134,40 @@ public class OSMBehaviorController {
} }
} }
// TODO: Write unit tests for the critical methods below!
@Nullable @Nullable
public PedestrianOSM findSwapCandidate(PedestrianOSM pedestrian, Topography topography) { public PedestrianOSM findSwapCandidate(PedestrianOSM pedestrian, Topography topography) {
// Agents with no targets don't want to swap places.
if (pedestrian.hasNextTarget() == false) {
return null;
}
List<Pedestrian> closestPedestrians = getClosestPedestriansWhichAreCloserToTarget(pedestrian, topography);
if (closestPedestrians.size() > 0) {
for (Pedestrian closestPedestrian : closestPedestrians) {
if (closestPedestrian.hasNextTarget()) {
boolean closestPedIsCooperative = closestPedestrian.getSelfCategory() == SelfCategory.COOPERATIVE;
boolean targetOrientationDiffers = false;
// TODO: Make both options configurable in JSON file.
// double angleInRadian = calculateAngleBetweenTargets(pedestrian, closestPedestrian, topography);
double angleInRadian = calculateAngleBetweenTargetGradients(pedestrian, (PedestrianOSM)closestPedestrian);
if (angleInRadian == -1 || Math.toDegrees(angleInRadian) > pedestrian.getAttributes().getTargetOrientationAngleThreshold()) {
targetOrientationDiffers = true;
}
List<Pedestrian> closestPedestrians = getClosestPedestriansWhichAreCloserToTarget(pedestrian, topography); if (closestPedIsCooperative && targetOrientationDiffers) {
return (PedestrianOSM)closestPedestrian;
if (closestPedestrians.size() > 0) { }
for (Pedestrian closestPedestrian : closestPedestrians) { } else {
if(pedestrian.hasNextTarget()) { return (PedestrianOSM)closestPedestrian;
boolean closestPedIsCooperative = closestPedestrian.getSelfCategory() == SelfCategory.COOPERATIVE; }
boolean targetOrientationDiffers = false; }
}
// TODO: Use "pedestrian.getTargetGradient()" instead of "calculateAngleBetweenTargets()".
double angleInRadian = calculateAngleBetweenTargets(pedestrian, closestPedestrian, topography); return null;
if (angleInRadian == -1 || Math.toDegrees(angleInRadian) > pedestrian.getAttributes().getTargetOrientationAngleThreshold()) {
targetOrientationDiffers = true;
}
if (closestPedIsCooperative && targetOrientationDiffers) {
return (PedestrianOSM)closestPedestrian;
}
} else {
if(!closestPedestrian.hasNextTarget()) {
return (PedestrianOSM)closestPedestrian;
}
}
}
}
return null;
} }
@NotNull @NotNull
...@@ -278,23 +282,23 @@ public class OSMBehaviorController { ...@@ -278,23 +282,23 @@ public class OSMBehaviorController {
pedestrian2.setNextPosition(oldPosition); pedestrian2.setNextPosition(oldPosition);
// Synchronize movement of both pedestrians // Synchronize movement of both pedestrians
double startTimeStep = pedestrian1.getTimeOfNextStep(); double startTimeStep = pedestrian1.getTimeOfNextStep();
double durationStep = Math.max(pedestrian1.getDurationNextStep(), pedestrian2.getDurationNextStep()); double durationStep = Math.max(pedestrian1.getDurationNextStep(), pedestrian2.getDurationNextStep());
double endTimeStep = startTimeStep + durationStep; double endTimeStep = startTimeStep + durationStep;
// We interrupt the current footstep of pedestrian 2 to sync it with // We interrupt the current footstep of pedestrian 2 to sync it with
// pedestrian 1. It is only required for the sequential update scheme // pedestrian 1. It is only required for the sequential update scheme
// since pedestrian 2 might have done some steps in this time step and // since pedestrian 2 might have done some steps in this time step and
// is ahead (with respect to the time) of pedestrian 1. // is ahead (with respect to the time) of pedestrian 1.
// We remove those steps which is not a good solution! // We remove those steps which is not a good solution!
if(!pedestrian2.getTrajectory().isEmpty()) { if(!pedestrian2.getTrajectory().isEmpty()) {
pedestrian2.getTrajectory().adjustEndTime(startTimeStep); pedestrian2.getTrajectory().adjustEndTime(startTimeStep);
} }
pedestrian1.setTimeOfNextStep(startTimeStep); pedestrian1.setTimeOfNextStep(startTimeStep);
pedestrian2.setTimeOfNextStep(startTimeStep); pedestrian2.setTimeOfNextStep(startTimeStep);
makeStep(pedestrian1, topography, durationStep); makeStep(pedestrian1, topography, durationStep);
makeStep(pedestrian2, topography, durationStep); makeStep(pedestrian2, topography, durationStep);
// TODO The experiment showed that speed decreased (to half of free-flow velocity). // TODO The experiment showed that speed decreased (to half of free-flow velocity).
...@@ -302,7 +306,7 @@ public class OSMBehaviorController { ...@@ -302,7 +306,7 @@ public class OSMBehaviorController {
pedestrian1.setTimeOfNextStep(endTimeStep); pedestrian1.setTimeOfNextStep(endTimeStep);
pedestrian2.setTimeOfNextStep(endTimeStep); pedestrian2.setTimeOfNextStep(endTimeStep);
pedestrian1.setTimeCredit(pedestrian1.getTimeCredit() - durationStep); pedestrian1.setTimeCredit(pedestrian1.getTimeCredit() - durationStep);
pedestrian2.setTimeCredit(pedestrian1.getTimeCredit()); pedestrian2.setTimeCredit(pedestrian1.getTimeCredit());
} }
} }
...@@ -46,7 +46,7 @@ public class PotentialFieldTargetGrid extends PotentialFieldTarget implements IP ...@@ -46,7 +46,7 @@ public class PotentialFieldTargetGrid extends PotentialFieldTarget implements IP
public Vector2D getTargetPotentialGradient(VPoint pos, Agent ped) { public Vector2D getTargetPotentialGradient(VPoint pos, Agent ped) {
double[] gradient = { 0.0, 0.0 }; double[] gradient = { 0.0, 0.0 };
if (ped.getNextTargetId() > -1) { if (ped.hasNextTarget()) {
InterpolationUtil.getGradientMollified(getCellGrids().get(ped.getNextTargetId()), new double[]{pos.getX(), pos.getY()}, gradient, 0.1); InterpolationUtil.getGradientMollified(getCellGrids().get(ped.getNextTargetId()), new double[]{pos.getX(), pos.getY()}, gradient, 0.1);
} }
......
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