Search in sources :

Example 6 with EncodingManager

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

the class GraphHopperIT method testNorthBayreuthDestination.

@Test
public void testNorthBayreuthDestination() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/north-bayreuth.osm.gz").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car,generic", 8));
    tmpHopper.importOrLoad();
    GHRequest req = new GHRequest(49.985307, 11.50628, 49.985731, 11.507465).setVehicle("car").setWeighting("fastest");
    GHResponse rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(550, rsp.getBest().getDistance(), 1);
    req = new GHRequest(49.985307, 11.50628, 49.985731, 11.507465).setVehicle("generic").setWeighting("generic");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(550, rsp.getBest().getDistance(), 1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 7 with EncodingManager

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

the class GraphHopperIT method testNorthBayreuthBlockeEdges.

@Test
public void testNorthBayreuthBlockeEdges() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/north-bayreuth.osm.gz").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("generic", 8));
    tmpHopper.importOrLoad();
    GHRequest req = new GHRequest(49.985272, 11.506151, 49.986107, 11.507202).setVehicle("generic").setWeighting("generic");
    GHResponse rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(122, rsp.getBest().getDistance(), 1);
    // block point 49.985759,11.50687
    req.getHints().put(Routing.BLOCK_AREA, "49.985759,11.50687");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(365, rsp.getBest().getDistance(), 1);
    req = new GHRequest(49.975845, 11.522598, 50.026821, 11.497364).setVehicle("generic").setWeighting("generic");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(6684, rsp.getBest().getDistance(), 1);
    // block by area
    String someArea = "49.97986,11.472902,50.003946,11.534357";
    req.getHints().put(Routing.BLOCK_AREA, someArea);
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(12173, rsp.getBest().getDistance(), 1);
    // Add blocked point to above area, to increase detour        
    req.getHints().put(Routing.BLOCK_AREA, "50.017578,11.547527;" + someArea);
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(16674, rsp.getBest().getDistance(), 1);
    // block by edge IDs -> i.e. use small circular area
    req.getHints().put(Routing.BLOCK_AREA, "49.981599,11.517448,100");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(6879, rsp.getBest().getDistance(), 1);
    // block by edge IDs -> i.e. use small rectangular area
    req.getHints().put(Routing.BLOCK_AREA, "49.981875,11.515818,49.981088,11.519423");
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    assertEquals(6879, rsp.getBest().getDistance(), 1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 8 with EncodingManager

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

the class GraphHopperIT method testSRTMWithInstructions.

@Test
public void testSRTMWithInstructions() throws Exception {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(importVehicles));
    tmpHopper.setElevationProvider(new SRTMProvider().setCacheDir(new File(DIR)));
    tmpHopper.importOrLoad();
    GHResponse rsp = tmpHopper.route(new GHRequest(43.730729, 7.421288, 43.727697, 7.419199).setAlgorithm(ASTAR).setVehicle(vehicle).setWeighting(weightCalcStr));
    PathWrapper arsp = rsp.getBest();
    assertEquals(1626.8, arsp.getDistance(), .1);
    assertEquals(60, arsp.getPoints().getSize());
    assertTrue(arsp.getPoints().is3D());
    InstructionList il = arsp.getInstructions();
    assertEquals(10, il.size());
    assertTrue(il.get(0).getPoints().is3D());
    String str = arsp.getPoints().toString();
    assertEquals("(43.73068455771767,7.421283689825812,62.0), (43.73067957305937,7.421382123709815,66.0), " + "(43.73109792316924,7.421546222751131,45.0), (43.73129908884985,7.421589994913116,45.0), " + "(43.731327028527716,7.421414533736137,45.0), (43.73125047381037,7.421366291225693,45.0), " + "(43.73125457162979,7.421274090288746,52.0), " + "(43.73128213877862,7.421115579183003,52.0), (43.731362232521825,7.421145381506057,52.0), " + "(43.731371359483255,7.421123216028286,52.0), (43.731485725897976,7.42117332118392,52.0), " + "(43.731575132867135,7.420868778695214,52.0), (43.73160605277731,7.420824820268709,52.0), " + "(43.7316401391843,7.420850152243305,52.0), (43.731674039326776,7.421050014072285,52.0)", str.substring(0, 662));
    assertEquals("(43.727778875703635,7.418772930326453,11.0), (43.72768239068275,7.419007064826944,11.0), " + "(43.727680946587874,7.419198768422206,11.0)", str.substring(str.length() - 132));
    assertEquals(84, arsp.getAscend(), 1e-1);
    assertEquals(135, arsp.getDescend(), 1e-1);
    List<GPXEntry> list = arsp.getInstructions().createGPXList();
    assertEquals(60, list.size());
    final long lastEntryMillis = list.get(list.size() - 1).getTime();
    assertEquals(new GPXEntry(43.73068455771767, 7.421283689825812, 62.0, 0), list.get(0));
    assertEquals(new GPXEntry(43.727680946587874, 7.4191987684222065, 11.0, lastEntryMillis), list.get(list.size() - 1));
    assertEquals(62, il.createGPXList().get(0).getElevation(), 1e-2);
    assertEquals(66, il.createGPXList().get(1).getElevation(), 1e-2);
    assertEquals(52, il.createGPXList().get(10).getElevation(), 1e-2);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) SRTMProvider(com.graphhopper.reader.dem.SRTMProvider) File(java.io.File)

Example 9 with EncodingManager

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

the class GraphHopperIT method testTurnCostsOnOff.

@Test
public void testTurnCostsOnOff() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/moscow.osm.gz").setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car|turn_costs=true"));
    tmpHopper.importOrLoad();
    // with turn costs (default if none-CH and turn cost enabled)
    GHRequest req = new GHRequest(55.813357, 37.5958585, 55.811042, 37.594689);
    GHResponse rsp = tmpHopper.route(req);
    assertEquals(1044, rsp.getBest().getDistance(), 1);
    // without turn costs
    req.getHints().put(Routing.EDGE_BASED, "false");
    rsp = tmpHopper.route(req);
    assertEquals(400, rsp.getBest().getDistance(), 1);
    // with turn costs
    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 10 with EncodingManager

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

the class GraphHopperIT method testSRTMWithTunnelInterpolation.

@Test
public void testSRTMWithTunnelInterpolation() throws Exception {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(osmFile).setStoreOnFlush(true).setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(genericImportVehicles, 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();
    // Without interpolation: 356.5
    assertEquals(351.4, arsp.getDistance(), .1);
    PointList pointList = arsp.getPoints();
    assertEquals(6, pointList.getSize());
    assertTrue(pointList.is3D());
    assertEquals(17, pointList.getEle(0), .1);
    assertEquals(19.04, pointList.getEle(1), .1);
    assertEquals(21.67, pointList.getEle(2), .1);
    assertEquals(25.03, pointList.getEle(3), .1);
    assertEquals(28.65, pointList.getEle(4), .1);
    assertEquals(31.32, 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)

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