implémentation correcte de la solution naïve (mis en commentaire de la solution précédente qui ne marchait pas)
Этот коммит содержится в:
родитель
e466356c86
коммит
d6bd57d709
2 изменённых файлов: 44 добавлений и 5 удалений
|
|
@ -105,12 +105,51 @@ public class ProblemeOuvert extends DijkstraAlgorithm {
|
||||||
double batteryLeft = ((LabelProblemeOuvert) LabelActuel).getAutonomieRestante();
|
double batteryLeft = ((LabelProblemeOuvert) LabelActuel).getAutonomieRestante();
|
||||||
|
|
||||||
double newCost = LabelActuel.getCoutRealise() + arcCost;
|
double newCost = LabelActuel.getCoutRealise() + arcCost;
|
||||||
|
|
||||||
|
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);
|
||||||
|
succLabel.setAutonomieRestante(batteryLeft);
|
||||||
|
predecessorArcs[succ.getId()] = arc;
|
||||||
|
|
||||||
|
// Insertion dans le tas car on est sûr qu'il n'est pas
|
||||||
|
|
||||||
|
heap.insert(succLabel);
|
||||||
|
|
||||||
|
notifyNodeReached(succ);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. On fait aussi le test avec une autonmie pleine pour voir si la solution est meilleure (il faudra rajouter 2mn au temps de trajet)
|
||||||
|
//si on recharge effectivement et détecter cette recharge
|
||||||
|
if (arc.getRoadInformation().getType() == RoadType.MOTORWAY) {
|
||||||
|
//if (newCost+120 < succLabel.getCoutRealise()) {
|
||||||
|
if (succLabel.getCoutRealise() != Double.POSITIVE_INFINITY) {
|
||||||
|
heap.remove(succLabel);
|
||||||
|
|
||||||
|
}
|
||||||
|
succLabel.setCoutRealise(newCost+120);
|
||||||
|
succLabel.setPere(arc);
|
||||||
|
succLabel.setAutonomieRestante(MAX_BATTERY);
|
||||||
|
predecessorArcs[succ.getId()] = arc;
|
||||||
|
|
||||||
|
// Insertion dans le tas car on est sûr qu'il n'est pas
|
||||||
|
|
||||||
|
heap.insert(succLabel);
|
||||||
|
|
||||||
|
notifyNodeReached(succ);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (batteryLeft < arcCost) { //si nous n'avons pas assez de batterie pour l'arc
|
if (batteryLeft < arcCost) { //si nous n'avons pas assez de batterie pour l'arc
|
||||||
// Recharge possible uniquement sur autoroute
|
// Recharge possible uniquement sur autoroute
|
||||||
if (arc.getRoadInformation().getType() == RoadType.MOTORWAY) {
|
if (arc.getRoadInformation().getType() == RoadType.MOTORWAY) {
|
||||||
double rechargeCost = newCost + 120; // 2 minutes de recharge
|
double rechargeCost = newCost + 120; // 2 minutes de recharge
|
||||||
if (rechargeCost < succLabel.getCoutRealise()) {
|
//if (rechargeCost < succLabel.getCoutRealise()) {
|
||||||
if (succLabel.getCoutRealise() != Double.POSITIVE_INFINITY) {
|
if (succLabel.getCoutRealise() != Double.POSITIVE_INFINITY) {
|
||||||
heap.remove(succLabel);
|
heap.remove(succLabel);
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +159,7 @@ public class ProblemeOuvert extends DijkstraAlgorithm {
|
||||||
predecessorArcs[succ.getId()] = arc;
|
predecessorArcs[succ.getId()] = arc;
|
||||||
heap.insert(succLabel);
|
heap.insert(succLabel);
|
||||||
notifyNodeReached(succ);
|
notifyNodeReached(succ);
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Assez de batterie
|
// Assez de batterie
|
||||||
|
|
@ -136,7 +175,7 @@ public class ProblemeOuvert extends DijkstraAlgorithm {
|
||||||
heap.insert(succLabel);
|
heap.insert(succLabel);
|
||||||
notifyNodeReached(succ);
|
notifyNodeReached(succ);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,7 @@ public class TestDijkstra {
|
||||||
System.out.println("== Test Probleme Ouvert ==");
|
System.out.println("== Test Probleme Ouvert ==");
|
||||||
testScenario("bretagne.mapgr",165317,74644 , Mode.TIME, false,2,false);
|
testScenario("bretagne.mapgr",165317,74644 , Mode.TIME, false,2,false);
|
||||||
|
|
||||||
System.out.println("== Test Probleme Ouvert ==");
|
//System.out.println("== Test Probleme Ouvert ==");
|
||||||
testScenario("bretagne.mapgr",165317,74644 , Mode.TIME, false,2,false);
|
//testScenario("bretagne.mapgr",165317,74644 , Mode.TIME, false,2,false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Загрузка…
Сослаться в новой задаче