Dijkstra beta0.2
This commit is contained in:
parent
2a5ac7f244
commit
ad0e3a294f
1 changed files with 20 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
||||||
package org.insa.graphs.algorithm.shortestpath;
|
package org.insa.graphs.algorithm.shortestpath;
|
||||||
|
|
||||||
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
||||||
|
import org.insa.graphs.model.Arc;
|
||||||
|
|
||||||
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
|
|
||||||
|
@ -16,35 +17,37 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
||||||
// TODO:
|
// TODO:
|
||||||
|
|
||||||
//initialisation
|
//initialisation
|
||||||
BinaryHeap tas=new BinaryHeap();
|
BinaryHeap<Integer> tas=new BinaryHeap<Integer>();
|
||||||
Label[] tablabel=new Label[data.getGraph().size()];
|
Label[] tablabel=new Label[data.getGraph().size()];
|
||||||
for (int i=0;i<tablabel.length;i++) {
|
for (int i=0;i<tablabel.length;i++) {
|
||||||
tablabel[i]=new Label(data.getGraph().get(i),null,Integer.MAX_VALUE);
|
tablabel[i]=new Label(data.getGraph().get(i),null,Integer.MAX_VALUE);//non marqué par défaut
|
||||||
}
|
}
|
||||||
tablabel[data.getOrigin().getId()].cout=0;
|
tablabel[data.getOrigin().getId()].cout=0;
|
||||||
tas.insert(data.getOrigin().getId());
|
tas.insert(data.getOrigin().getId());
|
||||||
|
|
||||||
boolean exnonmar=true;
|
boolean exnonmar=true;//existe sommets non marqués
|
||||||
int min;
|
int x;//id du node qu'on étudie
|
||||||
//itérations
|
//itérations
|
||||||
while (exnonmar) {
|
while (exnonmar){
|
||||||
min=tas.deleteMin();
|
x=tas.deleteMin();
|
||||||
tablabel[min].marque=true;
|
tablabel[x].marque=true;
|
||||||
for (successeurs y) {
|
for (Arc arcy: data.getGraph().get(x).getSuccessors()) {
|
||||||
if (!tablabel[y].marque) {
|
if (!tablabel[arcy.getDestination().getId()].marque) {
|
||||||
if (tablabel[y].cout>tablabel[x].cout+(int)tablabel[y].pere.getMinimumTravelTime()) {
|
if (tablabel[arcy.getDestination().getId()].cout>tablabel[x].cout+(int)arcy.getMinimumTravelTime()) {
|
||||||
tablabel[y].cout=tablabel[x].cout+(int)tablabel[y].pere.getMinimumTravelTime();
|
tablabel[arcy.getDestination().getId()].cout=tablabel[x].cout+(int)arcy.getMinimumTravelTime();
|
||||||
if (exist y in tas) {
|
try{
|
||||||
tas.update(y);
|
tas.remove(arcy.getDestination().getId());
|
||||||
}else {
|
} finally {//méthode fortement douteuse pour opérer update ou inssert selon si l'élément est déjà dans le tas ou pas
|
||||||
tas.insert(y);
|
tas.insert(arcy.getDestination().getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exnonmar=false;//pas ici; comment savoir quand le changer?
|
||||||
|
//penser à gérer le cas "aucun chemin n'existe"
|
||||||
}
|
}
|
||||||
|
|
||||||
exnonmar=false;
|
|
||||||
}
|
}
|
||||||
|
//créer le chemin solution grâce au tas
|
||||||
|
|
||||||
return solution;
|
return solution;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue