|
17 | 17 |
|
18 | 18 | import de.jetsli.graph.routing.AStar;
|
19 | 19 | import de.jetsli.graph.routing.DijkstraBidirection;
|
| 20 | +import de.jetsli.graph.routing.DijkstraBidirectionRef; |
| 21 | +import de.jetsli.graph.routing.DijkstraSimple; |
20 | 22 | import de.jetsli.graph.storage.Storage;
|
21 | 23 | import de.jetsli.graph.util.CalcDistance;
|
22 | 24 | import de.jetsli.graph.routing.Path;
|
@@ -69,14 +71,14 @@ public static void main(String[] strs) throws Exception {
|
69 | 71 | }
|
70 | 72 | };
|
71 | 73 | osm2Graph(osmReader, args);
|
| 74 | + RoutingAlgorithmIntegrationTests tests = new RoutingAlgorithmIntegrationTests(osmReader.getGraph()); |
72 | 75 | if (args.getBool("test", false)) {
|
73 |
| - new RoutingAlgorithmIntegrationTests(osmReader.getGraph()).start(); |
| 76 | + tests.start(); |
74 | 77 | } else if (args.getBool("dijkstra", false)) {
|
75 |
| - // TODO move dijkstra runner into test class too! |
| 78 | + String algo = args.get("algo", "dijkstra"); |
76 | 79 | //warmup
|
77 |
| - osmReader.doDijkstra(50); |
78 |
| - |
79 |
| - osmReader.doDijkstra(500); |
| 80 | + tests.runShortestPathPerf(50, algo); |
| 81 | + tests.runShortestPathPerf(500, algo); |
80 | 82 | }
|
81 | 83 | }
|
82 | 84 | private int expectedLocs;
|
@@ -124,46 +126,6 @@ private int getMaxLocs() {
|
124 | 126 | return expectedLocs;
|
125 | 127 | }
|
126 | 128 |
|
127 |
| - public void doDijkstra(int runs) throws Exception { |
128 |
| - Graph g = storage.getGraph(); |
129 |
| - Location2IDIndex index = new Location2IDQuadtree(g).prepareIndex(20000); |
130 |
| - double minLat = 49.484186, minLon = 8.974228; |
131 |
| - double maxLat = 50.541363, maxLon = 10.880356; |
132 |
| -// RoutingAlgorithm algo = new DijkstraBidirectionRef(g); |
133 |
| -// RoutingAlgorithm algo = new DijkstraBidirection(g); |
134 |
| -// RoutingAlgorithm algo = new DijkstraSimple(g); |
135 |
| - RoutingAlgorithm algo = new AStar(g); |
136 |
| - |
137 |
| - logger.info("running dijkstra with " + algo.getClass().getSimpleName()); |
138 |
| - Random rand = new Random(123); |
139 |
| - StopWatch sw = new StopWatch(); |
140 |
| - for (int i = 0; i < runs; i++) { |
141 |
| - double fromLat = rand.nextDouble() * (maxLat - minLat) + minLat; |
142 |
| - double fromLon = rand.nextDouble() * (maxLon - minLon) + minLon; |
143 |
| - int from = index.findID(fromLat, fromLon); |
144 |
| - double toLat = rand.nextDouble() * (maxLat - minLat) + minLat; |
145 |
| - double toLon = rand.nextDouble() * (maxLon - minLon) + minLon; |
146 |
| - int to = index.findID(toLat, toLon); |
147 |
| -// logger.info(i + " " + sw + " from (" + from + ")" + fromLat + ", " + fromLon + " to (" + to + ")" + toLat + ", " + toLon); |
148 |
| - if (from == to) { |
149 |
| - logger.warn("skipping i " + i + " from==to " + from); |
150 |
| - continue; |
151 |
| - } |
152 |
| - |
153 |
| - algo.clear(); |
154 |
| - sw.start(); |
155 |
| - Path p = algo.calcShortestPath(from, to); |
156 |
| - sw.stop(); |
157 |
| - if (p == null) { |
158 |
| - logger.warn("no route found for i=" + i + " !?" + " graph-from " + from + ", graph-to " + to); |
159 |
| - continue; |
160 |
| - } |
161 |
| - if (i % 20 == 0) |
162 |
| - logger.info(i + " " + sw.getSeconds() / (i + 1) + " secs/run (distance:" |
163 |
| - + p.distance() + ",length:" + p.locations() + ")"); |
164 |
| - } |
165 |
| - } |
166 |
| - |
167 | 129 | public OSMReader(String storageLocation, int size) {
|
168 | 130 | storage = createStorage(storageLocation, expectedLocs = size);
|
169 | 131 | logger.info("using " + storage.getClass().getSimpleName());
|
@@ -210,8 +172,7 @@ public void cleanUp() {
|
210 | 172 | int n = g.getNodes();
|
211 | 173 | logger.info("nodes " + n + ", subnetworks:" + subnetworks.size() + ", removed them => " + (prev - n) + " less nodes");
|
212 | 174 | }
|
213 |
| - |
214 |
| - |
| 175 | + |
215 | 176 | public void flush() {
|
216 | 177 | storage.flush();
|
217 | 178 | }
|
|
0 commit comments