Search in sources :

Example 11 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class Bike2WeightFlagEncoder method applyWayTags.

@Override
public void applyWayTags(ReaderWay way, EdgeIteratorState edge) {
    PointList pl = edge.fetchWayGeometry(FetchMode.ALL);
    if (!pl.is3D())
        throw new IllegalStateException(getName() + " requires elevation data to improve speed calculation based on it. Please enable it in config via e.g. graph.elevation.provider: srtm");
    IntsRef intsRef = edge.getFlags();
    if (way.hasTag("tunnel", "yes") || way.hasTag("bridge", "yes") || way.hasTag("highway", "steps"))
        // note: although tunnel can have a difference in elevation it is very unlikely that the elevation data is correct for a tunnel
        return;
    // Decrease the speed for ele increase (incline), and decrease the speed for ele decrease (decline). The speed-decrease
    // has to be bigger (compared to the speed-increase) for the same elevation difference to simulate losing energy and avoiding hills.
    // For the reverse speed this has to be the opposite but again keeping in mind that up+down difference.
    double incEleSum = 0, incDist2DSum = 0, decEleSum = 0, decDist2DSum = 0;
    // double prevLat = pl.getLat(0), prevLon = pl.getLon(0);
    double prevEle = pl.getEle(0);
    double fullDist2D = edge.getDistance();
    // for short edges an incline makes no sense and for 0 distances could lead to NaN values for speed, see #432
    if (fullDist2D < 2)
        return;
    double eleDelta = pl.getEle(pl.size() - 1) - prevEle;
    if (eleDelta > 0.1) {
        incEleSum = eleDelta;
        incDist2DSum = fullDist2D;
    } else if (eleDelta < -0.1) {
        decEleSum = -eleDelta;
        decDist2DSum = fullDist2D;
    }
    // Calculate slop via tan(asin(height/distance)) but for rather smallish angles where we can assume tan a=a and sin a=a.
    // Then calculate a factor which decreases or increases the speed.
    // Do this via a simple quadratic equation where y(0)=1 and y(0.3)=1/4 for incline and y(0.3)=2 for decline
    double fwdIncline = incDist2DSum > 1 ? incEleSum / incDist2DSum : 0;
    double fwdDecline = decDist2DSum > 1 ? decEleSum / decDist2DSum : 0;
    double restDist2D = fullDist2D - incDist2DSum - decDist2DSum;
    double maxSpeed = getHighwaySpeed("cycleway");
    if (accessEnc.getBool(false, intsRef)) {
        // use weighted mean so that longer incline influences speed more than shorter
        double speed = avgSpeedEnc.getDecimal(false, intsRef);
        double fwdFaster = 1 + 2 * keepIn(fwdDecline, 0, 0.2);
        fwdFaster = fwdFaster * fwdFaster;
        double fwdSlower = 1 - 5 * keepIn(fwdIncline, 0, 0.2);
        fwdSlower = fwdSlower * fwdSlower;
        speed = speed * (fwdSlower * incDist2DSum + fwdFaster * decDist2DSum + 1 * restDist2D) / fullDist2D;
        setSpeed(false, intsRef, keepIn(speed, PUSHING_SECTION_SPEED / 2.0, maxSpeed));
    }
    if (accessEnc.getBool(true, intsRef)) {
        double speedReverse = avgSpeedEnc.getDecimal(true, intsRef);
        double bwFaster = 1 + 2 * keepIn(fwdIncline, 0, 0.2);
        bwFaster = bwFaster * bwFaster;
        double bwSlower = 1 - 5 * keepIn(fwdDecline, 0, 0.2);
        bwSlower = bwSlower * bwSlower;
        speedReverse = speedReverse * (bwFaster * incDist2DSum + bwSlower * decDist2DSum + 1 * restDist2D) / fullDist2D;
        setSpeed(true, intsRef, keepIn(speedReverse, PUSHING_SECTION_SPEED / 2.0, maxSpeed));
    }
    edge.setFlags(intsRef);
}
Also used : PointList(com.graphhopper.util.PointList) IntsRef(com.graphhopper.storage.IntsRef)

