|
@@ -0,0 +1,85 @@
|
|
1
|
+package org.insa.graphs.algorithm.shortestpath;
|
|
2
|
+
|
|
3
|
+import static org.junit.Assert.assertTrue;
|
|
4
|
+
|
|
5
|
+import org.junit.BeforeClass;
|
|
6
|
+import org.junit.Test;
|
|
7
|
+
|
|
8
|
+import java.io.BufferedInputStream;
|
|
9
|
+import java.io.DataInputStream;
|
|
10
|
+import java.io.FileInputStream;
|
|
11
|
+
|
|
12
|
+import org.insa.graphs.model.io.BinaryGraphReader;
|
|
13
|
+import org.insa.graphs.model.io.GraphReader;
|
|
14
|
+import org.insa.graphs.model.Graph;
|
|
15
|
+
|
|
16
|
+import org.insa.graphs.algorithm.shortestpath.DijkstraAlgorithm;
|
|
17
|
+import org.insa.graphs.algorithm.shortestpath.AStarAlgorithm;
|
|
18
|
+
|
|
19
|
+import org.insa.graphs.algorithm.ArcInspectorFactory;
|
|
20
|
+import org.insa.graphs.algorithm.shortestpath.ShortestPathData;
|
|
21
|
+
|
|
22
|
+public class PerformancesTest {
|
|
23
|
+
|
|
24
|
+ // Graph utilisé pour les tests
|
|
25
|
+ static Graph graph;
|
|
26
|
+
|
|
27
|
+ //Lecture du graphe
|
|
28
|
+ @BeforeClass
|
|
29
|
+ public static void initAll() throws Exception {
|
|
30
|
+ final String mapName = "/home/paulfaure/Documents/3A/JAVA/Cartes BE/haute-garonne/europe/france/haute-garonne.mapgr";
|
|
31
|
+
|
|
32
|
+ // Create a graph reader.
|
|
33
|
+ final GraphReader reader = new BinaryGraphReader(
|
|
34
|
+ new DataInputStream(new BufferedInputStream(new FileInputStream(mapName))));
|
|
35
|
+
|
|
36
|
+ // Read the graph.
|
|
37
|
+ PerformancesTest.graph = reader.read();
|
|
38
|
+
|
|
39
|
+ reader.close();
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ @Test
|
|
43
|
+ public void testDijkstraPlusRapidePetitTrajet() {
|
|
44
|
+ // On ne fait le test qu'avec un filtre sur les chemins autorisés
|
|
45
|
+ ShortestPathData data = new ShortestPathData(graph, graph.get(87500), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
|
46
|
+ ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
|
47
|
+ ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
|
48
|
+ ShortestPathSolution solutionAStar = aStar.run();
|
|
49
|
+ ShortestPathSolution solutionDijkstra = dijkstra.run();
|
|
50
|
+ assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) < 0);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ @Test
|
|
54
|
+ public void testDijkstraPlusRapideCheminNul() {
|
|
55
|
+ // On ne fait le test qu'avec un filtre sur les chemins autorisés
|
|
56
|
+ ShortestPathData data = new ShortestPathData(graph, graph.get(103867), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
|
57
|
+ ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
|
58
|
+ ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
|
59
|
+ ShortestPathSolution solutionAStar = aStar.run();
|
|
60
|
+ ShortestPathSolution solutionDijkstra = dijkstra.run();
|
|
61
|
+ assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) < 0);
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ @Test
|
|
65
|
+ public void testDijkstraPlusRapideCheminInexistant() {
|
|
66
|
+ // On ne fait le test qu'avec un filtre sur les chemins autorisés
|
|
67
|
+ ShortestPathData data = new ShortestPathData(graph, graph.get(135847), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
|
68
|
+ ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
|
69
|
+ ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
|
70
|
+ ShortestPathSolution solutionAStar = aStar.run();
|
|
71
|
+ ShortestPathSolution solutionDijkstra = dijkstra.run();
|
|
72
|
+ assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) < 0);
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ @Test
|
|
76
|
+ public void testAStarPlusRapideLongTrajet() {
|
|
77
|
+ // On ne fait le test qu'avec un filtre sur les chemins autorisés
|
|
78
|
+ ShortestPathData data = new ShortestPathData(graph, graph.get(12305), graph.get(103867), ArcInspectorFactory.getAllFilters().get(0));
|
|
79
|
+ ShortestPathAlgorithm dijkstra = new DijkstraAlgorithm(data);
|
|
80
|
+ ShortestPathAlgorithm aStar = new AStarAlgorithm(data);
|
|
81
|
+ ShortestPathSolution solutionAStar = aStar.run();
|
|
82
|
+ ShortestPathSolution solutionDijkstra = dijkstra.run();
|
|
83
|
+ assertTrue(solutionDijkstra.getSolvingTime().compareTo(solutionAStar.getSolvingTime()) > 0);
|
|
84
|
+ }
|
|
85
|
+}
|