Search in sources :

Example 6 with DecimalEncodedValue

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);
}
Also used : DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 7 with DecimalEncodedValue

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());
}
Also used : DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with DecimalEncodedValue

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);
}
Also used : DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) PMap(com.graphhopper.util.PMap) ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 9 with DecimalEncodedValue

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);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) TransportationMode(com.graphhopper.routing.util.TransportationMode) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) Graph(com.graphhopper.storage.Graph) CountryRule(com.graphhopper.routing.util.countryrules.CountryRule) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 10 with DecimalEncodedValue

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);
}
Also used : DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) ReaderWay(com.graphhopper.reader.ReaderWay)

Aggregations

DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)26 Test (org.junit.jupiter.api.Test)15 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)6 Snap (com.graphhopper.storage.index.Snap)6 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 ReaderWay (com.graphhopper.reader.ReaderWay)4 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 IntsRef (com.graphhopper.storage.IntsRef)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)3 DefaultTurnCostProvider (com.graphhopper.routing.weighting.DefaultTurnCostProvider)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 Graph (com.graphhopper.storage.Graph)3 TurnCostStorage (com.graphhopper.storage.TurnCostStorage)3 Path (com.graphhopper.routing.Path)2 RoutingAlgorithm (com.graphhopper.routing.RoutingAlgorithm)2 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)2 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2