dijkstra : compiling version but not functional

This commit is contained in:
Clement Lacau 2024-04-18 01:16:09 +02:00
parent f51d3a26b5
commit 6e4c4de7dd

View file

@ -2,11 +2,14 @@ package org.insa.graphs.algorithm.shortestpath;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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.Graph;
import org.insa.graphs.model.Node;
import org.insa.graphs.model.Path;
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
@ -81,7 +84,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// Create the path ...
ArrayList<Arc> arcs_path = new ArrayList<>();
Label dest;
Label dest = labels.findMin();
for (Label label : labels.array) {
if (label.getNode() == data.getDestination()){
dest = label;
@ -90,10 +93,24 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
Node current = dest.getParentNode();
while (current != null) {
current
for (Arc arc : current.getSuccessors()) {
if (arc.getDestination() == dest.getNode()) {
arcs_path.add(arc);
}
arc = predecessorArcs[arc.getOrigin().getId()];
}
for (Label label : labels.array) {
if (label.getNode() == current){
dest = label;
current = label.getParentNode();
}
}
}
// Reverse the path...
Collections.reverse(arcs_path);
// Create the final solution.
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(graph, arcs_path));
return solution;
}