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 20ef467..155519f 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 @@ -30,13 +30,41 @@ public class Path { * @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. + * Need to be implemented. */ public static Path createFastestPathFromNodes(Graph graph, List nodes) throws IllegalArgumentException { - List arcs = new ArrayList(); - // TODO: - return new Path(graph, arcs); + List arcs = new ArrayList(); + if (nodes.size()==1){ + return new Path(graph, nodes.get(0)); + } + else { + for (int i = 0 ; i < nodes.size()-1; i++) { + double min = Double.POSITIVE_INFINITY; + boolean found = false; + + if (nodes.get(i).getSuccessors().size() >= 1) { + Arc min_arc = null; + for(Arc a : nodes.get(i).getSuccessors()) { + if( a.getDestination()==nodes.get(i+1) ) { + + if( a.getMinimumTravelTime() < min) { + min_arc = a ; // choose fastest route + min = a.getMinimumTravelTime() ; + } + found = true; + } + } + + if (!found) { + throw new IllegalArgumentException("two consecutive nodes in the list are not connected in the graph."); + } + arcs.add( min_arc ); + } + + } + return new Path(graph, arcs); + } } /**