Search in sources :

Example 36 with GraphHopper

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);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 37 with GraphHopper

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);
    }
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) GraphHopper(com.graphhopper.GraphHopper) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) StopWatch(com.graphhopper.util.StopWatch) GZIPInputStream(java.util.zip.GZIPInputStream) Random(java.util.Random) PrinctonReader(com.graphhopper.reader.PrinctonReader) GraphBuilder(com.graphhopper.storage.GraphBuilder) Directory(com.graphhopper.storage.Directory) Test(org.junit.Test)

Aggregations

GraphHopper (com.graphhopper.GraphHopper)37 Test (org.junit.Test)31 GHPoint (com.graphhopper.util.shapes.GHPoint)17 IOException (java.io.IOException)7 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)6 GHRequest (com.graphhopper.GHRequest)4 GHResponse (com.graphhopper.GHResponse)4 File (java.io.File)4 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CmdArgs (com.graphhopper.util.CmdArgs)3 ReaderNode (com.graphhopper.reader.ReaderNode)2 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)2 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)2 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 QueryResult (com.graphhopper.storage.index.QueryResult)2