Improved max speed detection

This commit is contained in:
Arnaud Vergnet 2020-05-23 16:44:57 +02:00
parent ac18c2d522
commit 79e82989f4

View file

@ -8,6 +8,16 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
super(data);
}
private double getMaxSpeed(Graph graph, ShortestPathData inputData) {
final double graphMaxSpeed = graph.getGraphInformation().getMaximumSpeed();
final double inputMaxSpeed = inputData.getMaximumSpeed();
double maxSpeed = Double.min(graphMaxSpeed, inputMaxSpeed);
if (inputMaxSpeed < 0)
maxSpeed = graphMaxSpeed;
return maxSpeed;
}
@Override
protected ShortestPathSolution doRun() {
final ShortestPathData data = getInputData();
@ -19,7 +29,7 @@ public class AStarAlgorithm extends DijkstraAlgorithm {
final double distance = graph.getNodes().get(i).getPoint().distanceTo(
data.getDestination().getPoint()
);
final double maxSpeed = graph.getGraphInformation().getMaximumSpeed();
final double maxSpeed = getMaxSpeed(graph, data);
double estimatedCost = distance;
if (data.getMode() == ShortestPathData.Mode.TIME)
estimatedCost /= maxSpeed;