fix(dijkstra): path reconstruction not choosing optimal arc
This commit is contained in:
parent
f4db47ee4e
commit
fd69c3b30c
1 changed files with 8 additions and 3 deletions
|
@ -122,12 +122,17 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
// Knowing the parent node, get the arc between the parent and
|
// Knowing the parent node, get the arc between the parent and
|
||||||
// current node and add it to the path
|
// current node and add it to the path
|
||||||
if (parent_label != null) {
|
if (parent_label != null) {
|
||||||
|
double minCost = Double.MAX_VALUE;
|
||||||
|
Arc minCostArc = null;
|
||||||
for (Arc arc : parent_label.getNode().getSuccessors()) {
|
for (Arc arc : parent_label.getNode().getSuccessors()) {
|
||||||
if (arc.getDestination().getId() == current_label.getNode().getId() && data.isAllowed(arc)) {
|
if (arc.getDestination().getId() == current_label.getNode().getId()
|
||||||
arcs_path.add(arc);
|
&& data.isAllowed(arc)
|
||||||
break;
|
&& data.getCost(arc) < minCost) {
|
||||||
|
minCost = data.getCost(arc);
|
||||||
|
minCostArc = arc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
arcs_path.add(minCostArc);
|
||||||
}
|
}
|
||||||
current_label = parent_label;
|
current_label = parent_label;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue