Search in sources :

Example 1 with EncodingManager

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

the class GraphHopperIT method testRoundaboutInstructionsWithCH.

@Test
public void testRoundaboutInstructionsWithCH() {
    String tmpOsmFile = DIR + "/monaco.osm.gz";
    String tmpVehicle = "car";
    String tmpImportVehicles = "car,bike";
    String tmpWeightCalcStr = "fastest";
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(tmpOsmFile).setStoreOnFlush(true).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager(tmpImportVehicles)).importOrLoad();
    assertEquals(tmpVehicle, tmpHopper.getDefaultVehicle().toString());
    assertEquals(2, tmpHopper.getCHFactoryDecorator().getPreparations().size());
    GHResponse rsp = tmpHopper.route(new GHRequest(43.745084, 7.430513, 43.745247, 7.430347).setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
    PathWrapper arsp = rsp.getBest();
    assertEquals(2, ((RoundaboutInstruction) arsp.getInstructions().get(1)).getExitNumber());
    rsp = tmpHopper.route(new GHRequest(43.745968, 7.42907, 43.745832, 7.428614).setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
    arsp = rsp.getBest();
    assertEquals(2, ((RoundaboutInstruction) arsp.getInstructions().get(1)).getExitNumber());
    rsp = tmpHopper.route(new GHRequest(43.745948, 7.42914, 43.746173, 7.428834).setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
    arsp = rsp.getBest();
    assertEquals(1, ((RoundaboutInstruction) arsp.getInstructions().get(1)).getExitNumber());
    rsp = tmpHopper.route(new GHRequest(43.735817, 7.417096, 43.735666, 7.416587).setVehicle(tmpVehicle).setWeighting(tmpWeightCalcStr));
    arsp = rsp.getBest();
    assertEquals(2, ((RoundaboutInstruction) arsp.getInstructions().get(1)).getExitNumber());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM)

Example 2 with EncodingManager

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

the class GraphHopperIT method testPointHint.

@Test
public void testPointHint() {
    GraphHopper tmpHopper = new GraphHopperOSM().setOSMFile(DIR + "/Laufamholzstrasse.osm.xml").setCHEnabled(false).setGraphHopperLocation(tmpGraphFile).setEncodingManager(new EncodingManager("car"));
    tmpHopper.importOrLoad();
    GHRequest req = new GHRequest(49.46553, 11.154669, 49.465244, 11.152577).setVehicle("car").setWeighting("fastest");
    req.setPointHints(new ArrayList<>(Arrays.asList("Laufamholzstraße, 90482, Nürnberg, Deutschland", "")));
    GHResponse rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    GHPoint snappedPoint = rsp.getBest().getWaypoints().toGHPoint(0);
    assertEquals(49.465686, snappedPoint.getLat(), .000001);
    assertEquals(11.154605, snappedPoint.getLon(), .000001);
    req.setPointHints(new ArrayList<>(Arrays.asList("", "")));
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    snappedPoint = rsp.getBest().getWaypoints().toGHPoint(0);
    assertEquals(49.465502, snappedPoint.getLat(), .000001);
    assertEquals(11.154498, snappedPoint.getLon(), .000001);
    // Match to closest edge, since hint was not found
    req.setPointHints(new ArrayList<>(Arrays.asList("xy", "")));
    rsp = tmpHopper.route(req);
    assertFalse(rsp.getErrors().toString(), rsp.hasErrors());
    snappedPoint = rsp.getBest().getWaypoints().toGHPoint(0);
    assertEquals(49.465502, snappedPoint.getLat(), .000001);
    assertEquals(11.154498, snappedPoint.getLon(), .000001);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GHPoint(com.graphhopper.util.shapes.GHPoint)

Example 3 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 4 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 5 with EncodingManager

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

the class OSMTurnRelationTest method testGetRestrictionAsEntries.

@Test
public void testGetRestrictionAsEntries() {
    CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
    final Map<Long, Integer> osmNodeToInternal = new HashMap<Long, Integer>();
    final Map<Integer, Long> internalToOSMEdge = new HashMap<Integer, Long>();
    osmNodeToInternal.put(3L, 3);
    // edge ids are only stored if they occured before in an OSMRelation
    internalToOSMEdge.put(3, 3L);
    internalToOSMEdge.put(4, 4L);
    GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager(encoder)).create();
    EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage);
    OSMReader osmReader = new OSMReader(ghStorage) {

        @Override
        public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
            return osmNodeToInternal.get(nodeOsmId);
        }

        @Override
        public long getOsmIdOfInternalEdge(int edgeId) {
            Long l = internalToOSMEdge.get(edgeId);
            if (l == null)
                return -1;
            return l;
        }
    };
    EdgeExplorer edgeExplorer = ghStorage.createEdgeExplorer();
    // TYPE == ONLY
    OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, Type.ONLY);
    Collection<OSMTurnRelation.TurnCostTableEntry> result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
    assertEquals(2, result.size());
    Iterator<OSMTurnRelation.TurnCostTableEntry> iter = result.iterator();
    OSMTurnRelation.TurnCostTableEntry entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(6, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
    entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(2, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
    // TYPE == NOT
    instance = new OSMTurnRelation(4, 3, 3, Type.NOT);
    result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
    assertEquals(1, result.size());
    iter = result.iterator();
    entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(3, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HashMap(java.util.HashMap) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test) EdgeBasedRoutingAlgorithmTest(com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest)

Aggregations

EncodingManager (com.graphhopper.routing.util.EncodingManager)60 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)21 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)19 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)18 Test (org.junit.jupiter.api.Test)18 GraphBuilder (com.graphhopper.storage.GraphBuilder)17 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)15 Test (org.junit.Test)10 ReaderWay (com.graphhopper.reader.ReaderWay)9 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)9 Graph (com.graphhopper.storage.Graph)6 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)5 IntsRef (com.graphhopper.storage.IntsRef)5 GraphHopper (com.graphhopper.GraphHopper)4 RAMDirectory (com.graphhopper.storage.RAMDirectory)4 GHPoint (com.graphhopper.util.shapes.GHPoint)4 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)3 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)3 Weighting (com.graphhopper.routing.weighting.Weighting)3