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 5e1aabf..0e681fc 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 @@ -18,6 +18,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { @Override protected ShortestPathSolution doRun() { + final ShortestPathData data = getInputData(); ShortestPathSolution solution = null; @@ -35,7 +36,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { // Init Dijkstra for (Node node : graph.getNodes()) { - labels.set(node.getId(), new Label(node)); + labels.add(new Label(node)); } Label s = labels.get(data.getOrigin().getId()); @@ -49,10 +50,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { Label x = s; int dest_id = data.getDestination().getId(); - while (!tas.isEmpty() || labels.get(dest_id).getNode().equals(x.getNode())) { + while (!tas.isEmpty() && !(labels.get(dest_id).getNode().equals(x.getNode()))) { x = tas.deleteMin(); x.mark(); - // A marked node is considered as reached notifyNodeReached(x.getNode()); @@ -61,7 +61,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { for (Arc successorArc : x.getNode().getSuccessors()) { Label successor = labels.get(successorArc.getDestination().getId()); - if (successor.isMarked()) { + if (!successor.isMarked()) { // This loop serves to get the lentgh of the arc as // we know its origin and destination for (Arc arc : x.getNode().getSuccessors()) {