résolution bug dijkstra
This commit is contained in:
parent
367bc7e877
commit
469c810f44
6 changed files with 13 additions and 27 deletions
|
|
@ -5,10 +5,10 @@ import java.util.EnumSet;
|
|||
import java.util.List;
|
||||
|
||||
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
||||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.model.GraphStatistics;
|
||||
import org.insa.graphs.model.AccessRestrictions.AccessMode;
|
||||
import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
|
||||
import org.insa.graphs.model.Arc;
|
||||
import org.insa.graphs.model.GraphStatistics;
|
||||
|
||||
public class ArcInspectorFactory {
|
||||
|
||||
|
|
|
|||
|
|
@ -37,10 +37,9 @@ public class MyArcInspector implements ArcInspector {
|
|||
// Calcul du coût sur le temps de parcours
|
||||
|
||||
double lengthInMeters = arc.getLength();
|
||||
double speedInMetersPerSecond = maxSpeed / 3.6;
|
||||
double speedInMetersPerSecond = arc.getRoadInformation().getMaximumSpeed() / 3.6; // Conversion de km/h à m/s
|
||||
return lengthInMeters / speedInMetersPerSecond;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -70,21 +70,15 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
Label succLabel = labels[succ.getId()];
|
||||
|
||||
if (succLabel.getMarque())
|
||||
continue; // déjà traité
|
||||
continue;
|
||||
|
||||
double newCost = LabelActuel.getTotalCost() + data.getCost(arc);
|
||||
// Correction ici : on utilise getCoutRealise() pour Dijkstra
|
||||
double newCost = LabelActuel.getCoutRealise() + data.getCost(arc);
|
||||
|
||||
//Label comp = new Label(null, false, newCost, null); //juste pour faire le compareTo entre label et pas entre double
|
||||
|
||||
if (newCost < succLabel.getTotalCost()) {
|
||||
//int res = succLabel.compareTo(comp);
|
||||
//if (res!=0){
|
||||
// Mise à jour du coût et du prédécesseur
|
||||
// Si le sommet a déjà un label dans le tas, on le retire
|
||||
// avant de le mettre à jour
|
||||
if (succLabel.getTotalCost() != Double.POSITIVE_INFINITY) {
|
||||
if (newCost < succLabel.getCoutRealise()) {
|
||||
if (succLabel.getCoutRealise() != Double.POSITIVE_INFINITY) {
|
||||
heap.remove(succLabel);
|
||||
System.out.println(succLabel.getCoutRealise());// print de confirmation , pour verif si tous les couts qui sortent du tas sont croissant. getTotalcost pas croissant!!
|
||||
//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);
|
||||
|
|
|
|||
|
|
@ -51,15 +51,7 @@ public class Label implements Comparable<Label> {
|
|||
// renvoit 0 si égal sinon renvoit la différence.
|
||||
@Override
|
||||
public int compareTo(Label L) {
|
||||
int retour;
|
||||
if (coutRealise == L.getTotalCost()) {
|
||||
retour = 0;
|
||||
}
|
||||
else {
|
||||
retour = (int) (coutRealise - L.getTotalCost());
|
||||
}
|
||||
return retour;
|
||||
|
||||
return Double.compare(this.getTotalCost(), L.getTotalCost());
|
||||
}
|
||||
|
||||
public void setSommetCourant(Node sommetCourant) {
|
||||
|
|
|
|||
|
|
@ -175,7 +175,8 @@ public class TestDijkstra {
|
|||
// System.out.println("== Trajet long (et pénible avec les enfants) ==");
|
||||
// testScenario("bretagne.mapgr",564429,602395 , Mode.LENGTH, false,false,false);
|
||||
|
||||
|
||||
System.out.println("== Test bug dijkstra temps ==");
|
||||
testScenario("paris.mapgr", 27361, 36108, Mode.TIME, true,false,false);
|
||||
|
||||
// System.out.println("== Trajet impossible (piste cyclable) ==");
|
||||
// testScenario("insa.mapgr",90,922 , Mode.LENGTH, false,false,true); //marche pas
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ public abstract class Arc {
|
|||
* @see Arc#getTravelTime(double)
|
||||
*/
|
||||
public double getMinimumTravelTime() {
|
||||
return getTravelTime(getRoadInformation().getMaximumSpeed());
|
||||
return getTravelTime(this.getRoadInformation().getMaximumSpeed());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue