From 79e82989f4070dd0361f06a6251101e79c771fb4 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sat, 23 May 2020 16:44:57 +0200 Subject: [PATCH] Improved max speed detection --- .../algorithm/shortestpath/AStarAlgorithm.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java index ab9078f..285da5e 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/AStarAlgorithm.java @@ -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;