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.setCoutRealise(0);
|
||||||
concurentNodeLabel.setMarque();
|
concurentNodeLabel.setMarque();
|
||||||
|
|
||||||
|
notifyOriginProcessed(data.getOrigin());
|
||||||
|
|
||||||
BinaryHeap<Label> labelsHeap = new BinaryHeap<Label>();
|
BinaryHeap<Label> labelsHeap = new BinaryHeap<Label>();
|
||||||
|
labelsHeap.insert(concurentNodeLabel);
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (int i = 0; !found && i < nbNodes; ++i) {
|
while (!found && !labelsHeap.isEmpty()) {
|
||||||
for (Arc arc : concurentNodeLabel.getSommetCourant().getSuccessors()) {
|
concurentNodeLabel = labelsHeap.deleteMin();
|
||||||
Label successorLabel = labelsList.get(arc.getDestination().getId());
|
if (!concurentNodeLabel.getMarque()) {
|
||||||
successorLabel.setCoutRealise(arc.getLength());
|
notifyNodeReached(concurentNodeLabel.getSommetCourant());
|
||||||
// GERER LA SOMME DES COUTS POUR LE NOUVEAU ALBEL
|
concurentNodeLabel.setMarque();
|
||||||
if (arc.getLength() < successorLabel.getCost()) {
|
for (Arc arc : concurentNodeLabel.getSommetCourant().getSuccessors()) {
|
||||||
labelsHeap.remove(successorLabel);
|
Label successorLabel = labelsList.get(arc.getDestination().getId());
|
||||||
}
|
Float newCost = arc.getLength() + concurentNodeLabel.getCost();
|
||||||
successorLabel.setPere(arc);
|
if (newCost < successorLabel.getCost()) {
|
||||||
labelsHeap.insert(successorLabel);
|
successorLabel.setPere(arc);
|
||||||
}
|
successorLabel.setCoutRealise(newCost);
|
||||||
concurentNodeLabel = labelsHeap.deleteMin();
|
labelsHeap.insert(successorLabel);
|
||||||
concurentNodeLabel.setMarque();
|
}
|
||||||
if (destinationNodeLabel.getMarque()) {
|
}
|
||||||
found = true;
|
if (destinationNodeLabel.getMarque()) {
|
||||||
}
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyDestinationReached(data.getDestination());
|
notifyDestinationReached(data.getDestination());
|
||||||
|
|
||||||
ArrayList<Arc> pathArcs = new ArrayList<Arc>();
|
ArrayList<Arc> pathArcs = new ArrayList<Arc>();
|
||||||
concurentNodeLabel = destinationNodeLabel;
|
concurentNodeLabel = destinationNodeLabel;
|
||||||
while(concurentNodeLabel.getPere() != null) {
|
while(concurentNodeLabel.getPere() != null) {
|
||||||
|
|
|
||||||
|
|
@ -39,9 +39,9 @@ public class Label implements Comparable<Label> {
|
||||||
this.pere = pere;
|
this.pere = pere;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getCoutRealise() {
|
// public double getCoutRealise() {
|
||||||
return coutRealise;
|
// return coutRealise;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public void setCoutRealise(float nouveauCout) {
|
public void setCoutRealise(float nouveauCout) {
|
||||||
this.coutRealise = nouveauCout;
|
this.coutRealise = nouveauCout;
|
||||||
|
|
@ -53,7 +53,7 @@ public class Label implements Comparable<Label> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Label o) {
|
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