fix(dijkstra): path reconstruction not choosing optimal arc

This commit is contained in:
Paul Alnet 2024-05-20 23:55:01 +02:00
parent f4db47ee4e
commit fd69c3b30c

View file

@ -122,12 +122,17 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// Knowing the parent node, get the arc between the parent and
// current node and add it to the path
if (parent_label != null) {
double minCost = Double.MAX_VALUE;
Arc minCostArc = null;
for (Arc arc : parent_label.getNode().getSuccessors()) {
if (arc.getDestination().getId() == current_label.getNode().getId() && data.isAllowed(arc)) {
arcs_path.add(arc);
break;
if (arc.getDestination().getId() == current_label.getNode().getId()
&& data.isAllowed(arc)
&& data.getCost(arc) < minCost) {
minCost = data.getCost(arc);
minCostArc = arc;
}
}
arcs_path.add(minCostArc);
}
current_label = parent_label;
}