|
@@ -56,31 +56,35 @@ public class DijkstraAlgorithm_et_AStarTest{
|
56
|
56
|
public static void initAll() throws IOException {
|
57
|
57
|
|
58
|
58
|
//TODO: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHHHH
|
59
|
|
- /*//gestion des restrictions pour pouvoir créer les Bellman-Ford
|
|
59
|
+ //rabbithole, mission annulée
|
|
60
|
+ //sinon, utilisation de toAccessInformation(), à condition de savoir quel bit correspond à quoi...
|
|
61
|
+ //gestion des restrictions pour pouvoir créer les Bellman-Ford
|
60
|
62
|
AccessRestrictions voiture, pedestre;
|
61
|
|
- AccessRestrictions.AccessRestriction authorise = AccessRestrictions.AccessRestriction.ALLOWED;
|
|
63
|
+ /*AccessRestrictions.AccessRestriction authorise = AccessRestrictions.AccessRestriction.ALLOWED;
|
62
|
64
|
EnumMap<AccessMode, AccessRestrictions.AccessRestriction> pmap, vmap;
|
63
|
65
|
pmap = null;//dkgfvbwslidfue djeflmmqff^dfomqf^sf652s894fd5swrtwedf+e
|
64
|
|
- vmap = new EnumMap<AccessMode, AccessRestrictions.AccessRestriction>();
|
|
66
|
+ vmap = null;//cette initalisation ne marche pas, COMMENT faire? ->toAccessInformation de voiture et pedestre sans passer par des EnumMap
|
65
|
67
|
pmap.put(AccessMode.FOOT, authorise);
|
66
|
|
- vmap.put(AccessMode.MOTORCAR, authorise);
|
67
|
|
- pedestre = new AccessRestrictions(pmap);
|
68
|
|
- voiture = new AccessRestrictions(vmap);*/
|
|
68
|
+ //vmap.put(AccessMode.MOTORCAR, authorise);*/
|
|
69
|
+ //bloc actuellement inutile
|
69
|
70
|
|
70
|
|
- RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, false, 36, ""),
|
71
|
|
- speed20 = new RoadInformation(RoadType.MOTORWAY, null, false, 72, ""),
|
72
|
|
- pietonable = new RoadInformation(RoadType.PEDESTRIAN, null, false, 5, "");
|
|
71
|
+ voiture = new AccessRestrictions();//vmap en paramètre si possible
|
|
72
|
+ pedestre = new AccessRestrictions();//pmap en paramètre si possible
|
|
73
|
+
|
|
74
|
+ RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, voiture, false, 36, ""),
|
|
75
|
+ speed20 = new RoadInformation(RoadType.MOTORWAY, voiture, false, 72, ""),
|
|
76
|
+ pietonable = new RoadInformation(RoadType.PEDESTRIAN, pedestre, false, 5, "");
|
73
|
77
|
//cyclable = new RoadInformation(RoadType.CYCLEWAY, null, false, 20, ""),
|
74
|
78
|
//toutes les routes ici sont à double sens
|
75
|
79
|
//attention, les piétons ont une maxspeed définie à 5
|
76
|
80
|
|
77
|
81
|
// Create nodes
|
78
|
|
- nodes = new Node[8];
|
|
82
|
+ nodes = new Node[9];
|
79
|
83
|
for (int i = 0; i < nodes.length; ++i) {
|
80
|
84
|
nodes[i] = new Node(i, null);
|
81
|
85
|
}
|
82
|
86
|
|
83
|
|
- // définition des arcs
|
|
87
|
+ // définition des arcs (graphe custom)
|
84
|
88
|
ab = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null);
|
85
|
89
|
ac = Node.linkNodes(nodes[0], nodes[2], 50, speed20, null);
|
86
|
90
|
ad = Node.linkNodes(nodes[0], nodes[3], 15, speed10, null);
|
|
@@ -103,62 +107,65 @@ public class DijkstraAlgorithm_et_AStarTest{
|
103
|
107
|
|
104
|
108
|
//initialisation des datas
|
105
|
109
|
dataal= new ShortestPathData(graph, nodes[0], nodes[4], alllen);//a->e
|
106
|
|
- datacl= new ShortestPathData(graph, nodes[0], nodes[0], carlen);//b->g
|
107
|
|
- dataat= new ShortestPathData(graph, nodes[0], nodes[0], alltime);//h->b
|
108
|
|
- datact= new ShortestPathData(graph, nodes[0], nodes[0], cartime);//c->b
|
109
|
|
- datapt= new ShortestPathData(graph, nodes[5], nodes[0], pietime);//f->e
|
|
110
|
+ datacl= new ShortestPathData(graph, nodes[1], nodes[6], carlen);//b->g
|
|
111
|
+ dataat= new ShortestPathData(graph, nodes[7], nodes[1], alltime);//h->b
|
|
112
|
+ datact= new ShortestPathData(graph, nodes[2], nodes[1], cartime);//c->b
|
|
113
|
+ datapt= new ShortestPathData(graph, nodes[5], nodes[4], pietime);//f->e
|
110
|
114
|
onenodata=new ShortestPathData(graph, nodes[2], nodes[2], pietime);
|
111
|
115
|
emptydata=new ShortestPathData(graph, null, null, pietime);
|
112
|
|
- invalidata=new ShortestPathData(graph, nodes[0], nodes[7], carlen);//h est accessible uniquement aux piétons
|
|
116
|
+ invalidata=new ShortestPathData(graph, nodes[0], nodes[8], carlen);//h aurait dû être inaccessible aux voitures
|
|
117
|
+ //pour compenser, ajout du node i non relié
|
113
|
118
|
|
114
|
119
|
//initialisation des Dijkstras
|
115
|
120
|
dijkal = (new DijkstraAlgorithm(dataal)).run();
|
116
|
121
|
dijkcl = (new DijkstraAlgorithm(datacl)).run();
|
117
|
122
|
dijkat = (new DijkstraAlgorithm(dataat)).run();
|
118
|
123
|
dijkct = (new DijkstraAlgorithm(datact)).run();
|
119
|
|
- //dijkpt = (new DijkstraAlgorithm(datapt)).run();//erreur ici
|
|
124
|
+ dijkpt = (new DijkstraAlgorithm(datapt)).run();
|
120
|
125
|
onenodijk = (new DijkstraAlgorithm(onenodata)).run();
|
121
|
|
- emptydijk = (new DijkstraAlgorithm(emptydata)).run();//erreur ici
|
122
|
|
- //invalidijk = (new DijkstraAlgorithm(invalidata)).run();//et erreur là
|
|
126
|
+ emptydijk = (new DijkstraAlgorithm(emptydata)).run();
|
|
127
|
+ invalidijk = (new DijkstraAlgorithm(invalidata)).run();
|
|
128
|
+ System.out.print(invalidijk.toString());//----------------------hey, look here
|
123
|
129
|
|
124
|
130
|
//initialisation des A*
|
125
|
131
|
asal = (new DijkstraAlgorithm(dataal)).run();
|
126
|
132
|
ascl = (new DijkstraAlgorithm(datacl)).run();
|
127
|
133
|
asat = (new DijkstraAlgorithm(dataat)).run();
|
128
|
134
|
asct = (new DijkstraAlgorithm(datact)).run();
|
129
|
|
- //aspt = (new DijkstraAlgorithm(datapt)).run();//erreur ici
|
|
135
|
+ aspt = (new DijkstraAlgorithm(datapt)).run();
|
130
|
136
|
asonenod = (new DijkstraAlgorithm(onenodata)).run();
|
131
|
|
- asempty = (new DijkstraAlgorithm(emptydata)).run();//erreur ici
|
132
|
|
- //asinvalid = (new DijkstraAlgorithm(invalidata)).run();//et erreur là
|
|
137
|
+ asempty = (new DijkstraAlgorithm(emptydata)).run();
|
|
138
|
+ asinvalid = (new DijkstraAlgorithm(invalidata)).run();
|
133
|
139
|
|
134
|
140
|
//initialisation des Bellman-Ford pour comparaison
|
135
|
141
|
bfaal = (new BellmanFordAlgorithm(dataal)).run();
|
136
|
|
- //bfacl = (new BellmanFordAlgorithm(datacl)).run();
|
137
|
|
- /*bfaat = (new BellmanFordAlgorithm(dataat)).run();
|
|
142
|
+ bfacl = (new BellmanFordAlgorithm(datacl)).run();
|
|
143
|
+ bfaat = (new BellmanFordAlgorithm(dataat)).run();
|
138
|
144
|
bfact = (new BellmanFordAlgorithm(datact)).run();
|
139
|
|
- bfapt = (new BellmanFordAlgorithm(datapt)).run();*/ //erreurs partout ici...
|
|
145
|
+ bfapt = (new BellmanFordAlgorithm(datapt)).run();
|
140
|
146
|
|
141
|
147
|
}
|
142
|
148
|
|
143
|
|
- //créer plus et avec des maps différentes
|
144
|
|
- //faire des test spécifiques pour longs trajets
|
145
|
|
-
|
146
|
|
-
|
147
|
|
- /*(Test faits directement via la console et DijkstraAlgorithm.java, actuellement commentés:
|
148
|
|
- -coûts croissants
|
149
|
|
- -nbr successeurs cohérents
|
150
|
|
- -tas valide.)*/
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+ /* ( Test faits directement via la console et DijkstraAlgorithm.java, actuellement commentés:
|
|
153
|
+ - coûts croissants
|
|
154
|
+ - nbr successeurs cohérents
|
|
155
|
+ - tas valide. ) */
|
151
|
156
|
|
|
157
|
+
|
|
158
|
+
|
152
|
159
|
@Test
|
153
|
160
|
public void cheminValideD() {
|
154
|
161
|
assertTrue(dijkal.getPath().isValid());
|
155
|
162
|
assertTrue(dijkcl.getPath().isValid());
|
156
|
163
|
assertTrue(dijkat.getPath().isValid());
|
157
|
164
|
assertTrue(dijkct.getPath().isValid());
|
158
|
|
- //assertTrue(dijkpt.getPath().isValid());//pas normal
|
|
165
|
+ assertTrue(dijkpt.getPath().isValid());
|
159
|
166
|
assertTrue(onenodijk.getPath().isValid());
|
160
|
167
|
assertTrue(emptydijk.getPath().isValid());
|
161
|
|
- //assertFalse(invalidijk.getPath().isValid());
|
|
168
|
+ assertFalse(invalidijk.getPath().isValid());
|
162
|
169
|
}
|
163
|
170
|
|
164
|
171
|
@Test
|
|
@@ -167,10 +174,10 @@ public class DijkstraAlgorithm_et_AStarTest{
|
167
|
174
|
assertTrue(ascl.getPath().isValid());
|
168
|
175
|
assertTrue(asat.getPath().isValid());
|
169
|
176
|
assertTrue(asct.getPath().isValid());
|
170
|
|
- //assertTrue(aspt.getPath().isValid());//pas normal
|
|
177
|
+ assertTrue(aspt.getPath().isValid());
|
171
|
178
|
assertTrue(asonenod.getPath().isValid());
|
172
|
179
|
assertTrue(asempty.getPath().isValid());
|
173
|
|
- //assertFalse(asinvalid.getPath().isValid());
|
|
180
|
+ assertFalse(asinvalid.getPath().isValid());
|
174
|
181
|
}
|
175
|
182
|
|
176
|
183
|
@Test
|
|
@@ -179,10 +186,10 @@ public class DijkstraAlgorithm_et_AStarTest{
|
179
|
186
|
assertTrue(dijkcl.isFeasible());
|
180
|
187
|
assertTrue(dijkat.isFeasible());
|
181
|
188
|
assertTrue(dijkct.isFeasible());
|
182
|
|
- //assertTrue(dijkpt.isFeasible());
|
|
189
|
+ assertTrue(dijkpt.isFeasible());
|
183
|
190
|
assertTrue(onenodijk.isFeasible());
|
184
|
191
|
assertFalse(emptydijk.isFeasible());
|
185
|
|
- //assertFalse(invalidijk.isFeasible());
|
|
192
|
+ assertFalse(invalidijk.isFeasible());
|
186
|
193
|
}
|
187
|
194
|
|
188
|
195
|
@Test
|
|
@@ -191,29 +198,29 @@ public class DijkstraAlgorithm_et_AStarTest{
|
191
|
198
|
assertTrue(ascl.isFeasible());
|
192
|
199
|
assertTrue(asat.isFeasible());
|
193
|
200
|
assertTrue(asct.isFeasible());
|
194
|
|
- //assertTrue(aspt.isFeasible());
|
|
201
|
+ assertTrue(aspt.isFeasible());
|
195
|
202
|
assertTrue(asonenod.isFeasible());
|
196
|
203
|
assertFalse(asempty.isFeasible());
|
197
|
|
- //assertFalse(asinvalid.isFeasible());
|
|
204
|
+ assertFalse(asinvalid.isFeasible());
|
198
|
205
|
}
|
199
|
206
|
|
200
|
207
|
//résultat identique à Bellman-Ford (sur les petits scénarios)
|
201
|
208
|
@Test
|
202
|
209
|
public void DsameasBF() {
|
203
|
210
|
assertTrue(Float.compare(dijkal.getPath().getLength(),bfaal.getPath().getLength())==0);
|
204
|
|
- //assertTrue(Float.compare(dijkcl.getPath().getLength(),bfacl.getPath().getLength())==0);
|
205
|
|
- //assertTrue(Double.compare(dijkat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
|
206
|
|
- //assertTrue(Double.compare(dijkct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
|
207
|
|
- //assertTrue(Double.compare(dijkpt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
|
|
211
|
+ assertTrue(Float.compare(dijkcl.getPath().getLength(),bfacl.getPath().getLength())==0);
|
|
212
|
+ assertTrue(Double.compare(dijkat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
|
|
213
|
+ assertTrue(Double.compare(dijkct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
|
|
214
|
+ assertTrue(Double.compare(dijkpt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
|
208
|
215
|
}
|
209
|
216
|
|
210
|
217
|
@Test
|
211
|
218
|
public void AsameasBF() {
|
212
|
219
|
assertTrue(Float.compare(asal.getPath().getLength(),bfaal.getPath().getLength())==0);
|
213
|
|
- //assertTrue(Float.compare(ascl.getPath().getLength(),bfacl.getPath().getLength())==0);
|
214
|
|
- //assertTrue(Double.compare(asat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
|
215
|
|
- //assertTrue(Double.compare(asct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
|
216
|
|
- //assertTrue(Double.compare(aspt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
|
|
220
|
+ assertTrue(Float.compare(ascl.getPath().getLength(),bfacl.getPath().getLength())==0);
|
|
221
|
+ assertTrue(Double.compare(asat.getPath().getMinimumTravelTime(),bfaat.getPath().getMinimumTravelTime())==0);
|
|
222
|
+ assertTrue(Double.compare(asct.getPath().getMinimumTravelTime(),bfact.getPath().getMinimumTravelTime())==0);
|
|
223
|
+ assertTrue(Double.compare(aspt.getPath().getMinimumTravelTime(),bfapt.getPath().getMinimumTravelTime())==0);
|
217
|
224
|
}
|
218
|
225
|
|
219
|
226
|
//grand scénario avec oracle:
|
|
@@ -227,18 +234,33 @@ public class DijkstraAlgorithm_et_AStarTest{
|
227
|
234
|
PathReader pathread = new BinaryPathReader(new DataInputStream(new BufferedInputStream(new FileInputStream(pathaddr))));
|
228
|
235
|
|
229
|
236
|
Graph graphmap = graphread.read();
|
230
|
|
- Path pathmap = pathread.readPath(graphmap);//erreur ici mais pas mapmismatch, donc pourquoi? Path impossible? (hem) TODO: correct this
|
231
|
|
- //quel inspector prendre? Le path est en longueur mais voitures seulement ou tout autorisé?
|
232
|
|
-
|
233
|
|
- DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), alllen));
|
234
|
|
- AStarAlgorithm asmap = new AStarAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), alllen));
|
|
237
|
+ Path pathmap = pathread.readPath(graphmap);
|
235
|
238
|
|
|
239
|
+ //après test, il faut prendre carlen et non alllen en ArcInspector (sinon A* et Dijkstra sont plus courts)
|
|
240
|
+ DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), carlen));
|
|
241
|
+ AStarAlgorithm asmap = new AStarAlgorithm(new ShortestPathData(graphmap, pathmap.getOrigin(), pathmap.getDestination(), carlen));
|
236
|
242
|
assertTrue(dijkmap.run().getPath().getLength()==pathmap.getLength());
|
237
|
243
|
assertTrue(asmap.run().getPath().getLength()==pathmap.getLength());
|
238
|
244
|
//comparaison de la longueur
|
239
|
245
|
}
|
240
|
246
|
|
241
|
247
|
//TODO: sans oracle
|
242
|
|
- //idem mais au lieu du path trouver les ids de deux nodes valides?
|
243
|
|
-
|
|
248
|
+ @Test
|
|
249
|
+ public void testMapNoOracle() throws FileNotFoundException, IOException{//A FAIRE
|
|
250
|
+
|
|
251
|
+ /*String mapaddr = "/home/favary/Bureau/commetud/3eme Annee MIC/Graphes-et-Algorithmes/Maps/bretagne.mapgr";
|
|
252
|
+
|
|
253
|
+ GraphReader graphread = new BinaryGraphReader(new DataInputStream(new BufferedInputStream(new FileInputStream(mapaddr))));
|
|
254
|
+
|
|
255
|
+ Graph graphmap = graphread.read();
|
|
256
|
+ Node Origine = null;
|
|
257
|
+ Node Destination = null;//ces trois lignes à faire!
|
|
258
|
+ Path pathmap = Path.createShortestPathFromNodes(graphmap, null);
|
|
259
|
+
|
|
260
|
+ DijkstraAlgorithm dijkmap = new DijkstraAlgorithm(new ShortestPathData(graphmap, Origine, Destination, carlen));
|
|
261
|
+ AStarAlgorithm asmap = new AStarAlgorithm(new ShortestPathData(graphmap, Origine, Destination, carlen));
|
|
262
|
+ assertTrue(dijkmap.run().getPath().getLength()<=pathmap.getLength());
|
|
263
|
+ assertTrue(asmap.run().getPath().getLength()<=pathmap.getLength());
|
|
264
|
+ //comparaison de la longueur */
|
|
265
|
+ }
|
244
|
266
|
}
|