From 40ac23a8c132671e99e50bdaf2e67c30ffe0e946 Mon Sep 17 00:00:00 2001 From: Gasson-Betuing Danyl Date: Fri, 9 May 2025 10:37:38 +0200 Subject: [PATCH] Pour resynchroniser le projet --- .../shortestpath/DijkstraAlgorithm.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 198cd5d..aa75234 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,12 @@ package org.insa.graphs.algorithm.shortestpath; +import java.util.Arrays; + +import org.insa.graphs.model.Arc; +import org.insa.graphs.model.Graph; +import org.insa.graphs.model.Node; +import org.insa.graphs.model.Path; + public class DijkstraAlgorithm extends ShortestPathAlgorithm { public DijkstraAlgorithm(ShortestPathData data) { @@ -9,16 +16,37 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm { @Override protected ShortestPathSolution doRun() { + + // 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; // variable that will contain the solution of the shortest path problem ShortestPathSolution solution = null; // TODO: implement the Dijkstra algorithm - + boolean found = false; + for (int i = 0; !found && i < nbNodes; ++i) { + found = true; + for (Node node : graph.getNodes()) { + for (Arc arc : node.getSuccessors()) { + + + } + } + } + + // when the algorithm terminates, return the solution that has been found return solution;