Dijkstra ajustement
This commit is contained in:
parent
ef88c3e14f
commit
8f4633fde0
1 changed files with 14 additions and 26 deletions
|
|
@ -9,7 +9,7 @@ import org.insa.graphs.model.Arc;
|
|||
import org.insa.graphs.model.Graph;
|
||||
import org.insa.graphs.model.Node;
|
||||
import org.insa.graphs.model.Path;
|
||||
import org.insa.graphs.model.RoadInformation.RoadType;
|
||||
|
||||
|
||||
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||
|
||||
|
|
@ -21,29 +21,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
return new Label(node, false, Double.POSITIVE_INFINITY, null);
|
||||
}
|
||||
|
||||
protected void tryUpdateLabel(Label[] labels, BinaryHeap<Label> heap, Node node,
|
||||
double newCost, Arc pere) {
|
||||
|
||||
Label label = labels[node.getId()];
|
||||
|
||||
if (newCost < label.getCoutRealise()) {
|
||||
if (label.getCoutRealise() != Double.POSITIVE_INFINITY) {
|
||||
heap.remove(label);
|
||||
}
|
||||
|
||||
label.setCoutRealise(newCost);
|
||||
label.setPere(pere);
|
||||
|
||||
heap.insert(label);
|
||||
notifyNodeReached(node);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void fonctionProblemeOuvert(RoadType typeDeRoute,Label[] labels, BinaryHeap<Label> heap, Node node,
|
||||
double newCost, Arc pere){}
|
||||
|
||||
|
||||
@Override
|
||||
protected ShortestPathSolution doRun() {
|
||||
|
|
@ -98,10 +75,21 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
// Correction ici : on utilise getCoutRealise() pour Dijkstra
|
||||
double newCost = LabelActuel.getCoutRealise() + data.getCost(arc);
|
||||
|
||||
tryUpdateLabel(labels, heap, succ, newCost, arc);
|
||||
if (newCost < succLabel.getCoutRealise()) {
|
||||
if (succLabel.getCoutRealise() != Double.POSITIVE_INFINITY) {
|
||||
heap.remove(succLabel);
|
||||
//System.out.println(succLabel.getTotalCost());// print de confirmation , pour verif si tous les couts qui sortent du tas sont croissant. getTotalcost pas croissant!!
|
||||
}
|
||||
succLabel.setCoutRealise(newCost);
|
||||
succLabel.setPere(arc);
|
||||
predecessorArcs[succ.getId()] = arc;
|
||||
|
||||
fonctionProblemeOuvert(arc.getRoadInformation().getType(),labels, heap, succ, newCost, arc); //fonction uniquement pour probleme ouvert, permet de ne pas réécrire l'algorithme pour le problème ouvert
|
||||
// Insertion dans le tas car on est sûr qu'il n'est pas
|
||||
|
||||
heap.insert(succLabel);
|
||||
|
||||
notifyNodeReached(succ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue