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 bacb8e3..bdf40e0 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 @@ -1,5 +1,16 @@ package org.insa.graphs.algorithm.shortestpath; +import java.util.ArrayList; +import java.util.Collections; + +import org.insa.graphs.algorithm.AbstractInputData.Mode; +import org.insa.graphs.algorithm.AbstractSolution.Status; +import org.insa.graphs.algorithm.utils.BinaryHeap; +import org.insa.graphs.model.Arc; +import org.insa.graphs.model.Label; +import org.insa.graphs.model.Node; +import org.insa.graphs.model.Path; + public class DijkstraAlgorithm extends ShortestPathAlgorithm { public DijkstraAlgorithm(ShortestPathData data) { @@ -9,9 +20,124 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { @Override protected ShortestPathSolution doRun() { final ShortestPathData data = getInputData(); - ShortestPathSolution solution = null; - // TODO: - return solution; + + int numberOfNodes = data.getGraph().size(); + + double shortestCostToDestination = Double.POSITIVE_INFINITY; + + // it's the cost of the last marked node. In order to stop algorithm when it's not + // useful + double lastMarkedNodeCost = 0; + + // Dijkstra Init + Label[] labels = new Label[numberOfNodes]; + + + for(Node node : data.getGraph().getNodes()) { + labels[node.getId()] = new Label(node); + } + + // Let's set the origin cost at 0 + labels[data.getOrigin().getId()].setNewCost(null, 0d); + + // We need to add a binaryMinHeap to get min at each iteration + BinaryHeap