Ajout observers
This commit is contained in:
parent
8199e93748
commit
5cb458cc25
1 changed files with 14 additions and 0 deletions
|
@ -46,6 +46,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
// We add into our binaryMinHeap the origin
|
// We add into our binaryMinHeap the origin
|
||||||
minHeap.insert(labels[data.getOrigin().getId()]);
|
minHeap.insert(labels[data.getOrigin().getId()]);
|
||||||
|
|
||||||
|
//We notify observers that we initialized the origin
|
||||||
|
notifyOriginProcessed(data.getOrigin());
|
||||||
|
|
||||||
// We can start searching for the shortestPath
|
// We can start searching for the shortestPath
|
||||||
|
|
||||||
// We stop the algorithm when the cost of last marked point is equal to the shortest found path
|
// We stop the algorithm when the cost of last marked point is equal to the shortest found path
|
||||||
|
@ -57,6 +60,11 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
//We mark it
|
//We mark it
|
||||||
minLabel.setMarked();
|
minLabel.setMarked();
|
||||||
|
|
||||||
|
//We notify we marked it
|
||||||
|
notifyNodeMarked(minLabel.getCurrent());
|
||||||
|
|
||||||
|
|
||||||
lastMarkedNodeCost = minLabel.getCost();
|
lastMarkedNodeCost = minLabel.getCost();
|
||||||
|
|
||||||
//We look at their successors
|
//We look at their successors
|
||||||
|
@ -91,6 +99,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
if(Double.isFinite(label.getCost())) {
|
if(Double.isFinite(label.getCost())) {
|
||||||
minHeap.remove(label);
|
minHeap.remove(label);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
notifyNodeReached(label.getCurrent());
|
||||||
|
}
|
||||||
label.setNewCost(successor, newCost);
|
label.setNewCost(successor, newCost);
|
||||||
minHeap.insert(label);
|
minHeap.insert(label);
|
||||||
|
|
||||||
|
@ -119,7 +130,10 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
return new ShortestPathSolution(data, Status.INFEASIBLE);
|
return new ShortestPathSolution(data, Status.INFEASIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//There is a path, let's find it
|
//There is a path, let's find it
|
||||||
|
notifyDestinationReached(data.getDestination());
|
||||||
|
|
||||||
ArrayList<Arc> path = new ArrayList<Arc>();
|
ArrayList<Arc> path = new ArrayList<Arc>();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue