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 b48792a..ad96e81 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,11 +30,79 @@ public class Path { */ public static Path createFastestPathFromNodes(Graph graph, List nodes) throws IllegalArgumentException { - List arcs = new ArrayList(); - // TODO: + if (nodes.size() == 1) { + Node node = nodes.get(0); + return new Path(graph, node); + + } + + if (nodes.size() == 0) { + Node node = null; + return new Path(graph, node); + } + + else { - return new Path(graph, arcs); + List arcs = new ArrayList(); + + // Node leorigin = nodes.get(0); + Node ledest = nodes.get(nodes.size() - 1); + boolean hsein = true; + int i = 0; + + while (hsein && i < nodes.size()) { + double vitessemin = Float.MAX_VALUE; + if (!(nodes.get(i).hasSuccessors()) && nodes.get(i) != ledest) { + hsein = false; + throw new IllegalArgumentException(); + + } + boolean bonsuccesseur = false; + // parcours de la liste des successeurs verification destinataire + if (nodes.get(i) != ledest) { + for (int k = 0; k < nodes.get(i).getSuccessors().size(); k++) { + if (i < nodes.size()) { + if (nodes.get(i).getSuccessors().get(k) + .getDestination() == nodes.get(i + 1)) { + bonsuccesseur = true; + } + } + + } + if (!bonsuccesseur) { + throw new IllegalArgumentException(); + } + + } + // si on n'a pas le bonsuccesseur on doit throw un + // IllegalArgumentException + + // on continue si on a le bonsuccesseur sinon on a une exception + if (bonsuccesseur) { + Arc arcajouter = null; + for (int j = 0; j < nodes.get(i).getSuccessors().size(); j++) { + if (nodes.get(i).getSuccessors().get(j) + .getDestination() == nodes.get(i + 1)) { + if (nodes.get(i).getSuccessors().get(j) + .getMinimumTravelTime() < vitessemin) { + vitessemin = nodes.get(i).getSuccessors().get(j) + .getMinimumTravelTime(); + arcajouter = nodes.get(i).getSuccessors().get(j); + // arcs.add(arcajouter); + // System.out.println(arcs); + } + } + + } + arcs.add(arcajouter); + } + + i++; + + } + return new Path(graph, arcs); + } } /** @@ -56,6 +124,12 @@ public class Path { } + + if (nodes.size() == 0) { + Node node = null; + return new Path(graph, node); + } + else { @@ -70,9 +144,7 @@ public class Path { float longueurmin = Float.MAX_VALUE; if (!(nodes.get(i).hasSuccessors()) && nodes.get(i) != ledest) { hsein = false; - throw new IllegalArgumentException( - "The path is invalid: node " + nodes.get(i) - + " has no successors but is not the destination."); + throw new IllegalArgumentException(); } boolean bonsuccesseur = false; @@ -87,8 +159,13 @@ public class Path { } } + if (!bonsuccesseur) { + throw new IllegalArgumentException(); + } } + // si on n'a pas le bonsuccesseur on doit throw un + // IllegalArgumentException // on continue si on a le bonsuccesseur sinon on a une exception if (bonsuccesseur) { @@ -175,7 +252,7 @@ public class Path { * Create a new path containing a single node. * * @param graph Graph containing the path. - * @param node Single node of the path. + * @param node Single node of the path. return new Path(graph, arcs); } */ public Path(Graph graph, Node node) { this.graph = graph;