Skip to content

Commit 45df71f

Browse files
author
Teemu Peltonen
committed
Set effectiveWalk distance as coefficient instead of mm
1 parent d8abd1d commit 45df71f

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

Diff for: src/main/java/org/opentripplanner/routing/edgetype/StreetWithElevationEdge.java

+3-18
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class StreetWithElevationEdge extends StreetEdge {
3030

3131
private boolean flattened;
3232

33-
private int effectiveWalkLength_mm;
33+
private double effectiveWalkFactor = 1.0;
3434

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

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

4644
public StreetWithElevationEdge(StreetVertex v1, StreetVertex v2, LineString geometry,
@@ -68,7 +66,7 @@ public boolean setElevationProfile(PackedCoordinateSequence elev, boolean comput
6866
slopeWorkFactor = (float)costs.slopeWorkFactor;
6967
maxSlope = (float)costs.maxSlope;
7068
flattened = costs.flattened;
71-
effectiveWalkLength_mm = costs.effectiveWalkDistance_mm;
69+
effectiveWalkFactor = costs.effectiveWalkFactor;
7270

7371
bicycleSafetyFactor *= costs.lengthMultiplier;
7472
bicycleSafetyFactor += costs.slopeSafetyCost / getDistance();
@@ -106,20 +104,7 @@ public double getSlopeWorkCostEffectiveLength() {
106104
@Override
107105
public double getSlopeWalkSpeedEffectiveLength() {
108106
// Convert from fixed millimeters to double meters
109-
return effectiveWalkLength_mm / 1000d;
110-
}
111-
112-
@Override
113-
protected void calculateLengthFromGeometry () {
114-
double accumulatedMeters = 0;
115-
116-
LineString geom = getGeometry();
117-
118-
for (int i = 1; i < geom.getNumPoints(); i++) {
119-
accumulatedMeters += SphericalDistanceLibrary.distance(geom.getCoordinateN(i - 1), geom.getCoordinateN(i));
120-
}
121-
122-
effectiveWalkLength_mm = (int) (accumulatedMeters * 1000);
107+
return effectiveWalkFactor * getDistance();
123108
}
124109

125110
@Override

Diff for: src/main/java/org/opentripplanner/routing/util/ElevationUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static SlopeCosts getSlopeCosts(CoordinateSequence elev, boolean slopeLim
7272
double flatLength = lengths[1];
7373
if (flatLength < 1e-3) {
7474
log.error("Too small edge, returning neutral slope costs.");
75-
return new SlopeCosts(1.0, 1.0, 0.0, 0.0, 1.0, false, (int)(flatLength*1000d));
75+
return new SlopeCosts(1.0, 1.0, 0.0, 0.0, 1.0, false, 1.0);
7676
}
7777
double lengthMultiplier = trueLength / flatLength;
7878
for (int i = 0; i < coordinates.length - 1; ++i) {
@@ -117,7 +117,7 @@ public static SlopeCosts getSlopeCosts(CoordinateSequence elev, boolean slopeLim
117117
* length of the street edge which is the flat one.
118118
*/
119119
return new SlopeCosts(slopeSpeedEffectiveLength / flatLength, slopeWorkCost / flatLength,
120-
slopeSafetyCost, maxSlope, lengthMultiplier, flattened, (int)(effectiveWalkLength * 1000d));
120+
slopeSafetyCost, maxSlope, lengthMultiplier, flattened, effectiveWalkLength / flatLength);
121121
}
122122

123123
/** constants for slope computation */

Diff for: src/main/java/org/opentripplanner/routing/util/SlopeCosts.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public class SlopeCosts {
1414
* to calculate the increase of 19% to walk such a distance. We add that
1515
* percentage to the 'flat' distance and get 1190m.
1616
*/
17-
public final int effectiveWalkDistance_mm;
17+
public final double effectiveWalkFactor;
1818

1919
SlopeCosts(double slopeSpeedFactor, double slopeWorkFactor, double slopeSafetyCost,
20-
double maxSlope, double lengthMultiplier, boolean flattened, int effectiveWalkDistance_mm) {
20+
double maxSlope, double lengthMultiplier, boolean flattened, double effectiveWalkFactor) {
2121
this.slopeSpeedFactor = slopeSpeedFactor;
2222
this.slopeWorkFactor = slopeWorkFactor;
2323
this.slopeSafetyCost = slopeSafetyCost;
2424
this.maxSlope = maxSlope;
2525
this.lengthMultiplier = lengthMultiplier;
2626
this.flattened = flattened;
27-
this.effectiveWalkDistance_mm = effectiveWalkDistance_mm;
27+
this.effectiveWalkFactor = effectiveWalkFactor;
2828
}
2929
}

0 commit comments

Comments
 (0)