dijkstra functional
This commit is contained in:
parent
73a1e4a058
commit
e5be8087f9
1 changed files with 16 additions and 20 deletions
|
@ -95,29 +95,25 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
|
||||
// We will find the path using the parent nodes, from the destination to the
|
||||
// origin
|
||||
Node current_node = data.getDestination();
|
||||
Label current_label = new Label(current_node);
|
||||
// System.out.println(current_node.getId());
|
||||
Label current_label = labels.get(data.getDestination().getId());
|
||||
Label parent_label = current_label;
|
||||
|
||||
while(current_node!=null&¤t_node!=data.getOrigin())
|
||||
while(current_label != null && current_label.getNode() != data.getOrigin())
|
||||
{
|
||||
// Find the label matching the parent node
|
||||
for (Label label : labels) {
|
||||
if (label.getNode() == current_node) {
|
||||
current_label = label;
|
||||
current_node = current_label.getParentNode();
|
||||
}
|
||||
}
|
||||
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 (current_node != null) {
|
||||
for (Arc arc : current_node.getSuccessors()) {
|
||||
if (parent_label != null) {
|
||||
for (Arc arc : parent_label.getNode().getSuccessors()) {
|
||||
if (arc.getDestination().getId() == current_label.getNode().getId()) {
|
||||
arcs_path.add(arc);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
current_label = parent_label;
|
||||
}
|
||||
|
||||
notifyDestinationReached(data.getDestination());
|
||||
|
|
Loading…
Reference in a new issue