Search in sources :

Example 16 with EncodingManager

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

the class GraphEdgeIdFinderTest method testParseStringHints.

@Test
public void testParseStringHints() {
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = new EncodingManager(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    // 0-1-2
    // | |
    // 3-4
    graph.edge(0, 1, 1, true);
    graph.edge(1, 2, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(0, 3, 1, true);
    graph.edge(1, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
    LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
    HintsMap hints = new HintsMap();
    hints.put(Parameters.Routing.BLOCK_AREA, "0.01,0.005,1");
    ConfigMap cMap = new ConfigMap();
    GraphEdgeIdFinder graphFinder = new GraphEdgeIdFinder(graph, locationIndex);
    ConfigMap result = graphFinder.parseStringHints(cMap, hints, new DefaultEdgeFilter(encoder));
    GHIntHashSet blockedEdges = new GHIntHashSet();
    blockedEdges.add(0);
    assertEquals(blockedEdges, result.get(BLOCKED_EDGES, new GHIntHashSet()));
    List<Shape> blockedShapes = new ArrayList<>();
    assertEquals(blockedShapes, result.get(BLOCKED_SHAPES, new ArrayList<>()));
    // big area converts into shapes
    hints.put(Parameters.Routing.BLOCK_AREA, "0,0,1000");
    result = graphFinder.parseStringHints(cMap, hints, new DefaultEdgeFilter(encoder));
    blockedEdges.clear();
    assertEquals(blockedEdges, result.get(BLOCKED_EDGES, new GHIntHashSet()));
    blockedShapes.add(new Circle(0, 0, 1000));
    assertEquals(blockedShapes, result.get(BLOCKED_SHAPES, new ArrayList<>()));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) Circle(com.graphhopper.util.shapes.Circle) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) Shape(com.graphhopper.util.shapes.Shape) ConfigMap(com.graphhopper.util.ConfigMap) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ArrayList(java.util.ArrayList) LocationIndex(com.graphhopper.storage.index.LocationIndex) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Example 17 with EncodingManager

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

the class GraphHopperStorageForDataFlagEncoderTest method testStorageProperties.

@Test
public void testStorageProperties() {
    graph = new GraphBuilder(encodingManager).setStore(true).setLocation(defaultGraphLoc).create();
    // 0-1
    ReaderWay way_0_1 = new ReaderWay(27l);
    way_0_1.setTag("highway", "primary");
    way_0_1.setTag("maxheight", "4.4");
    graph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    graph.getEdgeIteratorState(0, 1).setFlags(encoder.handleWayTags(way_0_1, 1, 0));
    // 1-2
    ReaderWay way_1_2 = new ReaderWay(28l);
    way_1_2.setTag("highway", "primary");
    way_1_2.setTag("maxweight", "45");
    graph.edge(1, 2, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.02, 0.02);
    graph.getEdgeIteratorState(1, 2).setFlags(encoder.handleWayTags(way_1_2, 1, 0));
    // 2-0
    ReaderWay way_2_0 = new ReaderWay(29l);
    way_2_0.setTag("highway", "primary");
    way_2_0.setTag("maxwidth", "5");
    graph.edge(2, 0, 1, true);
    graph.getEdgeIteratorState(2, 0).setFlags(encoder.handleWayTags(way_2_0, 1, 0));
    graph.flush();
    graph.close();
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false).importOrLoad();
    EncodingManager em = hopper.getEncodingManager();
    assertNotNull(em);
    assertEquals(1, em.fetchEdgeEncoders().size());
    FlagEncoder flagEncoder = em.fetchEdgeEncoders().get(0);
    assertTrue(flagEncoder instanceof DataFlagEncoder);
    DataFlagEncoder dataFlagEncoder = (DataFlagEncoder) flagEncoder;
    assertTrue(dataFlagEncoder.isStoreHeight());
    assertTrue(dataFlagEncoder.isStoreWeight());
    assertFalse(dataFlagEncoder.isStoreWidth());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.Test)

Example 18 with EncodingManager

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

the class GraphHopperIT method testSRTMWithoutTunnelInterpolation.

@Test
public void testSRTMWithoutTunnelInterpolation() throws Exception {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(importVehicles, 8));
    tmpHopper.setElevationProvider(new SRTMProvider().setCacheDir(new File(DIR)));
    tmpHopper.importOrLoad();
    GHResponse rsp = tmpHopper.route(new GHRequest(43.74056471749763, 7.4299266210693755, 43.73790260334179, 7.427984089259056).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
    PathWrapper arsp = rsp.getBest();
    assertEquals(356.5, arsp.getDistance(), .1);
    PointList pointList = arsp.getPoints();
    assertEquals(6, pointList.getSize());
    assertTrue(pointList.is3D());
    assertEquals(20.0, pointList.getEle(0), .1);
    assertEquals(23.0, pointList.getEle(1), .1);
    assertEquals(23.0, pointList.getEle(2), .1);
    assertEquals(41.0, pointList.getEle(3), .1);
    assertEquals(19.0, pointList.getEle(4), .1);
    assertEquals(26.5, pointList.getEle(5), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) File(java.io.File) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider)

Example 19 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager 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(92, 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(92, 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(92, bestPath.getPoints().getSize());
    // speed² mode is currently less optimal than CH so just check different nodes and correctness
    req.getHints().put(Landmark.DISABLE, false);
    req.getHints().put(CH.DISABLE, false);
    rsp = tmpHopper.route(req);
    long speed2Sum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertTrue("Visited nodes for speed² mode should be different but " + speed2Sum + " == " + chSum, speed2Sum != chSum);
    assertTrue("Visited nodes for speed² mode should be different but " + speed2Sum + " == " + flexSum, speed2Sum != flexSum);
    bestPath = rsp.getBest();
    assertEquals(3587, bestPath.getDistance(), 1);
    assertEquals(92, bestPath.getPoints().getSize());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 20 with EncodingManager

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

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