Skip to content

Commit

Permalink
Fix bug causing temporary split edges to be of effective walking dist…
Browse files Browse the repository at this point in the history
…ance 0 (zero) by setting effectiveWalk distance as coefficient instead of mm.

(cherry picked from commit 1818955)
(cherry picked from commit d8abd1d)
(cherry picked from commit 45df71f)
  • Loading branch information
Teemu Peltonen authored and t2gran committed Dec 5, 2018
1 parent ba4a09e commit a0dfec3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
Expand Up @@ -15,6 +15,7 @@ the License, or (at your option) any later version.

import org.opentripplanner.common.geometry.CompactElevationProfile;
import org.opentripplanner.common.geometry.PackedCoordinateSequence;
import org.opentripplanner.common.geometry.SphericalDistanceLibrary;
import org.opentripplanner.routing.util.ElevationUtils;
import org.opentripplanner.routing.util.SlopeCosts;
import org.opentripplanner.routing.vertextype.StreetVertex;
Expand Down Expand Up @@ -42,7 +43,7 @@ public class StreetWithElevationEdge extends StreetEdge {

private boolean flattened;

private int effectiveWalkLength_mm;
private double effectiveWalkFactor = 1.0;

/**
* Remember to call the {@link #setElevationProfile(PackedCoordinateSequence, boolean)} to initiate elevation data.
Expand All @@ -51,8 +52,6 @@ public StreetWithElevationEdge(StreetVertex v1, StreetVertex v2, LineString geom
I18NString name, double length, StreetTraversalPermission permission, boolean back) {
super(v1, v2, geometry, name, length, permission, back);

// Initiate to "flat" distance, use #setElevationProfile() to set elevation adjusted value
this.effectiveWalkLength_mm = getLength_mm();
}

public StreetWithElevationEdge(StreetVertex v1, StreetVertex v2, LineString geometry,
Expand Down Expand Up @@ -80,7 +79,7 @@ public boolean setElevationProfile(PackedCoordinateSequence elev, boolean comput
slopeWorkFactor = (float)costs.slopeWorkFactor;
maxSlope = (float)costs.maxSlope;
flattened = costs.flattened;
effectiveWalkLength_mm = costs.effectiveWalkDistance_mm;
effectiveWalkFactor = costs.effectiveWalkFactor;

bicycleSafetyFactor *= costs.lengthMultiplier;
bicycleSafetyFactor += costs.slopeSafetyCost / getDistance();
Expand Down Expand Up @@ -117,8 +116,7 @@ public double getSlopeWorkCostEffectiveLength() {
*/
@Override
public double getSlopeWalkSpeedEffectiveLength() {
// Convert from fixed millimeters to double meters
return effectiveWalkLength_mm / 1000d;
return effectiveWalkFactor * getDistance();
}

@Override
Expand Down
Expand Up @@ -85,7 +85,7 @@ public static SlopeCosts getSlopeCosts(CoordinateSequence elev, boolean slopeLim
double flatLength = lengths[1];
if (flatLength < 1e-3) {
log.error("Too small edge, returning neutral slope costs.");
return new SlopeCosts(1.0, 1.0, 0.0, 0.0, 1.0, false, (int)(flatLength*1000d));
return new SlopeCosts(1.0, 1.0, 0.0, 0.0, 1.0, false, 1.0);
}
double lengthMultiplier = trueLength / flatLength;
for (int i = 0; i < coordinates.length - 1; ++i) {
Expand Down Expand Up @@ -130,7 +130,7 @@ public static SlopeCosts getSlopeCosts(CoordinateSequence elev, boolean slopeLim
* length of the street edge which is the flat one.
*/
return new SlopeCosts(slopeSpeedEffectiveLength / flatLength, slopeWorkCost / flatLength,
slopeSafetyCost, maxSlope, lengthMultiplier, flattened, (int)(effectiveWalkLength * 1000d));
slopeSafetyCost, maxSlope, lengthMultiplier, flattened, effectiveWalkLength / flatLength);
}

/** constants for slope computation */
Expand Down
Expand Up @@ -27,16 +27,16 @@ public class SlopeCosts {
* to calculate the increase of 19% to walk such a distance. We add that
* percentage to the 'flat' distance and get 1190m.
*/
public final int effectiveWalkDistance_mm;
public final double effectiveWalkFactor;

SlopeCosts(double slopeSpeedFactor, double slopeWorkFactor, double slopeSafetyCost,
double maxSlope, double lengthMultiplier, boolean flattened, int effectiveWalkDistance_mm) {
double maxSlope, double lengthMultiplier, boolean flattened, double effectiveWalkFactor) {
this.slopeSpeedFactor = slopeSpeedFactor;
this.slopeWorkFactor = slopeWorkFactor;
this.slopeSafetyCost = slopeSafetyCost;
this.maxSlope = maxSlope;
this.lengthMultiplier = lengthMultiplier;
this.flattened = flattened;
this.effectiveWalkDistance_mm = effectiveWalkDistance_mm;
this.effectiveWalkFactor = effectiveWalkFactor;
}
}

0 comments on commit a0dfec3

Please sign in to comment.