Search in sources :

Example 1 with SlopeCosts

use of org.opentripplanner.routing.util.SlopeCosts in project OpenTripPlanner by opentripplanner.

the class StreetWithElevationEdge method setElevationProfile.

public boolean setElevationProfile(PackedCoordinateSequence elev, boolean computed) {
    if (elev == null || elev.size() < 2) {
        return false;
    }
    if (super.isSlopeOverride() && !computed) {
        return false;
    }
    boolean slopeLimit = getPermission().allows(StreetTraversalPermission.CAR);
    SlopeCosts costs = ElevationUtils.getSlopeCosts(elev, slopeLimit);
    packedElevationProfile = CompactElevationProfile.compactElevationProfile(elev);
    slopeSpeedFactor = (float) costs.slopeSpeedFactor;
    slopeWorkFactor = (float) costs.slopeWorkFactor;
    maxSlope = (float) costs.maxSlope;
    flattened = costs.flattened;
    bicycleSafetyFactor *= costs.lengthMultiplier;
    bicycleSafetyFactor += costs.slopeSafetyCost / getDistance();
    return costs.flattened;
}
Also used : SlopeCosts(org.opentripplanner.routing.util.SlopeCosts)

Example 2 with SlopeCosts

use of org.opentripplanner.routing.util.SlopeCosts in project OpenTripPlanner by opentripplanner.

the class TestTriangle method testTriangle.

public void testTriangle() {
    Coordinate c1 = new Coordinate(-122.575033, 45.456773);
    Coordinate c2 = new Coordinate(-122.576668, 45.451426);
    StreetVertex v1 = new IntersectionVertex(null, "v1", c1.x, c1.y, (NonLocalizedString) null);
    StreetVertex v2 = new IntersectionVertex(null, "v2", c2.x, c2.y, (NonLocalizedString) null);
    GeometryFactory factory = new GeometryFactory();
    LineString geometry = factory.createLineString(new Coordinate[] { c1, c2 });
    double length = 650.0;
    StreetWithElevationEdge testStreet = new StreetWithElevationEdge(v1, v2, geometry, "Test Lane", length, StreetTraversalPermission.ALL, false);
    // a safe street
    testStreet.setBicycleSafetyFactor(0.74f);
    Coordinate[] profile = new Coordinate[] { // slope = 0.1
    new Coordinate(0, 0), new Coordinate(length / 2, length / 20.0), // slope = -0.1
    new Coordinate(length, 0) };
    PackedCoordinateSequence elev = new PackedCoordinateSequence.Double(profile);
    testStreet.setElevationProfile(elev, false);
    SlopeCosts costs = ElevationUtils.getSlopeCosts(elev, true);
    double trueLength = costs.lengthMultiplier * length;
    double slopeWorkLength = testStreet.getSlopeWorkCostEffectiveLength();
    double slopeSpeedLength = testStreet.getSlopeSpeedEffectiveLength();
    RoutingRequest options = new RoutingRequest(TraverseMode.BICYCLE);
    options.optimize = OptimizeType.TRIANGLE;
    options.bikeSpeed = 6.0;
    options.walkReluctance = 1;
    options.setTriangleSafetyFactor(0);
    options.setTriangleSlopeFactor(0);
    options.setTriangleTimeFactor(1);
    State startState = new State(v1, options);
    State result = testStreet.traverse(startState);
    double timeWeight = result.getWeight();
    double expectedTimeWeight = slopeSpeedLength / options.getSpeed(TraverseMode.BICYCLE);
    assertTrue(Math.abs(expectedTimeWeight - timeWeight) < 0.00001);
    options.setTriangleSafetyFactor(0);
    options.setTriangleSlopeFactor(1);
    options.setTriangleTimeFactor(0);
    startState = new State(v1, options);
    result = testStreet.traverse(startState);
    double slopeWeight = result.getWeight();
    double expectedSlopeWeight = slopeWorkLength / options.getSpeed(TraverseMode.BICYCLE);
    assertTrue(Math.abs(expectedSlopeWeight - slopeWeight) < 0.00001);
    assertTrue(length * 1.5 / options.getSpeed(TraverseMode.BICYCLE) < slopeWeight);
    assertTrue(length * 1.5 * 10 / options.getSpeed(TraverseMode.BICYCLE) > slopeWeight);
    options.setTriangleSafetyFactor(1);
    options.setTriangleSlopeFactor(0);
    options.setTriangleTimeFactor(0);
    startState = new State(v1, options);
    result = testStreet.traverse(startState);
    double safetyWeight = result.getWeight();
    double slopeSafety = costs.slopeSafetyCost;
    double expectedSafetyWeight = (trueLength * 0.74 + slopeSafety) / options.getSpeed(TraverseMode.BICYCLE);
    assertTrue(Math.abs(expectedSafetyWeight - safetyWeight) < 0.00001);
    final double ONE_THIRD = 1 / 3.0;
    options.setTriangleSafetyFactor(ONE_THIRD);
    options.setTriangleSlopeFactor(ONE_THIRD);
    options.setTriangleTimeFactor(ONE_THIRD);
    startState = new State(v1, options);
    result = testStreet.traverse(startState);
    double averageWeight = result.getWeight();
    assertTrue(Math.abs(safetyWeight * ONE_THIRD + slopeWeight * ONE_THIRD + timeWeight * ONE_THIRD - averageWeight) < 0.00000001);
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) SlopeCosts(org.opentripplanner.routing.util.SlopeCosts) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) State(org.opentripplanner.routing.core.State) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) PackedCoordinateSequence(org.opentripplanner.common.geometry.PackedCoordinateSequence)

Aggregations

SlopeCosts (org.opentripplanner.routing.util.SlopeCosts)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)1 LineString (com.vividsolutions.jts.geom.LineString)1 PackedCoordinateSequence (org.opentripplanner.common.geometry.PackedCoordinateSequence)1 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)1 State (org.opentripplanner.routing.core.State)1 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)1 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)1