|
@@ -3,6 +3,7 @@ package org.insa.graphs.algorithm.shortestpath;
|
3
|
3
|
import org.insa.graphs.algorithm.AbstractSolution.Status;
|
4
|
4
|
import org.insa.graphs.algorithm.utils.BinaryHeap;
|
5
|
5
|
import org.insa.graphs.model.Arc;
|
|
6
|
+import org.insa.graphs.model.Node;
|
6
|
7
|
import org.insa.graphs.model.Path;
|
7
|
8
|
import java.util.ArrayList;
|
8
|
9
|
import java.util.Collections;//trier tout ça
|
|
@@ -13,7 +14,11 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
13
|
14
|
public DijkstraAlgorithm(ShortestPathData data) {
|
14
|
15
|
super(data);
|
15
|
16
|
}
|
16
|
|
-
|
|
17
|
+
|
|
18
|
+ public Label LabelTyped(Node sommet,Arc padre, float prix){
|
|
19
|
+ return new Label(sommet,padre, prix);
|
|
20
|
+ }
|
|
21
|
+
|
17
|
22
|
@Override
|
18
|
23
|
protected ShortestPathSolution doRun() {
|
19
|
24
|
|
|
@@ -22,17 +27,19 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
22
|
27
|
|
23
|
28
|
//initialisation
|
24
|
29
|
BinaryHeap<Label> tas=new BinaryHeap<Label>();//les Label sont comparés via leurs coûts
|
|
30
|
+
|
25
|
31
|
Label[] tablabel=new Label[data.getGraph().size()];
|
26
|
32
|
for (int i=0;i<tablabel.length;i++) {
|
27
|
|
- tablabel[i]=new Label(data.getGraph().get(i),null,Float.MAX_VALUE);//non marqué par défaut
|
|
33
|
+ tablabel[i]=LabelTyped(data.getGraph().get(i),null,Float.MAX_VALUE);//non marqué par défaut
|
28
|
34
|
}//dans le tablabel[idnode] on peut retrouver node
|
29
|
35
|
tablabel[data.getOrigin().getId()].cout=0;
|
30
|
|
- tas.insert(tablabel[data.getOrigin().getId()]);
|
31
|
|
-
|
|
36
|
+
|
|
37
|
+ tas.insert(tablabel[data.getOrigin().getId()]);
|
32
|
38
|
int nomark=tablabel.length;//nombre de sommets non marqués (pas optimal?)
|
33
|
39
|
int x;//id du node qu'on étudie
|
34
|
40
|
boolean arrive=false;//node de destination atteint ou pas
|
35
|
41
|
|
|
42
|
+
|
36
|
43
|
//itérations
|
37
|
44
|
while (nomark>0 && !arrive && !tas.isEmpty()){
|
38
|
45
|
|
|
@@ -56,14 +63,14 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
56
|
63
|
|
57
|
64
|
if (!tablabel[y].marque && data.isAllowed(arcy)) {//ligne 108 de l'excel d'avancement
|
58
|
65
|
|
59
|
|
- if (tablabel[y].cout>tablabel[x].cout+(float)data.getCost(arcy)) {
|
|
66
|
+ if (tablabel[y].getCost()>tablabel[x].getCost()+(float)data.getCost(arcy)) {
|
60
|
67
|
|
61
|
|
- if (tablabel[y].cout!=Float.MAX_VALUE) {
|
|
68
|
+ if (tablabel[y].getCost()!=Float.MAX_VALUE) {
|
62
|
69
|
tas.remove(tablabel[y]);
|
63
|
70
|
this.notifyNodeReached(arcy.getDestination());
|
64
|
71
|
}
|
65
|
72
|
|
66
|
|
- tablabel[y].cout=tablabel[x].cout+(float)data.getCost(arcy);
|
|
73
|
+ tablabel[y].cout=tablabel[x].getCost()+(float)data.getCost(arcy);
|
67
|
74
|
tablabel[y].pere=arcy;//ligne non dans le poly
|
68
|
75
|
tas.insert(tablabel[y]);
|
69
|
76
|
|
|
@@ -86,7 +93,7 @@ public class DijkstraAlgorithm extends ShortestPathAlgorithm {
|
86
|
93
|
while (labelact.pere!=null) {
|
87
|
94
|
bonsarcs.add(labelact.pere);
|
88
|
95
|
labelact=tablabel[labelact.pere.getOrigin().getId()];
|
89
|
|
- }
|
|
96
|
+ }
|
90
|
97
|
|
91
|
98
|
Collections.reverse(bonsarcs);
|
92
|
99
|
solution = new ShortestPathSolution(data,Status.OPTIMAL,new Path(data.getGraph(),bonsarcs));
|