Search in sources :

Example 6 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testLoadOSMNoCH.

@Test
public void testLoadOSMNoCH() {
    GraphHopper gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
    gh.importOrLoad();
    assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
    GHResponse rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setEncodingManager(new EncodingManager("car"));
    assertTrue(gh.load(ghLoc));
    rsp = gh.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getBest().getPoints().getSize());
    gh.close();
    gh = new GraphHopperOSM().setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm).init(new CmdArgs().put("graph.flag_encoders", "car").put(Parameters.CH.PREPARE + "weightings", "no"));
    assertFalse(gh.getAlgorithmFactory(new HintsMap("fastest")) instanceof PrepareContractionHierarchies);
    gh.close();
}
Also used : CmdArgs(com.graphhopper.util.CmdArgs) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) GHRequest(com.graphhopper.GHRequest) GraphHopper(com.graphhopper.GraphHopper) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 7 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testFerry.

@Test
public void testFerry() {
    GraphHopper hopper = new GraphHopperFacade(file2) {

        @Override
        public void cleanUp() {
        }
    }.importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    int n40 = AbstractGraphStorageTester.getIdOf(graph, 54.0);
    int n50 = AbstractGraphStorageTester.getIdOf(graph, 55.0);
    assertEquals(GHUtility.asSet(n40), GHUtility.getNeighbors(carAllExplorer.setBaseNode(n50)));
    // no duration is given => slow speed only!
    int n80 = AbstractGraphStorageTester.getIdOf(graph, 54.1);
    EdgeIterator iter = carOutExplorer.setBaseNode(n80);
    iter.next();
    assertEquals(5, carEncoder.getSpeed(iter.getFlags()), 1e-1);
    // duration 01:10 is given => more precise speed calculation!
    // ~111km (from 54.0,10.1 to 55.0,10.2) in duration=70 minutes => 95km/h => / 1.4 => 71km/h
    iter = carOutExplorer.setBaseNode(n40);
    iter.next();
    assertEquals(70, carEncoder.getSpeed(iter.getFlags()), 1e-1);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 8 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testBarriersOnTowerNodes.

@Test
public void testBarriersOnTowerNodes() {
    GraphHopper hopper = new GraphHopperFacade(fileBarriers).setMinNetworkSize(0, 0).importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    assertEquals(8, graph.getNodes());
    int n60 = AbstractGraphStorageTester.getIdOf(graph, 56);
    int newId = 5;
    assertEquals(GHUtility.asSet(newId), GHUtility.getNeighbors(carOutExplorer.setBaseNode(n60)));
    EdgeIterator iter = carOutExplorer.setBaseNode(n60);
    assertTrue(iter.next());
    assertEquals(newId, iter.getAdjNode());
    assertFalse(iter.next());
    iter = carOutExplorer.setBaseNode(newId);
    assertTrue(iter.next());
    assertEquals(n60, iter.getAdjNode());
    assertFalse(iter.next());
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 9 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testRoadAttributes.

@Test
public void testRoadAttributes() {
    GraphHopper hopper = new GraphHopperFacade(fileRoadAttributes);
    DataFlagEncoder dataFlagEncoder = (new DataFlagEncoder()).setStoreHeight(true).setStoreWeight(true).setStoreWidth(true);
    hopper.setEncodingManager(new EncodingManager(Arrays.asList(dataFlagEncoder), 8));
    hopper.importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    DataFlagEncoder encoder = (DataFlagEncoder) hopper.getEncodingManager().getEncoder("generic");
    assertEquals(5, graph.getNodes());
    int na = AbstractGraphStorageTester.getIdOf(graph, 11.1, 50);
    int nb = AbstractGraphStorageTester.getIdOf(graph, 12, 51);
    int nc = AbstractGraphStorageTester.getIdOf(graph, 11.2, 52);
    int nd = AbstractGraphStorageTester.getIdOf(graph, 11.3, 51);
    int ne = AbstractGraphStorageTester.getIdOf(graph, 10, 51);
    EdgeIteratorState edge_ab = GHUtility.getEdge(graph, na, nb);
    EdgeIteratorState edge_ad = GHUtility.getEdge(graph, na, nd);
    EdgeIteratorState edge_ae = GHUtility.getEdge(graph, na, ne);
    EdgeIteratorState edge_bc = GHUtility.getEdge(graph, nb, nc);
    EdgeIteratorState edge_bd = GHUtility.getEdge(graph, nb, nd);
    EdgeIteratorState edge_cd = GHUtility.getEdge(graph, nc, nd);
    EdgeIteratorState edge_ce = GHUtility.getEdge(graph, nc, ne);
    EdgeIteratorState edge_de = GHUtility.getEdge(graph, nd, ne);
    assertEquals(4.0, encoder.getHeight(edge_ab), 1e-5);
    assertEquals(2.5, encoder.getWidth(edge_ab), 1e-5);
    assertEquals(4.4, encoder.getWeight(edge_ab), 1e-5);
    assertEquals(4.0, encoder.getHeight(edge_bc), 1e-5);
    assertEquals(2.5, encoder.getWidth(edge_bc), 1e-5);
    assertEquals(4.4, encoder.getWeight(edge_bc), 1e-5);
    assertEquals(4.4, encoder.getHeight(edge_ad), 1e-5);
    assertEquals(3.5, encoder.getWidth(edge_ad), 1e-5);
    assertEquals(17.5, encoder.getWeight(edge_ad), 1e-5);
    assertEquals(4.4, encoder.getHeight(edge_cd), 1e-5);
    assertEquals(3.5, encoder.getWidth(edge_cd), 1e-5);
    assertEquals(17.5, encoder.getWeight(edge_cd), 1e-5);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 10 with GraphHopper

use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.

the class OSMReaderTest method testMaxSpeed.

@Test
public void testMaxSpeed() {
    GraphHopper hopper = new GraphHopperFacade(file2) {

        @Override
        public void cleanUp() {
        }
    }.importOrLoad();
    Graph graph = hopper.getGraphHopperStorage();
    int n60 = AbstractGraphStorageTester.getIdOf(graph, 56.0);
    EdgeIterator iter = carOutExplorer.setBaseNode(n60);
    iter.next();
    assertEquals(35, carEncoder.getSpeed(iter.getFlags()), 1e-1);
}
Also used : GraphHopper(com.graphhopper.GraphHopper) GHPoint(com.graphhopper.util.shapes.GHPoint) 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