Search in sources :

Example 1 with OSMTurnRelation

use of com.graphhopper.reader.OSMTurnRelation in project graphhopper by graphhopper.

the class OSMTurnRelationTest method testAcceptsTurnRelation.

@Test
public void testAcceptsTurnRelation() {
    List<String> vehicleTypes = new ArrayList<>(Arrays.asList("motorcar", "motor_vehicle", "vehicle"));
    List<String> vehicleTypesExcept = new ArrayList<>();
    OSMTurnRelation osmTurnRelation = new OSMTurnRelation(1, 1, 1, OSMTurnRelation.Type.NOT);
    assertTrue(osmTurnRelation.isVehicleTypeConcernedByTurnRestriction(vehicleTypes));
    vehicleTypesExcept.add("bus");
    osmTurnRelation.setVehicleTypesExcept(vehicleTypesExcept);
    assertTrue(osmTurnRelation.isVehicleTypeConcernedByTurnRestriction(vehicleTypes));
    vehicleTypesExcept.clear();
    vehicleTypesExcept.add("vehicle");
    osmTurnRelation.setVehicleTypesExcept(vehicleTypesExcept);
    assertFalse(osmTurnRelation.isVehicleTypeConcernedByTurnRestriction(vehicleTypes));
    vehicleTypesExcept.clear();
    vehicleTypesExcept.add("motor_vehicle");
    vehicleTypesExcept.add("vehicle");
    osmTurnRelation.setVehicleTypesExcept(vehicleTypesExcept);
    assertFalse(osmTurnRelation.isVehicleTypeConcernedByTurnRestriction(vehicleTypes));
    vehicleTypesExcept.clear();
    osmTurnRelation.setVehicleTypeRestricted("bus");
    osmTurnRelation.setVehicleTypesExcept(vehicleTypesExcept);
    assertFalse(osmTurnRelation.isVehicleTypeConcernedByTurnRestriction(vehicleTypes));
    osmTurnRelation.setVehicleTypeRestricted("vehicle");
    assertTrue(osmTurnRelation.isVehicleTypeConcernedByTurnRestriction(vehicleTypes));
}
Also used : OSMTurnRelation(com.graphhopper.reader.OSMTurnRelation) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 2 with OSMTurnRelation

use of com.graphhopper.reader.OSMTurnRelation in project graphhopper by graphhopper.

the class OSMTurnRelationParserTest method testGetRestrictionAsEntries.

@Test
public void testGetRestrictionAsEntries() {
    CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
    final Map<Long, Integer> osmNodeToInternal = new HashMap<>();
    final Map<Integer, Long> internalToOSMEdge = new HashMap<>();
    osmNodeToInternal.put(3L, 3);
    // edge ids are only stored if they occurred before in an OSMRelation
    internalToOSMEdge.put(3, 3L);
    internalToOSMEdge.put(4, 4L);
    OSMTurnRelationParser parser = new OSMTurnRelationParser(encoder.toString(), 1, OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR));
    GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager.Builder().add(encoder).addTurnCostParser(parser).build()).create();
    EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage, encoder);
    TurnCostParser.ExternalInternalMap map = new TurnCostParser.ExternalInternalMap() {

        @Override
        public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
            return osmNodeToInternal.getOrDefault(nodeOsmId, -1);
        }

        @Override
        public long getOsmIdOfInternalEdge(int edgeId) {
            Long l = internalToOSMEdge.get(edgeId);
            if (l == null)
                return -1;
            return l;
        }
    };
    // TYPE == ONLY
    OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, OSMTurnRelation.Type.ONLY);
    parser.addRelationToTCStorage(instance, map, ghStorage);
    TurnCostStorage tcs = ghStorage.getTurnCostStorage();
    DecimalEncodedValue tce = parser.getTurnCostEnc();
    assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 6)));
    assertEquals(0, tcs.get(tce, 4, 3, 3), .1);
    assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 2)));
    // TYPE == NOT
    instance = new OSMTurnRelation(4, 3, 3, OSMTurnRelation.Type.NOT);
    parser.addRelationToTCStorage(instance, map, ghStorage);
    assertTrue(Double.isInfinite(tcs.get(tce, 4, 3, 3)));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) OSMTurnRelation(com.graphhopper.reader.OSMTurnRelation) HashMap(java.util.HashMap) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) GraphBuilder(com.graphhopper.storage.GraphBuilder) TurnCostStorage(com.graphhopper.storage.TurnCostStorage) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) EdgeBasedRoutingAlgorithmTest(com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest) Test(org.junit.jupiter.api.Test)

Aggregations

OSMTurnRelation (com.graphhopper.reader.OSMTurnRelation)2 Test (org.junit.jupiter.api.Test)2 EdgeBasedRoutingAlgorithmTest (com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest)1 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)1 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)1 EncodingManager (com.graphhopper.routing.util.EncodingManager)1 GraphBuilder (com.graphhopper.storage.GraphBuilder)1 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)1 TurnCostStorage (com.graphhopper.storage.TurnCostStorage)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1