From 684c8ea6ac4307931711b75ffe3da0f1b737ca48 Mon Sep 17 00:00:00 2001 From: moll Date: Wed, 15 Apr 2026 17:38:08 +0200 Subject: [PATCH] made createFastestPathFromNodes() --- .../main/java/org/insa/graphs/model/Path.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java b/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java index dca057c..152f28d 100644 --- a/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java +++ b/be-graphes-model/src/main/java/org/insa/graphs/model/Path.java @@ -25,12 +25,33 @@ public class Path { * @return A path that goes through the given list of nodes. * @throws IllegalArgumentException If the list of nodes is not valid, i.e. two * consecutive nodes in the list are not connected in the graph. - * @deprecated Need to be implemented. */ public static Path createFastestPathFromNodes(Graph graph, List nodes) throws IllegalArgumentException { List arcs = new ArrayList(); - // TODO: + + if (nodes.size() == 1) { return new Path(graph, nodes.get(0)); } + + for (int i = 0; i < nodes.size() - 1; i++) { + Arc bestArc = null; + double bestSpeed = Double.MAX_VALUE; + for (Arc arcsucc : nodes.get(i).getSuccessors()) { + if (arcsucc.getDestination().equals(nodes.get(i+1))) { + int succspeed = arcsucc.getRoadInformation().getMaximumSpeed(); + if (arcsucc.getTravelTime(succspeed) < bestSpeed) { + bestArc = arcsucc; + bestSpeed = arcsucc.getTravelTime(succspeed); + } + } + + } + if (bestArc == null) { + throw new IllegalArgumentException(); + } else { + arcs.add(bestArc); + } + } + return new Path(graph, arcs); }