dijkstra
This commit is contained in:
parent
9e994c2104
commit
73a1e4a058
1 changed files with 4 additions and 4 deletions
|
@ -18,6 +18,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
|
||||
@Override
|
||||
protected ShortestPathSolution doRun() {
|
||||
|
||||
final ShortestPathData data = getInputData();
|
||||
ShortestPathSolution solution = null;
|
||||
|
||||
|
@ -35,7 +36,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
|
||||
// Init Dijkstra
|
||||
for (Node node : graph.getNodes()) {
|
||||
labels.set(node.getId(), new Label(node));
|
||||
labels.add(new Label(node));
|
||||
}
|
||||
|
||||
Label s = labels.get(data.getOrigin().getId());
|
||||
|
@ -49,10 +50,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
Label x = s;
|
||||
|
||||
int dest_id = data.getDestination().getId();
|
||||
while (!tas.isEmpty() || labels.get(dest_id).getNode().equals(x.getNode())) {
|
||||
while (!tas.isEmpty() && !(labels.get(dest_id).getNode().equals(x.getNode()))) {
|
||||
x = tas.deleteMin();
|
||||
x.mark();
|
||||
|
||||
// A marked node is considered as reached
|
||||
notifyNodeReached(x.getNode());
|
||||
|
||||
|
@ -61,7 +61,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
for (Arc successorArc : x.getNode().getSuccessors()) {
|
||||
Label successor = labels.get(successorArc.getDestination().getId());
|
||||
|
||||
if (successor.isMarked()) {
|
||||
if (!successor.isMarked()) {
|
||||
// This loop serves to get the lentgh of the arc as
|
||||
// we know its origin and destination
|
||||
for (Arc arc : x.getNode().getSuccessors()) {
|
||||
|
|
Loading…
Reference in a new issue