|
@@ -0,0 +1,224 @@
|
|
1
|
+import org.insa.graphs.model.*;
|
|
2
|
+import org.insa.graphs.algorithm.*;
|
|
3
|
+import org.insa.graphs.algorithm.shortestpath.*;
|
|
4
|
+import static org.junit.Assert.assertEquals;
|
|
5
|
+import static org.junit.Assert.assertFalse;
|
|
6
|
+import static org.junit.Assert.assertTrue;
|
|
7
|
+
|
|
8
|
+import java.io.BufferedInputStream;
|
|
9
|
+import java.io.DataInputStream;
|
|
10
|
+import java.io.FileInputStream;
|
|
11
|
+import java.io.IOException;
|
|
12
|
+import java.util.ArrayList;
|
|
13
|
+import java.util.Arrays;
|
|
14
|
+import java.util.Collection;
|
|
15
|
+import java.util.Collections;
|
|
16
|
+import org.insa.graphs.model.Arc;
|
|
17
|
+import org.insa.graphs.model.Graph;
|
|
18
|
+import org.insa.graphs.model.Node;
|
|
19
|
+import org.insa.graphs.model.Point;
|
|
20
|
+import org.insa.graphs.model.Path;
|
|
21
|
+import org.insa.graphs.model.RoadInformation;
|
|
22
|
+import org.insa.graphs.model.RoadInformation.RoadType;
|
|
23
|
+import org.insa.graphs.model.io.BinaryGraphReader;
|
|
24
|
+import org.insa.graphs.model.io.GraphReader;
|
|
25
|
+import org.junit.BeforeClass;
|
|
26
|
+import org.junit.Test;
|
|
27
|
+import org.junit.Assume;
|
|
28
|
+import org.junit.Before;
|
|
29
|
+import org.junit.Test;
|
|
30
|
+import org.junit.runner.RunWith;
|
|
31
|
+import org.junit.runners.Parameterized;
|
|
32
|
+import org.junit.runners.Parameterized.Parameter;
|
|
33
|
+import org.junit.runners.Parameterized.Parameters;
|
|
34
|
+
|
|
35
|
+@RunWith(Parameterized.class)
|
|
36
|
+public class OptiTest {
|
|
37
|
+ private static Graph graph1;
|
|
38
|
+ private static Graph graph2;
|
|
39
|
+ private static Graph graph3;
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+ @Parameters
|
|
44
|
+ public static Collection<ShortestPathData> data() {
|
|
45
|
+ //**************************************************************
|
|
46
|
+ //**************************************************************
|
|
47
|
+ //CREATION DU GRAPHE DE LA CARTE HAUTE-GARONNE
|
|
48
|
+ final String mapName1 = "C:\\Users\\nmouk\\Documents\\GIT\\MAPS\\haute-garonne\\europe\\france\\haute-garonne.mapgr" ;
|
|
49
|
+ try {
|
|
50
|
+ final FileInputStream F1= new FileInputStream(mapName1);
|
|
51
|
+ }
|
|
52
|
+ catch(Exception e) {System.out.println("Fichier non existant!");}
|
|
53
|
+ // Create a graph reader.
|
|
54
|
+ try {
|
|
55
|
+ final GraphReader reader = new BinaryGraphReader(
|
|
56
|
+ new DataInputStream(new BufferedInputStream(new FileInputStream(mapName1))));
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+ // Small graph use for tests
|
|
60
|
+ graph1 = reader.read();
|
|
61
|
+ }
|
|
62
|
+ catch(Exception e) {System.out.println("Fichier non lu!");}
|
|
63
|
+ //******************************************************************
|
|
64
|
+ //******************************************************************
|
|
65
|
+ //CREATION DU GRAPHE DE LA CARTE CARRE
|
|
66
|
+ final String mapName2 = "C:\\Users\\nmouk\\Documents\\GIT\\MAPS\\carre\\extras\\carre.mapgr" ;
|
|
67
|
+
|
|
68
|
+ try {
|
|
69
|
+ final FileInputStream F2= new FileInputStream(mapName2);
|
|
70
|
+ }
|
|
71
|
+ catch(Exception e) {System.out.println("Fichier non existant!");}
|
|
72
|
+ // Create a graph reader.
|
|
73
|
+ try {
|
|
74
|
+ final GraphReader reader = new BinaryGraphReader(
|
|
75
|
+ new DataInputStream(new BufferedInputStream(new FileInputStream(mapName2))));
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+ // Small graph use for tests
|
|
79
|
+ graph2 = reader.read();
|
|
80
|
+ }
|
|
81
|
+ catch(Exception e) {System.out.println("Fichier non lu!");}
|
|
82
|
+
|
|
83
|
+ //******************************************************************
|
|
84
|
+ //******************************************************************
|
|
85
|
+ //CREATION DU GRAPHE DE LA CARTE POLYNESIE FRANCAISE
|
|
86
|
+ final String mapName3 = "C:\\Users\\nmouk\\Documents\\GIT\\MAPS\\french-polynesia\\oceania\\french-polynesia.mapgr" ;
|
|
87
|
+
|
|
88
|
+ try {
|
|
89
|
+ final FileInputStream F3= new FileInputStream(mapName2);
|
|
90
|
+ }
|
|
91
|
+ catch(Exception e) {System.out.println("Fichier non existant!");}
|
|
92
|
+ // Create a graph reader.
|
|
93
|
+ try {
|
|
94
|
+ final GraphReader reader = new BinaryGraphReader(
|
|
95
|
+ new DataInputStream(new BufferedInputStream(new FileInputStream(mapName3))));
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+ // Small graph use for tests
|
|
99
|
+ graph3 = reader.read();
|
|
100
|
+ }
|
|
101
|
+ catch(Exception e) {System.out.println("Fichier non lu!");}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+ Collection<ShortestPathData> objects = new ArrayList<>();
|
|
106
|
+
|
|
107
|
+ //***************CARTE HAUTE-GARONNE****************************
|
|
108
|
+ //**************************************************************
|
|
109
|
+ //CHEMIN NUL AVEC 2 MODES DE DEPLACEMENTS
|
|
110
|
+ objects.add(new ShortestPathData(graph1, graph1.get(10991),graph1.get(10991),ArcInspectorFactory.getAllFilters().get(0)));
|
|
111
|
+ objects.add(new ShortestPathData(graph1, graph1.get(10991),graph1.get(10991),ArcInspectorFactory.getAllFilters().get(2)));
|
|
112
|
+ //CHEMIN AVEC 3 MODES DE DEPLACEMENTS
|
|
113
|
+ objects.add(new ShortestPathData(graph1, graph1.get(10991),graph1.get(10991),ArcInspectorFactory.getAllFilters().get(0)));
|
|
114
|
+ objects.add(new ShortestPathData(graph1, graph1.get(10991),graph1.get(10991),ArcInspectorFactory.getAllFilters().get(2)));
|
|
115
|
+ //***************CARTE CARRE************************************
|
|
116
|
+ //**************************************************************
|
|
117
|
+ //CHEMIN NUL AVEC 2 MODES DE DEPLACEMENTS
|
|
118
|
+ objects.add(new ShortestPathData(graph2, graph2.get(19),graph2.get(19),ArcInspectorFactory.getAllFilters().get(0)));
|
|
119
|
+ objects.add(new ShortestPathData(graph2, graph2.get(19),graph2.get(19),ArcInspectorFactory.getAllFilters().get(2)));
|
|
120
|
+ //CHEMIN AVEC 2 MODES DE DEPLACEMENTS
|
|
121
|
+ objects.add(new ShortestPathData(graph2, graph2.get(19),graph2.get(5),ArcInspectorFactory.getAllFilters().get(0)));
|
|
122
|
+ objects.add(new ShortestPathData(graph2, graph2.get(19),graph2.get(5),ArcInspectorFactory.getAllFilters().get(2)));
|
|
123
|
+ objects.add(new ShortestPathData(graph2, graph2.get(19),graph2.get(5),ArcInspectorFactory.getAllFilters().get(1)));
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+ //*************CARTE POLYNESIE FRANCAISE**********************
|
|
128
|
+ //************************************************************
|
|
129
|
+ //CHEMIN IMPOSSIBLE AVEC 2 MODES DE DEPLACEMENTS
|
|
130
|
+ objects.add(new ShortestPathData(graph3, graph3.get(8302),graph3.get(4904),ArcInspectorFactory.getAllFilters().get(0)));
|
|
131
|
+ objects.add(new ShortestPathData(graph3, graph3.get(8302),graph3.get(4904),ArcInspectorFactory.getAllFilters().get(2)));
|
|
132
|
+ return objects;
|
|
133
|
+ }
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+ @Parameter
|
|
137
|
+ public ShortestPathData parameter;
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+ @Test
|
|
141
|
+ public void testCheminNul()
|
|
142
|
+ { //Shortest path, all roads allowed
|
|
143
|
+ Assume.assumeTrue(parameter.getOrigin().getId()==parameter.getDestination().getId() && parameter.getGraph().getMapId() != graph3.getMapId());
|
|
144
|
+ ShortestPathAlgorithm Dijkstra= new DijkstraAlgorithm(parameter);
|
|
145
|
+ ShortestPathAlgorithm BF= new BellmanFordAlgorithm(parameter);
|
|
146
|
+ DijkstraAlgorithm Astar= new AStarAlgorithm(parameter);
|
|
147
|
+ assertEquals(Dijkstra.run().isFeasible(),BF.run().isFeasible());
|
|
148
|
+ assertEquals(Astar.run().isFeasible(),BF.run().isFeasible());
|
|
149
|
+ }
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+ @Test
|
|
153
|
+ public void testCheminCourt()
|
|
154
|
+ {
|
|
155
|
+ Assume.assumeTrue(parameter.getOrigin().getId()!=parameter.getDestination().getId() && parameter.getGraph().getMapId() != graph3.getMapId());
|
|
156
|
+ ShortestPathAlgorithm Dijkstra= new DijkstraAlgorithm(parameter);
|
|
157
|
+ ShortestPathAlgorithm BF= new BellmanFordAlgorithm(parameter);
|
|
158
|
+ DijkstraAlgorithm Astar= new AStarAlgorithm(parameter);
|
|
159
|
+ assertEquals(Dijkstra.run().getPath().getLength(), BF.run().getPath().getLength(),0.01);
|
|
160
|
+ assertEquals(Astar.run().getPath().getLength(),BF.run().getPath().getLength(),0.01);
|
|
161
|
+ assertEquals(Dijkstra.run().getPath().getMinimumTravelTime(), BF.run().getPath().getMinimumTravelTime(),0.01);
|
|
162
|
+ assertEquals(Astar.run().getPath().getMinimumTravelTime(),BF.run().getPath().getMinimumTravelTime(),0.01);
|
|
163
|
+
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ @Test
|
|
167
|
+ public void testCheminImpossible()
|
|
168
|
+ { //Shortest path, all roads allowed
|
|
169
|
+ Assume.assumeTrue(parameter.getGraph().getMapId() == graph3.getMapId());
|
|
170
|
+ ShortestPathAlgorithm Dijkstra= new DijkstraAlgorithm(parameter);
|
|
171
|
+ ShortestPathAlgorithm BF= new BellmanFordAlgorithm(parameter);
|
|
172
|
+ DijkstraAlgorithm Astar= new AStarAlgorithm(parameter);
|
|
173
|
+ assertEquals(Dijkstra.run().isFeasible(),BF.run().isFeasible());
|
|
174
|
+ assertEquals(Astar.run().isFeasible(),BF.run().isFeasible());
|
|
175
|
+ }
|
|
176
|
+
|
|
177
|
+ /*
|
|
178
|
+ @Test
|
|
179
|
+ public void testCheminLong()
|
|
180
|
+ {
|
|
181
|
+ ShortestPathData data1=new ShortestPathData(graph, longPath.getOrigin(),longPath.getDestination(),ArcInspectorFactory.getAllFilters().get(0));
|
|
182
|
+ ShortestPathAlgorithm Dijkstra= new DijkstraAlgorithm(data1);
|
|
183
|
+ ShortestPathAlgorithm BF= new BellmanFordAlgorithm(data1);
|
|
184
|
+ DijkstraAlgorithm Astar= new AStarAlgorithm(data1);
|
|
185
|
+ assertEquals(Dijkstra.run().toString(),BF.run().toString());
|
|
186
|
+ assertEquals(Astar.run().toString(),BF.run().toString());
|
|
187
|
+ }
|
|
188
|
+
|
|
189
|
+ @Test
|
|
190
|
+ public void testgrandeBoucle()
|
|
191
|
+ {
|
|
192
|
+ ShortestPathData data1=new ShortestPathData(graph, loopPath.getOrigin(),loopPath.getDestination(),ArcInspectorFactory.getAllFilters().get(0));
|
|
193
|
+ ShortestPathAlgorithm Dijkstra= new DijkstraAlgorithm(data1);
|
|
194
|
+ ShortestPathAlgorithm BF= new BellmanFordAlgorithm(data1);
|
|
195
|
+ DijkstraAlgorithm Astar= new AStarAlgorithm(data1);
|
|
196
|
+ assertEquals(Dijkstra.run().toString(),BF.run().toString());
|
|
197
|
+ assertEquals(Astar.run().toString(),BF.run().toString());
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ @Test
|
|
201
|
+ public void testBoucle()
|
|
202
|
+ {
|
|
203
|
+ ShortestPathData data1=new ShortestPathData(graph, longLoopPath.getOrigin(),longLoopPath.getDestination(),ArcInspectorFactory.getAllFilters().get(0));
|
|
204
|
+ ShortestPathAlgorithm Dijkstra= new DijkstraAlgorithm(data1);
|
|
205
|
+ ShortestPathAlgorithm BF= new BellmanFordAlgorithm(data1);
|
|
206
|
+ DijkstraAlgorithm Astar= new AStarAlgorithm(data1);
|
|
207
|
+ assertEquals(Dijkstra.run().toString(),BF.run().toString());
|
|
208
|
+ assertEquals(Astar.run().toString(),BF.run().toString());
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ @Test
|
|
212
|
+ public void Testinvalide()
|
|
213
|
+ {
|
|
214
|
+ ShortestPathData data1=new ShortestPathData(graph, nodes[0],nodes[5],ArcInspectorFactory.getAllFilters().get(0));
|
|
215
|
+ ShortestPathAlgorithm Dijkstra= new DijkstraAlgorithm(data1);
|
|
216
|
+ ShortestPathAlgorithm BF= new BellmanFordAlgorithm(data1);
|
|
217
|
+ DijkstraAlgorithm Astar= new AStarAlgorithm(data1);
|
|
218
|
+ assertEquals(Dijkstra.run().toString(),BF.run().toString());
|
|
219
|
+ assertEquals(Astar.run().toString(),BF.run().toString());
|
|
220
|
+ }
|
|
221
|
+
|
|
222
|
+ */
|
|
223
|
+
|
|
224
|
+}
|