Search in sources :

Example 16 with GraphHopperOSM

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

the class GraphHopperIT method testCHAndTurnCostsWithFlexmode.

@Test
public void testCHAndTurnCostsWithFlexmode() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/moscow.osm.gz").setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car|turn_costs=true"));
    tmpHopper.getCHFactoryDecorator().setDisablingAllowed(true);
    tmpHopper.importOrLoad();
    // without turn costs (default for CH)
    GHRequest req = new GHRequest(55.813357, 37.5958585, 55.811042, 37.594689);
    GHResponse rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(400, rsp.getBest().getDistance(), 1);
    // with turn costs
    req.getHints().put(CH.DISABLE, "true");
    req.getHints().put(Routing.EDGE_BASED, "true");
    rsp = tmpHopper.route(req);
    assertEquals(1044, rsp.getBest().getDistance(), 1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 17 with GraphHopperOSM

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

the class GraphHopperIT method testPathDetails1216.

@Test
public void testPathDetails1216() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/north-bayreuth.osm.gz").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car"));
    tmpHopper.importOrLoad();
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.984352, 11.498802)).addPoint(new GHPoint(49.984565, 11.499188)).addPoint(new GHPoint(49.9847, 11.499612)).setVehicle("car").setWeighting("fastest").setPathDetails(Arrays.asList(Parameters.DETAILS.AVERAGE_SPEED));
    GHResponse rsp = tmpHopper.route(req);
    assertFalse(rsp.hasErrors());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 18 with GraphHopperOSM

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

the class GraphHopperIT method testFlexMode_631.

@Test
public void testFlexMode_631() {
    String tmpOsmFile = DIR + "/monaco.osm.gz";
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(tmpOsmFile).setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car"));
    tmpHopper.getCHFactoryDecorator().setEnabled(true).setWeightingsAsStrings(Arrays.asList("fastest")).setDisablingAllowed(true);
    tmpHopper.getLMFactoryDecorator().setEnabled(true).setWeightingsAsStrings(Arrays.asList("fastest")).setDisablingAllowed(true);
    tmpHopper.importOrLoad();
    GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setVehicle("car");
    req.getHints().put(Landmark.DISABLE, true);
    req.getHints().put(CH.DISABLE, false);
    GHResponse rsp = tmpHopper.route(req);
    long chSum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertTrue("Too many visited nodes for ch mode " + chSum, chSum < 60);
    PathWrapper bestPath = rsp.getBest();
    assertEquals(3587, bestPath.getDistance(), 1);
    assertEquals(89, bestPath.getPoints().getSize());
    // request flex mode
    req.setAlgorithm(Parameters.Algorithms.ASTAR_BI);
    req.getHints().put(Landmark.DISABLE, true);
    req.getHints().put(CH.DISABLE, true);
    rsp = tmpHopper.route(req);
    long flexSum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertTrue("Too few visited nodes for flex mode " + flexSum, flexSum > 60);
    bestPath = rsp.getBest();
    assertEquals(3587, bestPath.getDistance(), 1);
    assertEquals(89, bestPath.getPoints().getSize());
    // request hybrid mode
    req.getHints().put(Landmark.DISABLE, false);
    req.getHints().put(CH.DISABLE, true);
    rsp = tmpHopper.route(req);
    long hSum = rsp.getHints().getLong("visited_nodes.sum", 0);
    // hybrid is better than CH: 40 vs. 42 !
    assertTrue("Visited nodes for hybrid mode should be different to CH but " + hSum + "==" + chSum, hSum != chSum);
    assertTrue("Too many visited nodes for hybrid mode " + hSum + ">=" + flexSum, hSum < flexSum);
    bestPath = rsp.getBest();
    assertEquals(3587, bestPath.getDistance(), 1);
    assertEquals(89, bestPath.getPoints().getSize());
// combining hybrid & speed mode is currently not possible and should be avoided: #1082
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 19 with GraphHopperOSM

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

the class GraphHopperIT method testUTurn.

@Test
public void testUTurn() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/monaco.osm.gz").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car"));
    tmpHopper.importOrLoad();
    GHRequest request = new GHRequest();
    // Force initial U-Turn
    request.addPoint(new GHPoint(43.743887, 7.431151), 200);
    request.addPoint(new GHPoint(43.744007, 7.431076));
    request.setAlgorithm(ASTAR).setVehicle("car").setWeighting(weightCalcStr);
    GHResponse rsp = tmpHopper.route(request);
    assertFalse(rsp.hasErrors());
    PathWrapper arsp = rsp.getBest();
    InstructionList il = arsp.getInstructions();
    assertEquals(3, il.size());
    List<Map<String, Object>> resultJson = il.createJson();
    // Initial U-turn
    assertEquals("Make a U-turn onto Avenue Princesse Grace", resultJson.get(0).get("text"));
    // Second U-turn to get to destination
    assertEquals("Make a U-turn onto Avenue Princesse Grace", resultJson.get(1).get("text"));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GHPoint(com.graphhopper.util.shapes.GHPoint) Map(java.util.Map)

Example 20 with GraphHopperOSM

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

the class RoutingAlgorithmWithOSMIT method runAlgo.

/**
 * @param withCH if true also the CH and LM algorithms will be tested which need
 *               preparation and takes a bit longer
 */
Graph runAlgo(TestAlgoCollector testCollector, String osmFile, String graphFile, List<OneRun> forEveryAlgo, String importVehicles, boolean withCH, String vehicle, String weightStr, boolean is3D) {
    // for different weightings we need a different storage, otherwise we would need to remove the graph folder
    // everytime we come with a different weighting
    // graphFile += weightStr;
    AlgoHelperEntry algoEntry = null;
    OneRun tmpOneRun = null;
    try {
        Helper.removeDir(new File(graphFile));
        GraphHopper hopper = new GraphHopperOSM().setStoreOnFlush(true).setCHEnabled(false).setDataReaderFile(osmFile).setGraphHopperLocation(graphFile).setEncodingManager(new EncodingManager(importVehicles));
        if (osmFile.contains("krautsand"))
            hopper.setMinNetworkSize(0, 0);
        // avoid that path.getDistance is too different to path.getPoint.calcDistance
        hopper.setWayPointMaxDistance(0);
        // always enable landmarks
        hopper.getLMFactoryDecorator().addWeighting(weightStr).setEnabled(true).setDisablingAllowed(true);
        if (withCH)
            hopper.getCHFactoryDecorator().addWeighting(weightStr).setEnabled(true).setDisablingAllowed(true);
        if (is3D)
            hopper.setElevationProvider(new SRTMProvider(DIR));
        hopper.importOrLoad();
        TraversalMode tMode = importVehicles.contains("turn_costs=true") ? TraversalMode.EDGE_BASED_2DIR : TraversalMode.NODE_BASED;
        FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicle);
        HintsMap hints = new HintsMap().setWeighting(weightStr).setVehicle(vehicle);
        Collection<AlgoHelperEntry> prepares = RoutingAlgorithmIT.createAlgos(hopper, hints, tMode);
        EdgeFilter edgeFilter = new DefaultEdgeFilter(encoder);
        for (AlgoHelperEntry entry : prepares) {
            algoEntry = entry;
            LocationIndex idx = entry.getIdx();
            for (OneRun oneRun : forEveryAlgo) {
                tmpOneRun = oneRun;
                List<QueryResult> list = oneRun.getList(idx, edgeFilter);
                testCollector.assertDistance(algoEntry, list, oneRun);
            }
        }
        return hopper.getGraphHopperStorage();
    } catch (Exception ex) {
        if (algoEntry == null)
            throw new RuntimeException("cannot handle file " + osmFile + ", " + ex.getMessage(), ex);
        throw new RuntimeException("cannot handle " + algoEntry.toString() + ", for " + tmpOneRun + ", file " + osmFile + ", " + ex.getMessage(), ex);
    } finally {
    // Helper.removeDir(new File(graphFile));
    }
}
Also used : AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) OneRun(com.graphhopper.routing.util.TestAlgoCollector.OneRun) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GraphHopper(com.graphhopper.GraphHopper) LocationIndex(com.graphhopper.storage.index.LocationIndex) IOException(java.io.IOException) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider) QueryResult(com.graphhopper.storage.index.QueryResult) File(java.io.File)

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