Dijkstra correction probleme de path different de Bellman Ford : changement ordre ligne labelchange

This commit is contained in:
knzrd 2025-05-26 18:44:18 +02:00
parent d78019f648
commit ced572abaa
2 changed files with 20 additions and 15 deletions

View file

@ -27,8 +27,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
final ShortestPathData data = getInputData();
// on crée un inspector qui nous permettra de savoir si on peut ou pas utiliser un arc
ArcInspector inspector = data.getArcInspector();
// on change l'inspector au mode qui nous intéresse soit ici voiture ( qui est a la deuxieme case du tableau)
//inspector = ArcInspectorFactory.getAllFilters().get(1);
final Graph graph = data.getGraph();
final int nbNodes = graph.size();
final Node destination = data.getDestination();
@ -47,6 +45,15 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
BinaryHeap<Label> tas = new BinaryHeap<>();
// on crée une variable permettant d'avoir le dernier label utilisé
Label labelcourant;
// cas trivial: node d'origine et st le meme que le node destination
/* if(origin.equals(destination) ){
notifyOriginProcessed(origin);
notifyDestinationReached(destination);
Path cheminvide = new Path(graph);
solution = new ShortestPathSolution(data,AbstractSolution.Status.OPTIMAL,cheminvide);
return solution;
} */
// initialisation de Dijkstra
for (Node nodes :graph.getNodes()) {
// on indique à chaque label le sommet courant dont il s'occupe
@ -78,10 +85,11 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
for (Arc arcscourants : labelcourant.getsommetcourant().getSuccessors()){
// Utilisation condition pour savoir si un arc peut être utilisé ou pas en fonction
// du mode de transport (piéton ou voiture )
if(inspector.isAllowed(arcscourants)){
if(data.isAllowed(arcscourants)){
Node successeur = arcscourants.getDestination();
// si le successeur n'est pas marqué on vérifie son coût courant
if(!(tableau_label[successeur.getId()].getmarque())) {
// si il a deja ete accede donc s'il a un cout non
// on accède au cout de l'arc (partie inspirée de BellmanFord)
double cout_arc = data.getCost(arcscourants);
// on accède au coût du sommet à partir de son label
@ -91,30 +99,26 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
// on compare les deux coûts
if(cout_nv<cout_actuel) {
Label labelchanger = tableau_label [successeur.getId()];
if(cout_actuel != Double.POSITIVE_INFINITY){
tas.remove(labelchanger);
}
// si le coût nv est meilleur on update le cout du sommet au sein du label
labelchanger.setcoutrealise(cout_nv);
// on indique que l'arc pere est arcscourants
labelchanger.setarcperefils(arcscourants);
// On notifie le fait qu'on a un nouveau node accessible
notifyNodeReached(labelchanger.getsommetcourant());
try {
// on met ce noeud dans le tas si il n'y a jamais été mis auparavant
tas.remove(labelchanger);
tas.insert(labelchanger);
} catch (ElementNotFoundException e) {
// on update sa place dans le tas s'il y est déjà
tas.insert(labelchanger);
}
}
}
}
}
}
if(tableau_label[destination.getId()].getmarque()==false ||destination == origin ) {
if(tableau_label[destination.getId()].getmarque()==false) {
solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
}
else {

View file

@ -70,18 +70,19 @@ public class Label implements Comparable<Label>{
// on override la méthode de comparaison
/*
@Override
public int compareTo(Label other){
return Double.compare(this.getCost(),other.getCost());
} */
}
//car on va utiliser priority avce les plus petit distances car on a une binary heap
// ces labels sont associé à chaque noeud : les noeuds du graphes sont numérotés de 0 à N-1
@Override
/*@Override
public int compareTo(Label other) {
// Compare via getTotalCost plutôt que directement getCost
return Double.compare(this.getTotalCost(), other.getTotalCost());
}
} */
}