Skip to content

Instantly share code, notes, and snippets.

@buma
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save buma/8e1a5c4c4954e2c36e59 to your computer and use it in GitHub Desktop.

Select an option

Save buma/8e1a5c4c4954e2c36e59 to your computer and use it in GitHub Desktop.
Diff of linking
diff --git a/otp-core/src/main/java/org/opentripplanner/routing/impl/CandidateEdge.java b/otp-core/src/main/java/org/opentripplanner/routing/impl/CandidateEdge.java
index 560208f..129fa38 100644
--- a/otp-core/src/main/java/org/opentripplanner/routing/impl/CandidateEdge.java
+++ b/otp-core/src/main/java/org/opentripplanner/routing/impl/CandidateEdge.java
@@ -137,7 +137,7 @@ public class CandidateEdge {
}
// Calculate the score last so it can use all other data.
- score = calcScore();
+ score = calcScore(mode);
}
/** Construct CandidateEdge based on a Coordinate. */
@@ -223,26 +223,40 @@ public class CandidateEdge {
}
/** Internal calculator for the score. Assumes that edge, platform and distance are initialized. */
- private double calcScore() {
+ private double calcScore(TraverseModeSet mode) {
double myScore = 0;
// why is this being scaled by 1/360th of the radius of the earth?
myScore = distance * SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M / 360.0;
myScore /= preference;
- if ((edge.getStreetClass() & platform) != 0) {
- // this a hack, but there's not really a better way to do it
- myScore /= PLATFORM_PREFERENCE;
- }
+
if (edge.getName().contains("sidewalk")) {
// this is a hack, but there's not really a better way to do it
myScore /= SIDEWALK_PREFERENCE;
}
- // apply strong preference to car edges and to platforms for the specified modes
- if (edge.getPermission().allows(StreetTraversalPermission.CAR)
- || (edge.getStreetClass() & platform) != 0) {
- // we're subtracting here because no matter how close we are to a
- // good non-car non-platform edge, we really want to avoid it in
- // case it's a Pedway or other weird and unlikely starting location.
- myScore -= CAR_PREFERENCE;
+
+ if (mode.isTransit()) {
+ if ((edge.getStreetClass() & platform) != 0) {
+ // this a hack, but there's not really a better way to do it
+ myScore /= PLATFORM_PREFERENCE;
+ //}
+ // apply strong preference to platforms for the specified modes
+ //if ((edge.getStreetClass() & platform) != 0) {
+ // we're subtracting here because no matter how close we are to a
+ // good non-car non-platform edge, we really want to avoid it in
+ // case it's a Pedway or other weird and unlikely starting location.
+ myScore -= CAR_PREFERENCE;
+ }
+ }
+
+ if (mode.getDriving()) {
+ // apply strong preference to car edges and to platforms for the specified modes
+ if (edge.getPermission().allows(StreetTraversalPermission.CAR)
+ || (edge.getStreetClass() & platform) != 0) {
+ // we're subtracting here because no matter how close we are to a
+ // good non-car non-platform edge, we really want to avoid it in
+ // case it's a Pedway or other weird and unlikely starting location.
+ myScore -= CAR_PREFERENCE;
+ }
}
// Consider the heading in the score if it is available.
diff --git a/otp-core/src/main/java/org/opentripplanner/routing/impl/CandidateEdgeBundle.java b/otp-core/src/main/java/org/opentripplanner/routing/impl/CandidateEdgeBundle.java
index 455ed72..0b7bf14 100644
--- a/otp-core/src/main/java/org/opentripplanner/routing/impl/CandidateEdgeBundle.java
+++ b/otp-core/src/main/java/org/opentripplanner/routing/impl/CandidateEdgeBundle.java
@@ -116,4 +116,14 @@ public class CandidateEdgeBundle extends ArrayList<CandidateEdge> {
}
return false;
}
+
+ public boolean allowsWalking() {
+ for (CandidateEdge ce : CandidateEdgeBundle.this) {
+ StreetEdge e = ce.getEdge();
+ if (e.getPermission().allows(StreetTraversalPermission.PEDESTRIAN)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
\ No newline at end of file
diff --git a/otp-core/src/main/java/org/opentripplanner/routing/impl/StreetVertexIndexServiceImpl.java b/otp-core/src/main/java/org/opentripplanner/routing/impl/StreetVertexIndexServiceImpl.java
index 77251cb..541d7ca 100644
--- a/otp-core/src/main/java/org/opentripplanner/routing/impl/StreetVertexIndexServiceImpl.java
+++ b/otp-core/src/main/java/org/opentripplanner/routing/impl/StreetVertexIndexServiceImpl.java
@@ -381,7 +381,7 @@ public class StreetVertexIndexServiceImpl implements StreetVertexIndexService {
if (best == null || bundle.best.score < best.best.score) {
if (possibleTransitLinksOnly) {
// assuming all platforms are tagged when they are not car streets... #1077
- if (!(bundle.allowsCars() || bundle.isPlatform()))
+ if (!(bundle.allowsWalking()|| bundle.isPlatform()))
continue;
}
best = bundle;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment