Skip to content

Commit 77f439a

Browse files
author
Peter
committed
moved perf test in integrationtest class too
1 parent 434db1f commit 77f439a

File tree

3 files changed

+61
-51
lines changed

3 files changed

+61
-51
lines changed

core/nbactions.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</goals>
1919
<properties>
2020
<exec.classpathScope>runtime</exec.classpathScope>
21-
<exec.args>-Xms1000m -Xmx1000m -XX:PermSize=20m -XX:MaxPermSize=20m -classpath %classpath de.jetsli.graph.reader.OSMReader test=true debug=true dijkstra=true graph=graph-unterfranken.osm osm=/media/SAMSUNG/unterfranken.osm</exec.args>
21+
<exec.args>-Xms1000m -Xmx1000m -XX:PermSize=20m -XX:MaxPermSize=20m -classpath %classpath de.jetsli.graph.reader.OSMReader test=false debug=true dijkstra=true graph=graph-unterfranken.osm osm=/media/SAMSUNG/unterfranken.osm</exec.args>
2222
<exec.executable>java</exec.executable>
2323
</properties>
2424
</action>
@@ -30,7 +30,7 @@
3030
</goals>
3131
<properties>
3232
<exec.classpathScope>runtime</exec.classpathScope>
33-
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Xms1000m -Xmx1000m -XX:PermSize=20m -XX:MaxPermSize=20m -classpath %classpath de.jetsli.graph.reader.OSMReader test=true debug=true dijkstra=true graph=graph-unterfranken.osm osm=/media/SAMSUNG/unterfranken.osm</exec.args>
33+
<exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -Xms1000m -Xmx1000m -XX:PermSize=20m -XX:MaxPermSize=20m -classpath %classpath de.jetsli.graph.reader.OSMReader test=false debug=true dijkstra=true graph=graph-unterfranken.osm osm=/media/SAMSUNG/unterfranken.osm</exec.args>
3434
<jpda.listen>true</jpda.listen>
3535
<exec.executable>java</exec.executable>
3636
</properties>
@@ -42,7 +42,7 @@
4242
<goal>org.codehaus.mojo:exec-maven-plugin:1.1.1:exec</goal>
4343
</goals>
4444
<properties>
45-
<exec.args>${profiler.args} -Xms1000m -Xmx1000m -XX:PermSize=20m -XX:MaxPermSize=20m -classpath %classpath de.jetsli.graph.reader.OSMReader test=true debug=true dijkstra=true graph=graph-unterfranken.osm osm=/media/SAMSUNG/unterfranken.osm</exec.args>
45+
<exec.args>${profiler.args} -Xms1000m -Xmx1000m -XX:PermSize=20m -XX:MaxPermSize=20m -classpath %classpath de.jetsli.graph.reader.OSMReader test=false debug=true dijkstra=true graph=graph-unterfranken.osm osm=/media/SAMSUNG/unterfranken.osm</exec.args>
4646
<profiler.action>profile</profiler.action>
4747
<exec.executable>${profiler.java}</exec.executable>
4848
</properties>

