From 40d68f76ad94cb9864e961ee1a1dc278750bf927 Mon Sep 17 00:00:00 2001 From: Gasson-Betuing Danyl Date: Fri, 9 May 2025 12:19:51 +0200 Subject: [PATCH] DebutImplementDijktra --- .../shortestpath/DijkstraAlgorithm.java | 33 ++++++++++++++----- .../graphs/algorithm/shortestpath/Label.java | 18 ++++++---- 2 files changed, 36 insertions(+), 15 deletions(-) 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 aa75234..9124a12 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 @@ -6,6 +6,8 @@ import org.insa.graphs.model.Arc; import org.insa.graphs.model.Graph; import org.insa.graphs.model.Node; import org.insa.graphs.model.Path; +import org.insa.graphs.algorithm.shortestpath.Label; +import org.insa.graphs.algorithm.utils.BinaryHeap; public class DijkstraAlgorithm extends ShortestPathAlgorithm { @@ -21,25 +23,40 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { // retrieve data from the input problem (getInputData() is inherited from the // parent class ShortestPathAlgorithm) final ShortestPathData data = getInputData(); - // the graph Graph graph = data.getGraph(); // node number final int nbNodes = graph.size(); - // Initialize array of distances. - double[] distances = new double[nbNodes]; - Arrays.fill(distances, Double.POSITIVE_INFINITY); - distances[data.getOrigin().getId()] = 0; + int nodeId = 0; + // initialize the label list + Label[] labels = new Label[nbNodes]; + for(Node node : graph.getNodes()){ + nodeId = node.getId(); + labels[nodeId] = new Label(node, false, Double.POSITIVE_INFINITY); + } + + labels[data.getOrigin().getId()].computedCost = 0; // variable that will contain the solution of the shortest path problem ShortestPathSolution solution = null; + //binary heap for selected lowest cost + BinaryHeap