use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class RacingBikeFlagEncoderTest method testPriority_avoidanceOfHighMaxSpeed.
@Test
public void testPriority_avoidanceOfHighMaxSpeed() {
// here we test the priority that would be calculated if the way was accessible (even when it is not)
// therefore we need a modified encoder that always yields access=WAY
BikeCommonFlagEncoder encoder = new RacingBikeFlagEncoder(new PMap("block_fords=true")) {
@Override
public EncodingManager.Access getAccess(ReaderWay way) {
return WAY;
}
};
EncodingManager encodingManager = EncodingManager.create(encoder);
DecimalEncodedValue avgSpeedEnc = encoder.getAverageSpeedEnc();
ReaderWay osmWay = new ReaderWay(1);
osmWay.setTag("highway", "tertiary");
osmWay.setTag("maxspeed", "50");
IntsRef intsRef = encodingManager.createEdgeFlags();
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, PREFER.getValue(), osmWay);
osmWay.setTag("maxspeed", "60");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, PREFER.getValue(), osmWay);
osmWay.setTag("maxspeed", "80");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, PREFER.getValue(), osmWay);
osmWay.setTag("maxspeed", "90");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, UNCHANGED.getValue(), osmWay);
osmWay.setTag("maxspeed", "120");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, UNCHANGED.getValue(), osmWay);
osmWay.setTag("highway", "motorway");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, AVOID.getValue(), osmWay);
osmWay.setTag("tunnel", "yes");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, AVOID_MORE.getValue(), osmWay);
osmWay.clearTags();
osmWay.setTag("highway", "motorway");
osmWay.setTag("tunnel", "yes");
osmWay.setTag("maxspeed", "80");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, AVOID_MORE.getValue(), osmWay);
osmWay.clearTags();
osmWay.setTag("highway", "motorway");
osmWay.setTag("tunnel", "yes");
osmWay.setTag("maxspeed", "120");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, AVOID_MORE.getValue(), osmWay);
osmWay.clearTags();
osmWay.setTag("highway", "notdefined");
osmWay.setTag("tunnel", "yes");
osmWay.setTag("maxspeed", "120");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, AVOID_MORE.getValue(), osmWay);
osmWay.clearTags();
osmWay.setTag("highway", "notdefined");
osmWay.setTag("maxspeed", "50");
encoder.setSpeed(false, intsRef, encoder.applyMaxSpeed(osmWay, 20));
assertEquals(20, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
assertPriority(encodingManager, UNCHANGED.getValue(), osmWay);
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class SpatialRuleLookupHelper method buildAndInjectSpatialRuleIntoGH.
public static void buildAndInjectSpatialRuleIntoGH(GraphHopper graphHopper, CmdArgs args) {
String spatialRuleLocation = args.get("spatial_rules.location", "");
if (!spatialRuleLocation.isEmpty()) {
try {
final BBox maxBounds = BBox.parseBBoxString(args.get("spatial_rules.max_bbox", "-180, 180, -90, 90"));
final InputStreamReader reader = new InputStreamReader(new FileInputStream(spatialRuleLocation), UTF_CS);
final SpatialRuleLookup index = SpatialRuleLookupBuilder.buildIndex(new GHJsonFactory().create().fromJson(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, maxBounds);
logger.info("Set spatial rule lookup with " + index.size() + " rules");
final FlagEncoderFactory oldFEF = graphHopper.getFlagEncoderFactory();
graphHopper.setFlagEncoderFactory(new FlagEncoderFactory() {
@Override
public FlagEncoder createFlagEncoder(String name, PMap configuration) {
if (name.equals(GENERIC)) {
return new DataFlagEncoder(configuration).setSpatialRuleLookup(index);
}
return oldFEF.createFlagEncoder(name, configuration);
}
});
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class DataFlagEncoderTest method testSpatialId.
@Test
public void testSpatialId() {
final GermanySpatialRule germany = new GermanySpatialRule();
germany.setBorders(Collections.singletonList(new Polygon(new double[] { 0, 0, 1, 1 }, new double[] { 0, 1, 1, 0 })));
SpatialRuleLookup index = new SpatialRuleLookup() {
@Override
public SpatialRule lookupRule(double lat, double lon) {
for (Polygon polygon : germany.getBorders()) {
if (polygon.contains(lat, lon)) {
return germany;
}
}
return SpatialRule.EMPTY;
}
@Override
public SpatialRule lookupRule(GHPoint point) {
return lookupRule(point.lat, point.lon);
}
@Override
public int getSpatialId(SpatialRule rule) {
if (germany.equals(rule)) {
return 1;
} else {
return 0;
}
}
@Override
public int size() {
return 2;
}
@Override
public BBox getBounds() {
return new BBox(-180, 180, -90, 90);
}
};
DataFlagEncoder encoder = new DataFlagEncoder(new PMap());
encoder.setSpatialRuleLookup(index);
EncodingManager em = new EncodingManager(encoder);
ReaderWay way = new ReaderWay(27l);
way.setTag("highway", "track");
way.setTag("estimated_center", new GHPoint(0.005, 0.005));
ReaderWay way2 = new ReaderWay(28l);
way2.setTag("highway", "track");
way2.setTag("estimated_center", new GHPoint(-0.005, -0.005));
ReaderWay livingStreet = new ReaderWay(29l);
livingStreet.setTag("highway", "living_street");
livingStreet.setTag("estimated_center", new GHPoint(0.005, 0.005));
ReaderWay livingStreet2 = new ReaderWay(30l);
livingStreet2.setTag("highway", "living_street");
livingStreet2.setTag("estimated_center", new GHPoint(-0.005, -0.005));
Graph graph = new GraphBuilder(em).create();
EdgeIteratorState e1 = graph.edge(0, 1, 1, true);
EdgeIteratorState e2 = graph.edge(0, 2, 1, true);
EdgeIteratorState e3 = graph.edge(0, 3, 1, true);
EdgeIteratorState e4 = graph.edge(0, 4, 1, true);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, -0.01, -0.01);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.01, 0.01);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, -0.01, -0.01);
e1.setFlags(encoder.handleWayTags(way, 1, 0));
e2.setFlags(encoder.handleWayTags(way2, 1, 0));
e3.setFlags(encoder.handleWayTags(livingStreet, 1, 0));
e4.setFlags(encoder.handleWayTags(livingStreet2, 1, 0));
assertEquals(index.getSpatialId(new GermanySpatialRule()), encoder.getSpatialId(e1.getFlags()));
assertEquals(index.getSpatialId(SpatialRule.EMPTY), encoder.getSpatialId(e2.getFlags()));
assertEquals(AccessValue.EVENTUALLY_ACCESSIBLE, encoder.getAccessValue(e1.getFlags()));
assertEquals(AccessValue.ACCESSIBLE, encoder.getAccessValue(e2.getFlags()));
assertEquals(5, encoder.getMaxspeed(e3, -1, false), .1);
assertEquals(-1, encoder.getMaxspeed(e4, -1, false), .1);
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method createEncodingManager.
private static EncodingManager createEncodingManager(String flagEncodersStr) {
EncodingManager.Builder builder = new EncodingManager.Builder();
for (String encoderStr : flagEncodersStr.split(",")) {
encoderStr = encoderStr.trim();
FlagEncoder encoder = new DefaultFlagEncoderFactory().createFlagEncoder(encoderStr.split("\\|")[0], new PMap(encoderStr));
builder.add(encoder);
builder.add(Subnetwork.create(encoder.toString()));
}
return builder.build();
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class ShortFastestWeightingTest method testTooSmall.
@Test
public void testTooSmall() {
try {
new ShortFastestWeighting(encoder, new PMap("short_fastest.distance_factor=0|short_fastest.time_factor=0"), TurnCostProvider.NO_TURN_COST_PROVIDER);
fail();
} catch (Exception ex) {
}
}
Aggregations