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));
}
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)));
}
Aggregations