use of com.graphhopper.routing.ev.DecimalEncodedValue in project graphhopper by graphhopper.
the class CarFlagEncoderTest method testMaxValue.
@Test
public void testMaxValue() {
CarFlagEncoder instance = new CarFlagEncoder(10, 0.5, 0);
EncodingManager em = EncodingManager.create(instance);
DecimalEncodedValue avSpeedEnc = em.getDecimalEncodedValue(EncodingManager.getKey(instance, "average_speed"));
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "motorway_link");
way.setTag("maxspeed", "60 mph");
IntsRef edgeFlags = instance.handleWayTags(em.createEdgeFlags(), way);
// double speed = AbstractFlagEncoder.parseSpeed("60 mph");
// => 96.56 * 0.9 => 86.9
assertEquals(86.9, avSpeedEnc.getDecimal(false, edgeFlags), 1e-1);
assertEquals(86.9, avSpeedEnc.getDecimal(true, edgeFlags), 1e-1);
// test that maxPossibleValue is not exceeded
way = new ReaderWay(2);
way.setTag("highway", "motorway_link");
way.setTag("maxspeed", "70 mph");
edgeFlags = instance.handleWayTags(em.createEdgeFlags(), way);
assertEquals(101.5, avSpeedEnc.getDecimal(false, edgeFlags), .1);
}
use of com.graphhopper.routing.ev.DecimalEncodedValue in project graphhopper by graphhopper.
the class LMIssueTest method lm_problem_to_node_of_fallback_approximator.
@ParameterizedTest
@EnumSource
public void lm_problem_to_node_of_fallback_approximator(Algo algo) {
// Before #1745 this test used to fail for LM, because when the distance was approximated for the start node 0
// the LMApproximator used the fall back approximator for which the to node was never set. This in turn meant
// that the to coordinates were zero and a way too large approximation was returned.
// Eventually the best path was not updated correctly because the spt entry of the fwd search already had a way
// too large weight.
// ---<---
// | |
// | 4 |
// |/ \ 0
// 1 | |
// \ | |
// 3 |
// 2 --<----
DecimalEncodedValue speedEnc = encoder.getAverageSpeedEnc();
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 49.405150, 9.709054);
na.setNode(1, 49.403705, 9.700517);
na.setNode(2, 49.400112, 9.700209);
na.setNode(3, 49.403009, 9.708364);
na.setNode(4, 49.409021, 9.703622);
// 30s
GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 3).setDistance(1000)).set(speedEnc, 120);
GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 2).setDistance(1000)).set(speedEnc, 120);
// 360s
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 3).setDistance(1000)).set(speedEnc, 10);
// 80s
GHUtility.setSpeed(60, true, false, encoder, graph.edge(0, 1).setDistance(1000)).set(speedEnc, 45);
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 4).setDistance(1000)).set(speedEnc, 45);
preProcessGraph();
int source = 0;
int target = 3;
Path refPath = new DijkstraBidirectionRef(graph, weighting, NODE_BASED).calcPath(source, target);
Path path = createAlgo(algo).calcPath(source, target);
assertEquals(refPath.getWeight(), path.getWeight(), 1.e-2);
assertEquals(refPath.getDistance(), path.getDistance(), 1.e-1);
assertEquals(refPath.getTime(), path.getTime(), 50);
assertEquals(refPath.calcNodes(), path.calcNodes());
}
use of com.graphhopper.routing.ev.DecimalEncodedValue 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.routing.ev.DecimalEncodedValue in project graphhopper by graphhopper.
the class OSMMaxSpeedParserTest method countryRule.
@Test
void countryRule() {
EncodingManager em = EncodingManager.create("car");
DecimalEncodedValue maxSpeedEnc = em.getDecimalEncodedValue(MaxSpeed.KEY);
Graph graph = new GraphBuilder(em).create();
FlagEncoder encoder = em.getEncoder("car");
EdgeIteratorState e1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
EdgeIteratorState e2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
OSMMaxSpeedParser parser = new OSMMaxSpeedParser(maxSpeedEnc);
IntsRef relFlags = em.createRelationFlags();
ReaderWay way = new ReaderWay(29L);
way.setTag("highway", "living_street");
way.setTag("country_rule", new CountryRule() {
@Override
public double getMaxSpeed(ReaderWay readerWay, TransportationMode transportationMode, double currentMaxSpeed) {
return 5;
}
});
parser.handleWayTags(e1.getFlags(), way, relFlags);
assertEquals(5, e1.get(maxSpeedEnc), .1);
// without a country_rule we get the default value
way.removeTag("country_rule");
parser.handleWayTags(e2.getFlags(), way, relFlags);
assertEquals(MaxSpeed.UNSET_SPEED, e2.get(maxSpeedEnc), .1);
}
use of com.graphhopper.routing.ev.DecimalEncodedValue in project graphhopper by graphhopper.
the class MotorcycleFlagEncoderTest method getBendiness.
private double getBendiness(EdgeIteratorState edge, double estimatedDistance) {
ReaderWay way = new ReaderWay(1);
way.setTag("highway", "primary");
way.setTag("estimated_distance", estimatedDistance);
assertTrue(encoder.getAccess(way).isWay());
IntsRef flags = encoder.handleWayTags(em.createEdgeFlags(), way);
edge.setFlags(flags);
encoder.applyWayTags(way, edge);
DecimalEncodedValue curvatureEnc = encoder.getDecimalEncodedValue(EncodingManager.getKey(encoder, "curvature"));
return edge.get(curvatureEnc);
}
Aggregations