|
@@ -1,7 +1,11 @@
|
1
|
1
|
package org.insa.graphs.algorithm.shortestpath;
|
2
|
2
|
|
|
3
|
+import org.insa.graphs.algorithm.AbstractSolution.Status;
|
3
|
4
|
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
4
|
5
|
import org.insa.graphs.model.Arc;
|
|
6
|
+import org.insa.graphs.model.Path;
|
|
7
|
+import java.util.ArrayList;
|
|
8
|
+import java.util.List;//trier tout ça
|
5
|
9
|
|
6
|
10
|
public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
7
|
11
|
|
|
@@ -13,42 +17,57 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
13
|
17
|
@Override
|
14
|
18
|
protected ShortestPathSolution doRun() {
|
15
|
19
|
final ShortestPathData data = getInputData();
|
16
|
|
- ShortestPathSolution solution = null;
|
|
20
|
+ ShortestPathSolution solution = new ShortestPathSolution(data,Status.UNKNOWN);//modifié
|
17
|
21
|
// TODO:
|
18
|
22
|
|
19
|
23
|
//initialisation
|
20
|
|
- BinaryHeap<Integer> tas=new BinaryHeap<Integer>();
|
|
24
|
+ BinaryHeap<Integer> tas=new BinaryHeap<Integer>();//type comparable nécessaire (donc pas Arc)
|
21
|
25
|
Label[] tablabel=new Label[data.getGraph().size()];
|
22
|
26
|
for (int i=0;i<tablabel.length;i++) {
|
23
|
27
|
tablabel[i]=new Label(data.getGraph().get(i),null,Integer.MAX_VALUE);//non marqué par défaut
|
24
|
|
- }
|
|
28
|
+ }//dans le tablabel[idnode] on peut retrouver node
|
25
|
29
|
tablabel[data.getOrigin().getId()].cout=0;
|
26
|
30
|
tas.insert(data.getOrigin().getId());
|
27
|
31
|
|
28
|
|
- boolean exnonmar=true;//existe sommets non marqués
|
|
32
|
+ int nomark=tablabel.length;//existe sommets non marqués (ou à coût infini?)(pas optimal?)
|
29
|
33
|
int x;//id du node qu'on étudie
|
|
34
|
+
|
|
35
|
+ if (data.getOrigin()==data.getDestination()) {
|
|
36
|
+ //retourne un graphe avec juste un node si besoin de gérer ce cas particulier
|
|
37
|
+ //(à vérifier, peut-être qu'une fois le reste fini ce ne sera pas nécessaire)
|
|
38
|
+ Path chemin= new Path(data.getGraph(),data.getOrigin());
|
|
39
|
+ solution = new ShortestPathSolution(data,Status.OPTIMAL,chemin);
|
|
40
|
+ nomark=0;
|
|
41
|
+ }
|
|
42
|
+
|
30
|
43
|
//itérations
|
31
|
|
- while (exnonmar){
|
|
44
|
+ while (nomark>0){
|
32
|
45
|
x=tas.deleteMin();
|
33
|
46
|
tablabel[x].marque=true;
|
34
|
|
- for (Arc arcy: data.getGraph().get(x).getSuccessors()) {
|
|
47
|
+ nomark--;
|
|
48
|
+ for (Arc arcy: tablabel[x].sommet_courant.getSuccessors()) {
|
35
|
49
|
if (!tablabel[arcy.getDestination().getId()].marque) {
|
36
|
50
|
if (tablabel[arcy.getDestination().getId()].cout>tablabel[x].cout+(int)arcy.getMinimumTravelTime()) {
|
37
|
51
|
tablabel[arcy.getDestination().getId()].cout=tablabel[x].cout+(int)arcy.getMinimumTravelTime();
|
|
52
|
+ tablabel[arcy.getDestination().getId()].pere=arcy;//ligne non dans le poly
|
38
|
53
|
try{
|
39
|
54
|
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
|
|
55
|
+ } 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
|
56
|
tas.insert(arcy.getDestination().getId());
|
42
|
57
|
}
|
43
|
|
- }
|
|
58
|
+ }//s'aider de l'algorithme de Bellman-Ford déjà fait
|
44
|
59
|
}
|
45
|
60
|
|
46
|
|
- exnonmar=false;//pas ici; comment savoir quand le changer?
|
47
|
|
- //penser à gérer le cas "aucun chemin n'existe"
|
|
61
|
+ //penser à gérer le cas "aucun chemin n'existe" (avec l'initialisation par défaut?)
|
48
|
62
|
}
|
49
|
63
|
}
|
50
|
|
- //créer le chemin solution grâce au tas
|
51
|
|
-
|
|
64
|
+ //créer le chemin solution grâce au tas (le tas nécessite un type comparable donc l'id des nodes)
|
|
65
|
+ List<Arc> bonsarcs=new ArrayList<Arc>();//pourquoi une erreur ici?
|
|
66
|
+ while (!tas.isEmpty()) {
|
|
67
|
+ bonsarcs.add(tablabel[tas.deleteMin()].pere);//un node de plus qu'il n'y a d'arcs, vérifier ce que ça donne
|
|
68
|
+ }//est-ce que le cas "un seul node" marche bien en renvoyant un unique arc null?
|
|
69
|
+ Path chemin= new Path(data.getGraph(),bonsarcs);
|
|
70
|
+ solution = new ShortestPathSolution(data,Status.OPTIMAL,chemin);
|
52
|
71
|
return solution;
|
53
|
72
|
}
|
54
|
73
|
|