Search in sources :

Example 26 with GraphHopperOSM

use of com.graphhopper.reader.osm.GraphHopperOSM in project graphhopper by graphhopper.

the class GraphHopperIT method testAlternativeRoutesBikeAndCar.

@Test
public void testAlternativeRoutesBikeAndCar() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/north-bayreuth.osm.gz").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("bike, car"));
    tmpHopper.importOrLoad();
    GHRequest req = new GHRequest(50.028917, 11.496506, 49.985228, 11.600876).setAlgorithm(ALT_ROUTE).setVehicle("bike").setWeighting("fastest");
    req.getHints().put("alternative_route.max_paths", "3");
    GHResponse rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(3, rsp.getAll().size());
    // via ramsenthal
    assertEquals(2864, rsp.getAll().get(0).getTime() / 1000);
    // via unterwaiz
    assertEquals(3318, rsp.getAll().get(1).getTime() / 1000);
    // via eselslohe -> theta; BTW: here smaller time as 2nd alternative due to priority influences time order
    assertEquals(3094, rsp.getAll().get(2).getTime() / 1000);
    req = new GHRequest(50.023513, 11.548862, 49.969441, 11.537876).setAlgorithm(ALT_ROUTE).setVehicle("car").setWeighting("fastest");
    req.getHints().put("alternative_route.max_paths", "3");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(3, rsp.getAll().size());
    // directly via obergräfenthal
    assertEquals(870, rsp.getAll().get(0).getTime() / 1000);
    // via ramsenthal -> lerchenhof
    assertEquals(913, rsp.getAll().get(1).getTime() / 1000);
    // via neudrossenfeld
    assertEquals(958, rsp.getAll().get(2).getTime() / 1000);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Aggregations

GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)26 EncodingManager (com.graphhopper.routing.util.EncodingManager)18 GraphHopper (com.graphhopper.GraphHopper)7 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)4 GHPoint (com.graphhopper.util.shapes.GHPoint)4 File (java.io.File)4 IOException (java.io.IOException)3 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2 OneRun (com.graphhopper.routing.util.TestAlgoCollector.OneRun)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 Provides (com.google.inject.Provides)1 GHBitSet (com.graphhopper.coll.GHBitSet)1 GHJsonBuilder (com.graphhopper.json.GHJsonBuilder)1 JsonFeatureCollection (com.graphhopper.json.geo.JsonFeatureCollection)1 DataReader (com.graphhopper.reader.DataReader)1 LandmarkStorage (com.graphhopper.routing.lm.LandmarkStorage)1 PrepareLandmarks (com.graphhopper.routing.lm.PrepareLandmarks)1 SpatialRuleLookup (com.graphhopper.routing.util.spatialrules.SpatialRuleLookup)1 SpatialRuleLookupBuilder (com.graphhopper.routing.util.spatialrules.SpatialRuleLookupBuilder)1