dijkstra verifications OK

This commit is contained in:
Clement Lacau 2024-05-04 22:32:08 +02:00
parent df55fb1472
commit b45ff5d930

View file

@ -60,7 +60,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
x = tas.deleteMin();
x.mark();
notifyNodeMarked(x.getNode());
// System.out.println(x.getCost()); // Pour vérifier une croissance des noeuds marqués
// We create a list of node successors of x, instead of a list of Arcs.
float arc_cost = 0;
for (Arc successorArc : x.getNode().getSuccessors()) {
@ -96,47 +96,47 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
}
}
if (labels.get(data.getDestination().getId()).getParentNode() == null) {
solution = new ShortestPathSolution(data, Status.INFEASIBLE);
}
else {
// Create the path ...
ArrayList<Arc> arcs_path = new ArrayList<>();
// Create the path ...
ArrayList<Arc> arcs_path = new ArrayList<>();
// We will find the path using the parent nodes, from the destination to the
// origin
Label current_label = labels.get(data.getDestination().getId());
Label parent_label = current_label;
// We will find the path using the parent nodes, from the destination to the
// origin
Label current_label = labels.get(data.getDestination().getId());
Label parent_label = current_label;
while(current_label != null && current_label.getNode() != data.getOrigin())
{
// Find the label matching the parent node
parent_label = labels.get(current_label.getParentNode().getId());
while(current_label != null && current_label.getNode() != data.getOrigin())
{
// Find the label matching the parent node
parent_label = labels.get(current_label.getParentNode().getId());
// Knowing the parent node, get the arc between the parent and
// current node and add it to the path
if (parent_label != null) {
for (Arc arc : parent_label.getNode().getSuccessors()) {
if (arc.getDestination().getId() == current_label.getNode().getId() && data.isAllowed(arc)) {
arcs_path.add(arc);
break;
// Knowing the parent node, get the arc between the parent and
// current node and add it to the path
if (parent_label != null) {
for (Arc arc : parent_label.getNode().getSuccessors()) {
if (arc.getDestination().getId() == current_label.getNode().getId() && data.isAllowed(arc)) {
arcs_path.add(arc);
break;
}
}
}
current_label = parent_label;
}
current_label = parent_label;
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));
}
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));
/*System.out.println("watch here" + "\n");
for (Arc a : arcs_path){
System.out.println(a.getOrigin().getId() + " --- " + a.getDestination().getId() + "\n");
}*/
return solution;
return solution;
}
}