Example 12 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class HikeFlagEncoder method applyWayTags.

@Override
public void applyWayTags(ReaderWay way, EdgeIteratorState edge) {
    PointList pl = edge.fetchWayGeometry(FetchMode.ALL);
    if (!pl.is3D())
        return;
    if (way.hasTag("tunnel", "yes") || way.hasTag("bridge", "yes") || way.hasTag("highway", "steps"))
        // note: although tunnel can have a difference in elevation it is unlikely that the elevation data is correct for a tunnel
        return;
    // Decrease the speed for ele increase (incline), and slightly decrease the speed for ele decrease (decline)
    double prevEle = pl.getEle(0);
    double fullDistance = edge.getDistance();
    // for short edges an incline makes no sense and for 0 distances could lead to NaN values for speed, see #432
    if (fullDistance < 2)
        return;
    double eleDelta = Math.abs(pl.getEle(pl.size() - 1) - prevEle);
    double slope = eleDelta / fullDistance;
    IntsRef edgeFlags = edge.getFlags();
    if ((accessEnc.getBool(false, edgeFlags) || accessEnc.getBool(true, edgeFlags)) && slope > 0.005) {
        // see #1679 => v_hor=4.5km/h for horizontal speed; v_vert=2*0.5km/h for vertical speed (assumption: elevation < edge distance/4.5)
        // s_3d/v=h/v_vert + s_2d/v_hor => v = s_3d / (h/v_vert + s_2d/v_hor) = sqrt(s²_2d + h²) / (h/v_vert + s_2d/v_hor)
        // slope=h/s_2d=~h/2_3d              = sqrt(1+slope²)/(slope+1/4.5) km/h
        // maximum slope is 0.37 (Ffordd Pen Llech)
        double newSpeed = Math.sqrt(1 + slope * slope) / (slope + 1 / 5.4);
        edge.set(avgSpeedEnc, Helper.keepIn(newSpeed, 1, 5));
    }
}
Also used : IntsRef(com.graphhopper.storage.IntsRef)

Example 13 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class AbstractBikeFlagEncoderTester method testRelation.

@Test
public void testRelation() {
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "track");
    way.setTag("bicycle", "yes");
    way.setTag("foot", "yes");
    way.setTag("motor_vehicle", "agricultural");
    way.setTag("surface", "gravel");
    way.setTag("tracktype", "grade3");
    ReaderRelation rel = new ReaderRelation(0);
    rel.setTag("type", "route");
    rel.setTag("network", "rcn");
    rel.setTag("route", "bicycle");
    ReaderRelation rel2 = new ReaderRelation(1);
    rel2.setTag("type", "route");
    rel2.setTag("network", "lcn");
    rel2.setTag("route", "bicycle");
    // two relation tags => we currently cannot store a list, so pick the lower ordinal 'regional'
    // Example https://www.openstreetmap.org/way/213492914 => two hike 84544, 2768803 and two bike relations 3162932, 5254650
    IntsRef relFlags = encodingManager.handleRelationTags(rel2, encodingManager.handleRelationTags(rel, encodingManager.createRelationFlags()));
    IntsRef edgeFlags = encodingManager.handleWayTags(way, relFlags);
    EnumEncodedValue<RouteNetwork> enc = encodingManager.getEnumEncodedValue(RouteNetwork.key("bike"), RouteNetwork.class);
    assertEquals(RouteNetwork.REGIONAL, enc.getEnum(false, edgeFlags));
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) ReaderRelation(com.graphhopper.reader.ReaderRelation) Test(org.junit.jupiter.api.Test)

Example 14 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class RoadsFlagEncoderTest method testSpeed.

@Test
public void testSpeed() {
    ReaderWay way = new ReaderWay(1);
    IntsRef flags = roadsEncoder.handleWayTags(encodingManager.createEdgeFlags(), way);
    assertTrue(roadsEncoder.getAverageSpeedEnc().getDecimal(false, flags) > 200);
}
Also used : ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Example 15 with IntsRef

use of com.graphhopper.storage.IntsRef in project graphhopper by graphhopper.

the class BikeFlagEncoderTest method testSpeedAndPriority.

@Test
public void testSpeedAndPriority() {
    IntsRef intsRef = encodingManager.createEdgeFlags();
    encoder.setSpeed(false, intsRef, 10);
    encoder.getAccessEnc().setBool(false, intsRef, true);
    encoder.getAccessEnc().setBool(true, intsRef, true);
    assertEquals(10, avgSpeedEnc.getDecimal(false, intsRef), 1e-1);
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "primary");
    assertEquals(18, encoder.getSpeed(way));
    assertPriority(AVOID.getValue(), way);
    way.setTag("scenic", "yes");
    assertEquals(18, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    // Pushing section: this is fine as we obey the law!
    way.clearTags();
    way.setTag("highway", "footway");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    // Use pushing section irrespective of the pavement
    way.setTag("surface", "paved");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    way.clearTags();
    way.setTag("highway", "path");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "secondary");
    way.setTag("bicycle", "dismount");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    assertPriority(AVOID.getValue(), way);
    way.clearTags();
    way.setTag("highway", "footway");
    way.setTag("bicycle", "yes");
    assertEquals(10, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.setTag("segregated", "no");
    assertEquals(10, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.setTag("segregated", "yes");
    assertEquals(18, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.clearTags();
    way.setTag("highway", "footway");
    way.setTag("surface", "paved");
    way.setTag("bicycle", "yes");
    assertEquals(10, encoder.getSpeed(way));
    way.setTag("surface", "cobblestone");
    assertEquals(8, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.setTag("segregated", "yes");
    way.setTag("surface", "paved");
    assertEquals(18, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.clearTags();
    way.setTag("highway", "platform");
    way.setTag("surface", "paved");
    way.setTag("bicycle", "yes");
    assertEquals(10, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.setTag("segregated", "yes");
    assertEquals(18, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.clearTags();
    way.setTag("highway", "cycleway");
    assertEquals(18, encoder.getSpeed(way));
    assertPriority(VERY_NICE.getValue(), way);
    int cyclewaySpeed = encoder.getSpeed(way);
    way.setTag("foot", "yes");
    way.setTag("segregated", "yes");
    assertPriority(VERY_NICE.getValue(), way);
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    way.setTag("segregated", "no");
    assertPriority(PREFER.getValue(), way);
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    // Make sure that "highway=cycleway" and "highway=path" with "bicycle=designated" give the same result
    way.clearTags();
    way.setTag("highway", "path");
    way.setTag("bicycle", "designated");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    // Assume foot=no for designated in absence of a foot tag
    assertPriority(VERY_NICE.getValue(), way);
    way.setTag("foot", "yes");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.setTag("foot", "no");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    assertPriority(VERY_NICE.getValue(), way);
    way.setTag("segregated", "yes");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    assertPriority(VERY_NICE.getValue(), way);
    way.setTag("segregated", "no");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    assertPriority(VERY_NICE.getValue(), way);
    way.setTag("bicycle", "yes");
    assertEquals(10, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.setTag("segregated", "yes");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    assertPriority(PREFER.getValue(), way);
    way.setTag("surface", "unpaved");
    assertEquals(14, encoder.getSpeed(way));
    way.setTag("surface", "paved");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "path");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    // use pushing section
    way.clearTags();
    way.setTag("highway", "path");
    way.setTag("surface", "paved");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    way.clearTags();
    way.setTag("highway", "path");
    way.setTag("surface", "ground");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    way.clearTags();
    way.setTag("highway", "platform");
    way.setTag("surface", "paved");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    way.clearTags();
    way.setTag("highway", "footway");
    way.setTag("surface", "paved");
    way.setTag("bicycle", "designated");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    assertPriority(VERY_NICE.getValue(), way);
    way.clearTags();
    way.setTag("highway", "platform");
    way.setTag("surface", "paved");
    way.setTag("bicycle", "designated");
    assertEquals(cyclewaySpeed, encoder.getSpeed(way));
    assertPriority(VERY_NICE.getValue(), way);
    way.clearTags();
    way.setTag("highway", "track");
    assertEquals(12, encoder.getSpeed(way));
    assertPriority(UNCHANGED.getValue(), way);
    way.setTag("tracktype", "grade1");
    assertEquals(18, encoder.getSpeed(way));
    assertPriority(UNCHANGED.getValue(), way);
    way.setTag("highway", "track");
    way.setTag("tracktype", "grade2");
    assertEquals(12, encoder.getSpeed(way));
    assertPriority(UNCHANGED.getValue(), way);
    // test speed for allowed get off the bike types
    way.setTag("highway", "track");
    way.setTag("bicycle", "yes");
    assertEquals(12, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "steps");
    assertEquals(2, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    way.clearTags();
    way.setTag("highway", "residential");
    way.setTag("bicycle", "use_sidepath");
    assertEquals(18, encoder.getSpeed(way));
    assertPriority(REACH_DESTINATION.getValue(), way);
    way.clearTags();
    way.setTag("highway", "steps");
    way.setTag("surface", "wood");
    assertEquals(PUSHING_SECTION_SPEED / 2, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    way.setTag("maxspeed", "20");
    assertEquals(PUSHING_SECTION_SPEED / 2, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    way.clearTags();
    way.setTag("highway", "track");
    way.setTag("surface", "paved");
    assertEquals(18, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "path");
    way.setTag("surface", "ground");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    assertPriority(SLIGHT_AVOID.getValue(), way);
    way.clearTags();
    way.setTag("highway", "track");
    way.setTag("bicycle", "yes");
    way.setTag("surface", "fine_gravel");
    assertEquals(18, encoder.getSpeed(way));
    way.setTag("surface", "unknown_surface");
    assertEquals(PUSHING_SECTION_SPEED, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "primary");
    way.setTag("surface", "fine_gravel");
    assertEquals(18, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "track");
    way.setTag("surface", "gravel");
    way.setTag("tracktype", "grade2");
    assertEquals(12, encoder.getSpeed(way));
    assertPriority(UNCHANGED.getValue(), way);
    way.clearTags();
    way.setTag("highway", "primary");
    way.setTag("surface", "paved");
    assertEquals(18, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "primary");
    assertEquals(18, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "residential");
    way.setTag("surface", "asphalt");
    assertEquals(18, encoder.getSpeed(way));
    way.clearTags();
    way.setTag("highway", "motorway");
    way.setTag("bicycle", "yes");
    assertEquals(18, encoder.getSpeed(way));
}
Also used : IntsRef(com.graphhopper.storage.IntsRef) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.jupiter.api.Test)

Aggregations

IntsRef (com.graphhopper.storage.IntsRef)108 Test (org.junit.jupiter.api.Test)96 ReaderWay (com.graphhopper.reader.ReaderWay)67 ReaderRelation (com.graphhopper.reader.ReaderRelation)7 GraphBuilder (com.graphhopper.storage.GraphBuilder)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)5 Graph (com.graphhopper.storage.Graph)5 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)4 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)3 NodeAccess (com.graphhopper.storage.NodeAccess)3 BooleanEncodedValue (com.graphhopper.routing.ev.BooleanEncodedValue)2 RoadEnvironment (com.graphhopper.routing.ev.RoadEnvironment)2 VirtualEdgeIteratorState (com.graphhopper.routing.querygraph.VirtualEdgeIteratorState)2 TransportationMode (com.graphhopper.routing.util.TransportationMode)2 CountryRule (com.graphhopper.routing.util.countryrules.CountryRule)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 PMap (com.graphhopper.util.PMap)2 PointList (com.graphhopper.util.PointList)2