use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class OSMReaderTest method testMain.
@Test
public void testMain() {
GraphHopper hopper = new GraphHopperFacade(file1).importOrLoad();
GraphHopperStorage graph = hopper.getGraphHopperStorage();
assertNotNull(graph.getProperties().get("datareader.import.date"));
assertNotEquals("", graph.getProperties().get("datareader.import.date"));
assertEquals("2013-01-02T01:10:14Z", graph.getProperties().get("datareader.data.date"));
assertEquals(4, graph.getNodes());
int n20 = AbstractGraphStorageTester.getIdOf(graph, 52);
int n10 = AbstractGraphStorageTester.getIdOf(graph, 51.2492152);
int n30 = AbstractGraphStorageTester.getIdOf(graph, 51.2);
int n50 = AbstractGraphStorageTester.getIdOf(graph, 49);
assertEquals(GHUtility.asSet(n20), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n10)));
assertEquals(3, GHUtility.count(carOutExplorer.setBaseNode(n20)));
assertEquals(GHUtility.asSet(n20), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n30)));
EdgeIterator iter = carOutExplorer.setBaseNode(n20);
assertTrue(iter.next());
assertEquals("street 123, B 122", iter.getName());
assertEquals(n50, iter.getAdjNode());
AbstractGraphStorageTester.assertPList(Helper.createPointList(51.25, 9.43), iter.fetchWayGeometry(0));
assertTrue(iter.isForward(carEncoder));
assertTrue(iter.isBackward(carEncoder));
assertTrue(iter.next());
assertEquals("route 666", iter.getName());
assertEquals(n30, iter.getAdjNode());
assertEquals(93147, iter.getDistance(), 1);
assertTrue(iter.next());
assertEquals("route 666", iter.getName());
assertEquals(n10, iter.getAdjNode());
assertEquals(88643, iter.getDistance(), 1);
assertTrue(iter.isForward(carEncoder));
assertTrue(iter.isBackward(carEncoder));
assertFalse(iter.next());
// get third added location id=30
iter = carOutExplorer.setBaseNode(n30);
assertTrue(iter.next());
assertEquals("route 666", iter.getName());
assertEquals(n20, iter.getAdjNode());
assertEquals(93146.888, iter.getDistance(), 1);
NodeAccess na = graph.getNodeAccess();
assertEquals(9.4, na.getLongitude(findID(hopper.getLocationIndex(), 51.2, 9.4)), 1e-3);
assertEquals(10, na.getLongitude(findID(hopper.getLocationIndex(), 49, 10)), 1e-3);
assertEquals(51.249, na.getLatitude(findID(hopper.getLocationIndex(), 51.2492152, 9.4317166)), 1e-3);
// node 40 is on the way between 30 and 50 => 9.0
assertEquals(9, na.getLongitude(findID(hopper.getLocationIndex(), 51.25, 9.43)), 1e-3);
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class RoutingAlgorithmIT method testPerformance.
@Test
public void testPerformance() throws IOException {
int N = 10;
int noJvmWarming = N / 4;
Random rand = new Random(0);
final EncodingManager eManager = new EncodingManager("car");
final GraphHopperStorage graph = new GraphBuilder(eManager).create();
String bigFile = "10000EWD.txt.gz";
new PrinctonReader(graph).setStream(new GZIPInputStream(PrinctonReader.class.getResourceAsStream(bigFile))).read();
GraphHopper hopper = new GraphHopper() {
{
setCHEnabled(false);
setEncodingManager(eManager);
loadGraph(graph);
}
@Override
protected LocationIndex createLocationIndex(Directory dir) {
return new LocationIndexTree(graph, dir);
}
};
Collection<AlgoHelperEntry> prepares = createAlgos(hopper, new HintsMap().setWeighting("shortest").setVehicle("car"), TraversalMode.NODE_BASED);
for (AlgoHelperEntry entry : prepares) {
StopWatch sw = new StopWatch();
for (int i = 0; i < N; i++) {
int node1 = Math.abs(rand.nextInt(graph.getNodes()));
int node2 = Math.abs(rand.nextInt(graph.getNodes()));
RoutingAlgorithm d = entry.createRoutingFactory().createAlgo(graph, entry.getAlgorithmOptions());
if (i >= noJvmWarming)
sw.start();
Path p = d.calcPath(node1, node2);
// avoid jvm optimization => call p.distance
if (i >= noJvmWarming && p.getDistance() > -1)
sw.stop();
// System.out.println("#" + i + " " + name + ":" + sw.getSeconds() + " " + p.nodes());
}
float perRun = sw.stop().getSeconds() / ((float) (N - noJvmWarming));
System.out.println("# " + getClass().getSimpleName() + " " + entry + ":" + sw.stop().getSeconds() + ", per run:" + perRun);
assertTrue("speed to low!? " + perRun + " per run", perRun < 0.08);
}
}
Aggregations