core/src/main/java/de/jetsli/graph/reader/OSMReader.java

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import de.jetsli.graph.routing.AStar;
1919
import de.jetsli.graph.routing.DijkstraBidirection;
20+
import de.jetsli.graph.routing.DijkstraBidirectionRef;
21+
import de.jetsli.graph.routing.DijkstraSimple;
2022
import de.jetsli.graph.storage.Storage;
2123
import de.jetsli.graph.util.CalcDistance;
2224
import de.jetsli.graph.routing.Path;
@@ -69,14 +71,14 @@ public static void main(String[] strs) throws Exception {
6971
}
7072
};
7173
osm2Graph(osmReader, args);
74+
RoutingAlgorithmIntegrationTests tests = new RoutingAlgorithmIntegrationTests(osmReader.getGraph());
7275
if (args.getBool("test", false)) {
73-
new RoutingAlgorithmIntegrationTests(osmReader.getGraph()).start();
76+
tests.start();
7477
} else if (args.getBool("dijkstra", false)) {
75-
// TODO move dijkstra runner into test class too!
78+
String algo = args.get("algo", "dijkstra");
7679
//warmup
77-
osmReader.doDijkstra(50);
78-
79-
osmReader.doDijkstra(500);
80+
tests.runShortestPathPerf(50, algo);
81+
tests.runShortestPathPerf(500, algo);
8082
}
8183
}
8284
private int expectedLocs;
@@ -124,46 +126,6 @@ private int getMaxLocs() {
124126
return expectedLocs;
125127
}
126128

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-
167129
public OSMReader(String storageLocation, int size) {
168130
storage = createStorage(storageLocation, expectedLocs = size);
169131
logger.info("using " + storage.getClass().getSimpleName());
@@ -210,8 +172,7 @@ public void cleanUp() {
210172
int n = g.getNodes();
211173
logger.info("nodes " + n + ", subnetworks:" + subnetworks.size() + ", removed them => " + (prev - n) + " less nodes");
212174
}
213-
214-
175+
215176
public void flush() {
216177
storage.flush();
217178
}

core/src/main/java/de/jetsli/graph/reader/RoutingAlgorithmIntegrationTests.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@
2525
import de.jetsli.graph.storage.Location2IDIndex;
2626
import de.jetsli.graph.storage.Location2IDQuadtree;
2727
import de.jetsli.graph.util.CmdArgs;
28-
import de.jetsli.graph.util.EdgeIdIterator;
2928
import de.jetsli.graph.util.Helper;
29+
import de.jetsli.graph.util.StopWatch;
3030
import java.io.File;
3131
import java.util.ArrayList;
3232
import java.util.List;
33+
import java.util.Random;
34+
import org.slf4j.Logger;
35+
import org.slf4j.LoggerFactory;
3336

3437
/**
3538
* @author Peter Karich
@@ -177,4 +180,50 @@ void runAlgo(Collector testCollector, String osmFile, String graphFile, List<One
177180
Helper.deleteDir(new File(graphFile));
178181
}
179182
}
183+
private Logger logger = LoggerFactory.getLogger(getClass());
184+
185+
public void runShortestPathPerf(int runs, String algoStr) throws Exception {
186+
Location2IDIndex index = new Location2IDQuadtree(unterfrankenGraph).prepareIndex(20000);
187+
double minLat = 49.484186, minLon = 8.974228;
188+
double maxLat = 50.541363, maxLon = 10.880356;
189+
RoutingAlgorithm algo;
190+
191+
if ("dijkstraref".equalsIgnoreCase(algoStr))
192+
algo = new DijkstraBidirectionRef(unterfrankenGraph);
193+
else if ("dijkstrabi".equalsIgnoreCase(algoStr))
194+
algo = new DijkstraBidirection(unterfrankenGraph);
195+
else if ("dijkstra".equalsIgnoreCase(algoStr))
196+
algo = new DijkstraSimple(unterfrankenGraph);
197+
else
198+
algo = new AStar(unterfrankenGraph);
199+
200+
logger.info("running shortest path with " + algo.getClass().getSimpleName());
201+
Random rand = new Random(123);
202+
StopWatch sw = new StopWatch();
203+
for (int i = 0; i < runs; i++) {
204+
double fromLat = rand.nextDouble() * (maxLat - minLat) + minLat;
205+
double fromLon = rand.nextDouble() * (maxLon - minLon) + minLon;
206+
int from = index.findID(fromLat, fromLon);
207+
double toLat = rand.nextDouble() * (maxLat - minLat) + minLat;
208+
double toLon = rand.nextDouble() * (maxLon - minLon) + minLon;
209+
int to = index.findID(toLat, toLon);
210+
// logger.info(i + " " + sw + " from (" + from + ")" + fromLat + ", " + fromLon + " to (" + to + ")" + toLat + ", " + toLon);
211+
if (from == to) {
212+
logger.warn("skipping i " + i + " from==to " + from);
213+
continue;
214+
}
215+
216+
algo.clear();
217+
sw.start();
218+
Path p = algo.calcShortestPath(from, to);
219+
sw.stop();
220+
if (p == null) {
221+
logger.warn("no route found for i=" + i + " !?" + " graph-from " + from + ", graph-to " + to);
222+
continue;
223+
}
224+
if (i % 20 == 0)
225+
logger.info(i + " " + sw.getSeconds() / (i + 1) + " secs/run (distance:"
226+
+ p.distance() + ",length:" + p.locations() + ")");
227+
}
228+
}
180229
}

0 commit comments

Comments
 (0)