|
@@ -1,6 +1,7 @@
|
1
|
1
|
package org.insa.graphs.algorithm.shortestpath;
|
2
|
2
|
|
3
|
3
|
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
|
4
|
+import org.insa.graphs.model.Arc;
|
4
|
5
|
|
5
|
6
|
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
6
|
7
|
|
|
@@ -16,35 +17,37 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
16
|
17
|
// TODO:
|
17
|
18
|
|
18
|
19
|
//initialisation
|
19
|
|
- BinaryHeap tas=new BinaryHeap();
|
|
20
|
+ BinaryHeap<Integer> tas=new BinaryHeap<Integer>();
|
20
|
21
|
Label[] tablabel=new Label[data.getGraph().size()];
|
21
|
22
|
for (int i=0;i<tablabel.length;i++) {
|
22
|
|
- tablabel[i]=new Label(data.getGraph().get(i),null,Integer.MAX_VALUE);
|
|
23
|
+ tablabel[i]=new Label(data.getGraph().get(i),null,Integer.MAX_VALUE);//non marqué par défaut
|
23
|
24
|
}
|
24
|
25
|
tablabel[data.getOrigin().getId()].cout=0;
|
25
|
26
|
tas.insert(data.getOrigin().getId());
|
26
|
27
|
|
27
|
|
- boolean exnonmar=true;
|
28
|
|
- int min;
|
|
28
|
+ boolean exnonmar=true;//existe sommets non marqués
|
|
29
|
+ int x;//id du node qu'on étudie
|
29
|
30
|
//itérations
|
30
|
|
- while (exnonmar) {
|
31
|
|
- min=tas.deleteMin();
|
32
|
|
- tablabel[min].marque=true;
|
33
|
|
- for (successeurs y) {
|
34
|
|
- if (!tablabel[y].marque) {
|
35
|
|
- if (tablabel[y].cout>tablabel[x].cout+(int)tablabel[y].pere.getMinimumTravelTime()) {
|
36
|
|
- tablabel[y].cout=tablabel[x].cout+(int)tablabel[y].pere.getMinimumTravelTime();
|
37
|
|
- if (exist y in tas) {
|
38
|
|
- tas.update(y);
|
39
|
|
- }else {
|
40
|
|
- tas.insert(y);
|
|
31
|
+ while (exnonmar){
|
|
32
|
+ x=tas.deleteMin();
|
|
33
|
+ tablabel[x].marque=true;
|
|
34
|
+ for (Arc arcy: data.getGraph().get(x).getSuccessors()) {
|
|
35
|
+ if (!tablabel[arcy.getDestination().getId()].marque) {
|
|
36
|
+ if (tablabel[arcy.getDestination().getId()].cout>tablabel[x].cout+(int)arcy.getMinimumTravelTime()) {
|
|
37
|
+ tablabel[arcy.getDestination().getId()].cout=tablabel[x].cout+(int)arcy.getMinimumTravelTime();
|
|
38
|
+ try{
|
|
39
|
+ tas.remove(arcy.getDestination().getId());
|
|
40
|
+ } finally {//méthode fortement douteuse pour opérer update ou inssert selon si l'élément est déjà dans le tas ou pas
|
|
41
|
+ tas.insert(arcy.getDestination().getId());
|
41
|
42
|
}
|
42
|
43
|
}
|
43
|
44
|
}
|
|
45
|
+
|
|
46
|
+ exnonmar=false;//pas ici; comment savoir quand le changer?
|
|
47
|
+ //penser à gérer le cas "aucun chemin n'existe"
|
44
|
48
|
}
|
45
|
|
-
|
46
|
|
- exnonmar=false;
|
47
|
49
|
}
|
|
50
|
+ //créer le chemin solution grâce au tas
|
48
|
51
|
|
49
|
52
|
return solution;
|
50
|
53
|
}
|