forked from lebotlan/BE-Graphes
NOT FINISHED : Dijkstra
This commit is contained in:
parent
f42e7edf5f
commit
fa87e8d63b
2 changed files with 27 additions and 21 deletions
|
|
@ -41,28 +41,34 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
concurentNodeLabel.setCoutRealise(0);
|
||||
concurentNodeLabel.setMarque();
|
||||
|
||||
notifyOriginProcessed(data.getOrigin());
|
||||
|
||||
BinaryHeap<Label> labelsHeap = new BinaryHeap<Label>();
|
||||
labelsHeap.insert(concurentNodeLabel);
|
||||
|
||||
boolean found = false;
|
||||
for (int i = 0; !found && i < nbNodes; ++i) {
|
||||
for (Arc arc : concurentNodeLabel.getSommetCourant().getSuccessors()) {
|
||||
Label successorLabel = labelsList.get(arc.getDestination().getId());
|
||||
successorLabel.setCoutRealise(arc.getLength());
|
||||
// GERER LA SOMME DES COUTS POUR LE NOUVEAU ALBEL
|
||||
if (arc.getLength() < successorLabel.getCost()) {
|
||||
labelsHeap.remove(successorLabel);
|
||||
}
|
||||
successorLabel.setPere(arc);
|
||||
labelsHeap.insert(successorLabel);
|
||||
}
|
||||
concurentNodeLabel = labelsHeap.deleteMin();
|
||||
concurentNodeLabel.setMarque();
|
||||
if (destinationNodeLabel.getMarque()) {
|
||||
found = true;
|
||||
}
|
||||
while (!found && !labelsHeap.isEmpty()) {
|
||||
concurentNodeLabel = labelsHeap.deleteMin();
|
||||
if (!concurentNodeLabel.getMarque()) {
|
||||
notifyNodeReached(concurentNodeLabel.getSommetCourant());
|
||||
concurentNodeLabel.setMarque();
|
||||
for (Arc arc : concurentNodeLabel.getSommetCourant().getSuccessors()) {
|
||||
Label successorLabel = labelsList.get(arc.getDestination().getId());
|
||||
Float newCost = arc.getLength() + concurentNodeLabel.getCost();
|
||||
if (newCost < successorLabel.getCost()) {
|
||||
successorLabel.setPere(arc);
|
||||
successorLabel.setCoutRealise(newCost);
|
||||
labelsHeap.insert(successorLabel);
|
||||
}
|
||||
}
|
||||
if (destinationNodeLabel.getMarque()) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notifyDestinationReached(data.getDestination());
|
||||
|
||||
ArrayList<Arc> pathArcs = new ArrayList<Arc>();
|
||||
concurentNodeLabel = destinationNodeLabel;
|
||||
while(concurentNodeLabel.getPere() != null) {
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ public class Label implements Comparable<Label> {
|
|||
this.pere = pere;
|
||||
}
|
||||
|
||||
public double getCoutRealise() {
|
||||
return coutRealise;
|
||||
}
|
||||
// public double getCoutRealise() {
|
||||
// return coutRealise;
|
||||
// }
|
||||
|
||||
public void setCoutRealise(float nouveauCout) {
|
||||
this.coutRealise = nouveauCout;
|
||||
|
|
@ -53,7 +53,7 @@ public class Label implements Comparable<Label> {
|
|||
|
||||
@Override
|
||||
public int compareTo(Label o) {
|
||||
return Double.compare(this.coutRealise, o.getCoutRealise()) ;
|
||||
return Double.compare(this.coutRealise, o.getCost()) ;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue