Added getPathCost method and pathCost attribute

This commit is contained in:
Clement Lacau 2024-05-18 16:08:28 +02:00
parent 86b860f9a3
commit de65f817b1

View file

@ -12,6 +12,8 @@ import org.insa.graphs.model.Path;
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
private float pathCost;
public DijkstraAlgorithm(ShortestPathData data) {
super(data);
}
@ -32,6 +34,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// List of sommets, but with type Label
ArrayList<Label> labels = new ArrayList<Label>(nbNodes);
// Heap of sommets
BinaryHeap<Label> tas = new BinaryHeap<Label>();
@ -97,6 +100,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
if (labels.get(data.getDestination().getId()).getParentNode() == null) {
this.pathCost = 0;
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
}
else {
@ -128,15 +132,18 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
notifyDestinationReached(data.getDestination());
// Reverse the path...
Collections.reverse(arcs_path);
// Create the final solution.
solution = new ShortestPathSolution(data, Status.OPTIMAL, new Path(graph, arcs_path));
this.pathCost = labels.get(data.getDestination().getId()).getTotalCost();
}
return solution;
}
public float getCostPath() {
return this.pathCost;
}
}