diff --git a/Synthese_LACAU_ALNET.docx b/Synthese_LACAU_ALNET.docx new file mode 100644 index 0000000..cf5339e Binary files /dev/null and b/Synthese_LACAU_ALNET.docx differ 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 0cc39a7..88d1dfa 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 @@ -1,13 +1,21 @@ package org.insa.graphs.algorithm.shortestpath; +import org.insa.graphs.algorithm.AbstractInputData.Mode; import org.insa.graphs.model.Node; public class AStarAlgorithm extends DijkstraAlgorithm { private Node destination; - + @Override protected Label createLabel(Node node) { - return new LabelStar(node, destination); + LabelStar retour; + if (data.getMode() == Mode.LENGTH) { + retour = new LabelStar(node, -1, destination); + } + else { + retour = new LabelStar(node, data.getGraph().getGraphInformation().getMaximumSpeed(), destination); + } + return retour; } public AStarAlgorithm(ShortestPathData data) { diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java index 36cc09b..47c7b0f 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/DijkstraAlgorithm.java @@ -74,15 +74,19 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { // we know its origin and destination for (Arc arc : x.getNode().getSuccessors()) { if (successor.getNode().equals(arc.getDestination())) { + // data.getcost(arc) returns a cost considering the mode chosen: + // TIME or LENGTH + // Similar to using getLength / getMinimumTravelTime arc_cost = (float) data.getCost(arc); } } + final float possible_path_cost = x.getCost() + arc_cost; - if (successor.getCost() > possible_path_cost) { + if (successor.getCost() >= possible_path_cost) { // Mise à jour du label successor.setPathCost(possible_path_cost); successor.setParentNode(x.getNode()); - // Si le noeud n'a pas déjà était rajouté au tas, on le rajoute + // Si le noeud n'a pas déjà été rajouté au tas, on le rajoute // isReached permet de vérifier en complexité O(1) // C'est un léger coût en mémoire pour un gain en vitesse if (successor.isReached()) { @@ -92,7 +96,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { successor.markReached(); notifyNodeReached(successor.getNode()); } - tas.insert(successor); } } @@ -112,7 +115,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { Label current_label = labels.get(data.getDestination().getId()); Label parent_label = current_label; - while(current_label != null && current_label.getNode() != data.getOrigin()) + while(current_label != null && current_label.getNode().getId() != data.getOrigin().getId()) { // Find the label matching the parent node parent_label = labels.get(current_label.getParentNode().getId()); diff --git a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/Label.java b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/Label.java index ffdf560..bdc3da7 100644 --- a/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/Label.java +++ b/be-graphes-algos/src/main/java/org/insa/graphs/algorithm/shortestpath/Label.java @@ -1,6 +1,7 @@ package org.insa.graphs.algorithm.shortestpath; import org.insa.graphs.model.Node; +import org.insa.graphs.algorithm.AbstractInputData.Mode; public class Label implements Comparable