Dijkstra avec Observers
This commit is contained in:
parent
91e3152d6d
commit
31de9cb5f5
1 changed files with 16 additions and 12 deletions
|
@ -16,6 +16,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
|
||||
@Override
|
||||
protected ShortestPathSolution doRun() {
|
||||
|
||||
final ShortestPathData data = getInputData();
|
||||
ShortestPathSolution solution = new ShortestPathSolution(data,Status.UNKNOWN);//modifié
|
||||
|
||||
|
@ -31,10 +32,9 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
int nomark=tablabel.length;//nombre de sommets non marqués (pas optimal?)
|
||||
int x;//id du node qu'on étudie
|
||||
boolean arrive=false;//node de destination atteint ou pas
|
||||
System.out.println("Initialisation OK");
|
||||
|
||||
//itérations
|
||||
while (nomark>0 && !arrive){
|
||||
while (nomark>0 && !arrive && !tas.isEmpty()){
|
||||
|
||||
x=tas.deleteMin().sommet_courant.getId();
|
||||
|
||||
|
@ -43,23 +43,25 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
}else {
|
||||
|
||||
tablabel[x].marque=true;
|
||||
this.notifyNodeMarked(tablabel[x].sommet_courant);
|
||||
nomark--;
|
||||
int y;
|
||||
|
||||
for (Arc arcy: tablabel[x].sommet_courant.getSuccessors()) {//mauvais parcours?
|
||||
for (Arc arcy: tablabel[x].sommet_courant.getSuccessors()) {
|
||||
|
||||
y=arcy.getDestination().getId();
|
||||
|
||||
if (!tablabel[y].marque) {
|
||||
if (!tablabel[y].marque && data.isAllowed(arcy)) {//ligne 108 de l'excel d'avancement
|
||||
|
||||
if (tablabel[y].cout>tablabel[x].cout+(float)data.getCost(arcy)) {
|
||||
|
||||
if (tablabel[y].cout!=Float.MAX_VALUE)
|
||||
if (tablabel[y].cout!=Float.MAX_VALUE) {
|
||||
tas.remove(tablabel[y]);
|
||||
this.notifyNodeReached(arcy.getDestination());
|
||||
}
|
||||
|
||||
tablabel[y].cout=tablabel[x].cout+(float)data.getCost(arcy);
|
||||
tablabel[y].pere=arcy;//ligne non dans le poly
|
||||
//méthode à vérifier pour opérer update ou insert (avec le if float.max plus haut)
|
||||
tas.insert(tablabel[y]);
|
||||
|
||||
}
|
||||
|
@ -69,23 +71,25 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
|||
}
|
||||
}
|
||||
|
||||
System.out.println("Itérations OK");
|
||||
|
||||
if (!arrive) {
|
||||
solution= new ShortestPathSolution(data,Status.INFEASIBLE);
|
||||
}else {
|
||||
|
||||
this.notifyDestinationReached(data.getDestination());
|
||||
|
||||
ArrayList<Arc> bonsarcs=new ArrayList<Arc>();
|
||||
Label labelact=tablabel[data.getDestination().getId()];
|
||||
|
||||
while (labelact.pere!=null) {
|
||||
bonsarcs.add(labelact.pere);
|
||||
labelact=tablabel[labelact.pere.getOrigin().getId()];
|
||||
//à vérifier
|
||||
}//est-ce que le cas "un seul node" marche bien en renvoyant un unique arc null?
|
||||
}
|
||||
|
||||
Collections.reverse(bonsarcs);
|
||||
//Path chemin= new Path(data.getGraph(),bonsarcs);//y'a t-il un retour si le chemin est infaisable? éviterait la condition précédente si oui
|
||||
solution = new ShortestPathSolution(data,Status.OPTIMAL,new Path(data.getGraph(),bonsarcs));
|
||||
}
|
||||
System.out.println("Fin OK");
|
||||
|
||||
return solution;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue