condition d'arrêt Dijkstra
This commit is contained in:
parent
dab81d1bca
commit
10320f4a49
1 changed files with 9 additions and 5 deletions
|
@ -43,12 +43,15 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
Arc[] predecessorArcs = new Arc[nbNodes];
|
Arc[] predecessorArcs = new Arc[nbNodes];
|
||||||
|
|
||||||
Label current, next;
|
Label current, next;
|
||||||
|
|
||||||
|
|
||||||
// While the heap has elements
|
// While the heap has elements and the destination has not been reached and marked
|
||||||
while (!labelsHeap.isEmpty()) {
|
while (!labelsHeap.isEmpty()
|
||||||
|
&& (labelsList[data.getDestination().getId()] == null || !labelsList[data.getDestination().getId()].isMarked() )) {
|
||||||
|
|
||||||
// Remove the min
|
// Remove the min
|
||||||
current = labelsHeap.findMin();
|
current = labelsHeap.findMin();
|
||||||
|
//System.out.println("cout :"+current.getCost());
|
||||||
try {
|
try {
|
||||||
labelsHeap.remove(current);
|
labelsHeap.remove(current);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -63,6 +66,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//System.out.println("origine : "+arc.getOrigin().getId()+" destination : "+ arc.getDestination().getId());
|
||||||
next = labelsList[arc.getDestination().getId()];
|
next = labelsList[arc.getDestination().getId()];
|
||||||
|
|
||||||
//If the destination of an arc does not exist or is not marked
|
//If the destination of an arc does not exist or is not marked
|
||||||
|
@ -76,18 +80,18 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
labelsList[arc.getDestination().getId()] = next;
|
labelsList[arc.getDestination().getId()] = next;
|
||||||
labelsHeap.insert(next);
|
labelsHeap.insert(next);
|
||||||
notifyNodeReached(arc.getDestination());
|
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
if (next.getCost() > current.getCost() + data.getCost(arc)) {
|
if (next.getCost() > current.getCost() + data.getCost(arc)) {
|
||||||
next.setCost(current.getCost() + data.getCost(arc));
|
next.setCost(current.getCost() + data.getCost(arc));
|
||||||
next.setFather(arc);
|
next.setFather(arc);
|
||||||
notifyNodeReached(arc.getDestination());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
notifyNodeReached(arc.getDestination());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//System.out.println("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue