Dijkstra correction probleme de path different de Bellman Ford : changement ordre ligne labelchange
This commit is contained in:
parent
d78019f648
commit
ced572abaa
2 changed files with 20 additions and 15 deletions
|
@ -27,8 +27,6 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
final ShortestPathData data = getInputData();
|
final ShortestPathData data = getInputData();
|
||||||
// on crée un inspector qui nous permettra de savoir si on peut ou pas utiliser un arc
|
// on crée un inspector qui nous permettra de savoir si on peut ou pas utiliser un arc
|
||||||
ArcInspector inspector = data.getArcInspector();
|
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 Graph graph = data.getGraph();
|
||||||
final int nbNodes = graph.size();
|
final int nbNodes = graph.size();
|
||||||
final Node destination = data.getDestination();
|
final Node destination = data.getDestination();
|
||||||
|
@ -47,6 +45,15 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
BinaryHeap<Label> tas = new BinaryHeap<>();
|
BinaryHeap<Label> tas = new BinaryHeap<>();
|
||||||
// on crée une variable permettant d'avoir le dernier label utilisé
|
// on crée une variable permettant d'avoir le dernier label utilisé
|
||||||
Label labelcourant;
|
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
|
// initialisation de Dijkstra
|
||||||
for (Node nodes :graph.getNodes()) {
|
for (Node nodes :graph.getNodes()) {
|
||||||
// on indique à chaque label le sommet courant dont il s'occupe
|
// 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()){
|
for (Arc arcscourants : labelcourant.getsommetcourant().getSuccessors()){
|
||||||
// Utilisation condition pour savoir si un arc peut être utilisé ou pas en fonction
|
// Utilisation condition pour savoir si un arc peut être utilisé ou pas en fonction
|
||||||
// du mode de transport (piéton ou voiture )
|
// du mode de transport (piéton ou voiture )
|
||||||
if(inspector.isAllowed(arcscourants)){
|
if(data.isAllowed(arcscourants)){
|
||||||
Node successeur = arcscourants.getDestination();
|
Node successeur = arcscourants.getDestination();
|
||||||
// si le successeur n'est pas marqué on vérifie son coût courant
|
// si le successeur n'est pas marqué on vérifie son coût courant
|
||||||
if(!(tableau_label[successeur.getId()].getmarque())) {
|
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)
|
// on accède au cout de l'arc (partie inspirée de BellmanFord)
|
||||||
double cout_arc = data.getCost(arcscourants);
|
double cout_arc = data.getCost(arcscourants);
|
||||||
// on accède au coût du sommet à partir de son label
|
// on accède au coût du sommet à partir de son label
|
||||||
|
@ -91,20 +99,16 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
// on compare les deux coûts
|
// on compare les deux coûts
|
||||||
if(cout_nv<cout_actuel) {
|
if(cout_nv<cout_actuel) {
|
||||||
Label labelchanger = tableau_label [successeur.getId()];
|
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
|
// si le coût nv est meilleur on update le cout du sommet au sein du label
|
||||||
labelchanger.setcoutrealise(cout_nv);
|
labelchanger.setcoutrealise(cout_nv);
|
||||||
// on indique que l'arc pere est arcscourants
|
// on indique que l'arc pere est arcscourants
|
||||||
labelchanger.setarcperefils(arcscourants);
|
labelchanger.setarcperefils(arcscourants);
|
||||||
// On notifie le fait qu'on a un nouveau node accessible
|
// On notifie le fait qu'on a un nouveau node accessible
|
||||||
notifyNodeReached(labelchanger.getsommetcourant());
|
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);
|
tas.insert(labelchanger);
|
||||||
} catch (ElementNotFoundException e) {
|
|
||||||
// on update sa place dans le tas s'il y est déjà
|
|
||||||
tas.insert(labelchanger);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,7 +118,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tableau_label[destination.getId()].getmarque()==false ||destination == origin ) {
|
if(tableau_label[destination.getId()].getmarque()==false) {
|
||||||
solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
|
solution = new ShortestPathSolution(data, AbstractSolution.Status.INFEASIBLE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -70,18 +70,19 @@ public class Label implements Comparable<Label>{
|
||||||
|
|
||||||
|
|
||||||
// on override la méthode de comparaison
|
// on override la méthode de comparaison
|
||||||
/*
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Label other){
|
public int compareTo(Label other){
|
||||||
return Double.compare(this.getCost(),other.getCost());
|
return Double.compare(this.getCost(),other.getCost());
|
||||||
} */
|
}
|
||||||
|
|
||||||
|
|
||||||
//car on va utiliser priority avce les plus petit distances car on a une binary heap
|
//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
|
// 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) {
|
public int compareTo(Label other) {
|
||||||
// Compare via getTotalCost plutôt que directement getCost
|
// Compare via getTotalCost plutôt que directement getCost
|
||||||
return Double.compare(this.getTotalCost(), other.getTotalCost());
|
return Double.compare(this.getTotalCost(), other.getTotalCost());
|
||||||
}
|
} */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue