Search in sources :

Example 26 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class DepthFirstSearchTest method testDFS2.

@Test
public void testDFS2() {
    DepthFirstSearch dfs = new DepthFirstSearch() {

        @Override
        public boolean goFurther(int v) {
            counter++;
            assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
            set.add(v);
            list.add(v);
            return super.goFurther(v);
        }
    };
    EncodingManager em = new EncodingManager("car");
    FlagEncoder fe = em.getEncoder("car");
    Graph g = new GraphBuilder(em).create();
    g.edge(1, 2, 1, false);
    g.edge(1, 4, 1, true);
    g.edge(1, 3, 1, false);
    g.edge(2, 3, 1, false);
    g.edge(4, 3, 1, true);
    dfs.start(g.createEdgeExplorer(new DefaultEdgeFilter(fe, false, true)), 1);
    assertTrue(counter > 0);
    assertEquals("[1, 2, 3, 4]", list.toString());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) Graph(com.graphhopper.storage.Graph) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) Test(org.junit.Test)

Example 27 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class ShapeFileReaderTest method initHopper.

private static GraphHopper initHopper(GraphHopper gh, String inputFile, String outDir) {
    URL resourceURL = ShapeFileReaderTest.class.getResource(inputFile);
    try {
        inputFile = new File(resourceURL.toURI()).getAbsolutePath();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // turn off geometry simplification so geometry should be the same
    // between pbf and shapefile readers
    gh.setWayPointMaxDistance(0);
    return gh.setStoreOnFlush(false).setDataReaderFile(inputFile).setGraphHopperLocation(new File(outDir).getAbsolutePath()).setEncodingManager(new EncodingManager(new CarFlagEncoder())).setCHEnabled(false).importOrLoad();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) File(java.io.File) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder)

Example 28 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class GraphHopperIT method beforeClass.

@BeforeClass
public static void beforeClass() {
    // make sure we are using fresh graphhopper files with correct vehicle
    Helper.removeDir(new File(graphFileFoot));
    hopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(graphFileFoot).setEncodingManager(new EncodingManager(importVehicles)).importOrLoad();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) File(java.io.File)

Example 29 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class GraphHopperIT method testMultipleVehiclesWithCH.

@Test
public void testMultipleVehiclesWithCH() {
    String tmpOsmFile = DIR + "/monaco.osm.gz";
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(tmpOsmFile).setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("bike,car")).importOrLoad();
    assertEquals("bike", tmpHopper.getDefaultVehicle().toString());
    checkMultiVehiclesWithCH(tmpHopper);
    tmpHopper.close();
    tmpHopper.clean();
    // new instance, try different order, resulting only in different default vehicle
    tmpHopper = new GraphHopperOSM().setOSMFile(tmpOsmFile).setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car,bike")).importOrLoad();
    assertEquals("car", tmpHopper.getDefaultVehicle().toString());
    checkMultiVehiclesWithCH(tmpHopper);
    tmpHopper.close();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 30 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager 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)

Aggregations

EncodingManager (com.graphhopper.routing.util.EncodingManager)33 Test (org.junit.Test)15 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)14 GraphBuilder (com.graphhopper.storage.GraphBuilder)10 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)8 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)7 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)6 Graph (com.graphhopper.storage.Graph)5 File (java.io.File)5 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)3 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)3 RAMDirectory (com.graphhopper.storage.RAMDirectory)3 Before (org.junit.Before)3 GraphHopper (com.graphhopper.GraphHopper)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)2 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)2 HintsMap (com.graphhopper.routing.util.HintsMap)2