|
@@ -2,36 +2,96 @@ package org.insa.graphs.algorithm.shortestpath;
|
2
|
2
|
|
3
|
3
|
import static org.junit.Assert.*;
|
4
|
4
|
|
|
5
|
+import org.insa.graphs.*;//voir si on ne peut pas importer launch autrement
|
|
6
|
+
|
|
7
|
+import java.io.BufferedInputStream;
|
|
8
|
+import java.io.DataInputStream;
|
|
9
|
+import java.io.FileInputStream;
|
5
|
10
|
import java.io.IOException;
|
6
|
11
|
import java.util.ArrayList;
|
7
|
12
|
import java.util.Arrays;
|
8
|
13
|
|
|
14
|
+import org.insa.graphs.algorithm.ArcInspector;
|
|
15
|
+import org.insa.graphs.algorithm.ArcInspectorFactory;
|
9
|
16
|
import org.insa.graphs.algorithm.shortestpath.*;
|
10
|
|
-import org.insa.graphs.model.Arc;
|
11
|
|
-import org.insa.graphs.model.Graph;
|
12
|
|
-import org.insa.graphs.model.Node;
|
13
|
|
-import org.insa.graphs.model.Path;
|
14
|
|
-import org.insa.graphs.model.RoadInformation;
|
|
17
|
+import org.insa.graphs.model.*;
|
15
|
18
|
import org.insa.graphs.model.RoadInformation.RoadType;
|
16
|
19
|
import org.junit.BeforeClass;
|
17
|
20
|
import org.junit.Test;
|
18
|
21
|
|
19
|
|
-public class DijkstraAlgorithmTest {
|
|
22
|
+public class DijkstraAlgorithmTest{
|
20
|
23
|
|
|
24
|
+ //copié sur PathTest.java
|
|
25
|
+ // Small graph use for tests
|
|
26
|
+ private static Graph graph;
|
|
27
|
+
|
|
28
|
+ // List of nodes
|
|
29
|
+ private static Node[] nodes;
|
|
30
|
+
|
|
31
|
+ // List of arcs in the graph, a2b is the arc from node A (0) to B (1).
|
|
32
|
+ @SuppressWarnings("unused")
|
|
33
|
+ private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
|
|
34
|
+
|
|
35
|
+ // Some paths...
|
|
36
|
+ private static Path emptyPath, singleNodePath, shortPath, longPath, loopPath, longLoopPath,
|
|
37
|
+ invalidPath;
|
|
38
|
+
|
|
39
|
+ @BeforeClass
|
|
40
|
+ public static void initAll() throws IOException {
|
|
41
|
+
|
|
42
|
+ // 10 and 20 meters per seconds
|
|
43
|
+ RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, true, 36, ""),
|
|
44
|
+ speed20 = new RoadInformation(RoadType.MOTORWAY, null, true, 72, "");
|
|
45
|
+
|
|
46
|
+ // Create nodes
|
|
47
|
+ nodes = new Node[5];
|
|
48
|
+ for (int i = 0; i < nodes.length; ++i) {
|
|
49
|
+ nodes[i] = new Node(i, null);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ // Add arcs...
|
|
53
|
+ a2b = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null);
|
|
54
|
+ a2c = Node.linkNodes(nodes[0], nodes[2], 15, speed10, null);
|
|
55
|
+ a2e = Node.linkNodes(nodes[0], nodes[4], 15, speed20, null);
|
|
56
|
+ b2c = Node.linkNodes(nodes[1], nodes[2], 10, speed10, null);
|
|
57
|
+ c2d_1 = Node.linkNodes(nodes[2], nodes[3], 20, speed10, null);
|
|
58
|
+ c2d_2 = Node.linkNodes(nodes[2], nodes[3], 10, speed10, null);
|
|
59
|
+ c2d_3 = Node.linkNodes(nodes[2], nodes[3], 15, speed20, null);
|
|
60
|
+ d2a = Node.linkNodes(nodes[3], nodes[0], 15, speed10, null);
|
|
61
|
+ d2e = Node.linkNodes(nodes[3], nodes[4], 22.8f, speed20, null);
|
|
62
|
+ e2d = Node.linkNodes(nodes[4], nodes[0], 10, speed10, null);
|
|
63
|
+
|
|
64
|
+ graph = new Graph("ID", "", Arrays.asList(nodes), null);
|
|
65
|
+
|
|
66
|
+ emptyPath = new Path(graph, new ArrayList<Arc>());
|
|
67
|
+ singleNodePath = new Path(graph, nodes[1]);
|
|
68
|
+ shortPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1 }));
|
|
69
|
+ longPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2e }));
|
|
70
|
+ loopPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a }));
|
|
71
|
+ longLoopPath = new Path(graph,
|
|
72
|
+ Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
|
|
73
|
+ invalidPath = new Path(graph, Arrays.asList(new Arc[] { a2b, c2d_1, d2e }));
|
|
74
|
+
|
|
75
|
+ }
|
|
76
|
+ //---fin de la copie de PathTest.java
|
|
77
|
+
|
|
78
|
+ //regarder LAUNCH.JAVA pour ouvrir une map
|
|
79
|
+
|
21
|
80
|
private static DijkstraAlgorithm samenode, bikinsatime, bikinsalong, invalinsa;
|
22
|
81
|
private static BellmanFordAlgorithm Bsamenode, Bbikinsatime, Bbikinsalong, Binvalinsa;
|
23
|
82
|
private static ShortestPathData samenodespd, bikinsatimespd, bikinsalongspd, invalinsaspd;
|
24
|
83
|
|
25
|
|
- private static Graph graph;
|
26
|
|
- private static Node origine;//trouver ces nodes
|
27
|
|
- private static Node bikini;
|
28
|
|
- private static Node inaccessible;
|
29
|
|
- //en créer plus et avec des maps différentes
|
|
84
|
+ // (cf l.187 excel ggdoc) permet de savoir quels arcs autoriser
|
|
85
|
+ private ArcInspector inspecteuruno=ArcInspectorFactory.getAllFilters().get(0);// No filter (all arcs allowed)
|
|
86
|
+ private ArcInspector inspecteurtres=ArcInspectorFactory.getAllFilters().get(2);// Only road allowed for cars and time
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+ //créer plus et avec des maps différentes
|
30
|
90
|
//faire des test spécifiques pour longs trajets
|
31
|
91
|
|
32
|
|
- @BeforeClass
|
33
|
|
- public static void initAll() {
|
34
|
|
-
|
|
92
|
+ /*@BeforeClass
|
|
93
|
+ public static void initAllbis() {
|
|
94
|
+//en fait pas sûr que ça marche comme ça, voir avec Launch
|
35
|
95
|
samenodespd=new ShortestPathData(graph, null, null, null);
|
36
|
96
|
bikinsatimespd=new ShortestPathData(graph, null, null, null);
|
37
|
97
|
bikinsalongspd=new ShortestPathData(graph, null, null, null);
|
|
@@ -46,15 +106,23 @@ public class DijkstraAlgorithmTest {
|
46
|
106
|
Bbikinsatime= new BellmanFordAlgorithm(bikinsatimespd);
|
47
|
107
|
Bbikinsalong=new BellmanFordAlgorithm(bikinsalongspd);
|
48
|
108
|
Binvalinsa=new BellmanFordAlgorithm(invalinsaspd);
|
49
|
|
- }
|
|
109
|
+ }*/
|
50
|
110
|
|
51
|
|
- //test faits directement via la console et DijkstraAlgorithm.java:
|
52
|
|
- //(coûts croissants)
|
53
|
|
- //(nbr successeurs cohérents)
|
54
|
|
- //(tas valide)
|
|
111
|
+ //comment trouver les noeuds dans une map? Ne comparer que les grands chemins (qui font ouvrir la map) avec BF
|
|
112
|
+
|
|
113
|
+ /*(Test faits directement via la console et DijkstraAlgorithm.java, actuellement commentés:
|
|
114
|
+ -coûts croissants
|
|
115
|
+ -nbr successeurs cohérents
|
|
116
|
+ -tas valide.)*/
|
55
|
117
|
|
56
|
118
|
@Test
|
57
|
119
|
public void cheminValide() {
|
|
120
|
+ ShortestPathData data1=new ShortestPathData(null, null, null, inspecteuruno);
|
|
121
|
+ ShortestPathData data3=new ShortestPathData(null, null, null, inspecteurtres);
|
|
122
|
+ ShortestPathAlgorithm Dijkstra1=new DijkstraAlgorithm(data1);
|
|
123
|
+ ShortestPathAlgorithm Dijkstra3=new DijkstraAlgorithm(data3);
|
|
124
|
+ assertTrue(Dijkstra1.doRun().getPath().isValid());
|
|
125
|
+ assertTrue(Dijkstra3.doRun().getPath().isValid());
|
58
|
126
|
assertTrue(samenode.doRun().getPath().isValid());
|
59
|
127
|
assertTrue(bikinsatime.doRun().getPath().isValid());
|
60
|
128
|
assertTrue(bikinsalong.doRun().getPath().isValid());
|
|
@@ -63,22 +131,18 @@ public class DijkstraAlgorithmTest {
|
63
|
131
|
|
64
|
132
|
@Test
|
65
|
133
|
public void faisable() {
|
|
134
|
+ ShortestPathData data1=new ShortestPathData(null, null, null, inspecteuruno);
|
|
135
|
+ ShortestPathData data3=new ShortestPathData(null, null, null, inspecteurtres);
|
|
136
|
+ ShortestPathAlgorithm Dijkstra1=new DijkstraAlgorithm(data1);
|
|
137
|
+ ShortestPathAlgorithm Dijkstra3=new DijkstraAlgorithm(data3);
|
|
138
|
+ assertTrue(Dijkstra1.doRun().isFeasible());
|
|
139
|
+ assertTrue(Dijkstra3.doRun().isFeasible());
|
66
|
140
|
assertTrue(samenode.doRun().isFeasible());
|
67
|
141
|
assertTrue(bikinsatime.doRun().isFeasible());
|
68
|
142
|
assertTrue(bikinsalong.doRun().isFeasible());
|
69
|
143
|
assertFalse(invalinsa.doRun().isFeasible());
|
70
|
144
|
}
|
71
|
145
|
|
72
|
|
- //cout calculé par Dijkstra identique à celui calculé par Path (comparaison pas avec ==)
|
73
|
|
- //comment ça? Dijkstra ne renvoie pas le cout du path dans ShortestPathSolution, obligé d'utiliser getPath.getCout
|
74
|
|
- //sans doute à voir avec comment demander un cout en temps ou en longueur
|
75
|
|
- @Test
|
76
|
|
- public void sameasPath() {
|
77
|
|
- assertTrue(samenode.doRun().getPath().isValid());//à faire
|
78
|
|
- assertTrue(bikinsatime.doRun().getPath().isValid());
|
79
|
|
- assertTrue(bikinsalong.doRun().getPath().isValid());
|
80
|
|
- assertTrue(invalinsa.doRun().getPath().isValid());
|
81
|
|
- }
|
82
|
146
|
|
83
|
147
|
//résultat identique à Bellman-Ford (sur les petits scénarios)
|
84
|
148
|
@Test
|
|
@@ -89,7 +153,8 @@ public class DijkstraAlgorithmTest {
|
89
|
153
|
assertTrue(invalinsa.doRun().getPath().equals(Binvalinsa.doRun().getPath()));
|
90
|
154
|
}
|
91
|
155
|
|
92
|
|
- //tests applicables aussi pour des grands scénarios
|
|
156
|
+ //tests applicables aussi pour des grands scénarios:
|
|
157
|
+ //...
|
93
|
158
|
|
94
|
159
|
|
95
|
160
|
}
|