Skip to content

Instantly share code, notes, and snippets.

@buma
Created August 23, 2016 16:51
Show Gist options
  • Save buma/4c4df5009b94464c9f0bcc2fe26ad9f1 to your computer and use it in GitHub Desktop.
Save buma/4c4df5009b94464c9f0bcc2fe26ad9f1 to your computer and use it in GitHub Desktop.
diff --git a/.gitignore b/.gitignore
index 9158691..eea1dfd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,8 @@ hs_err_pid*
cache
*.iml
src/main/resources/git.properties
+*.json
+*.geojson
+*.yaml
+*.py
+*.txt
diff --git a/src/main/java/com/conveyal/r5/point_to_point/PointToPointRouterServer.java b/src/main/java/com/conveyal/r5/point_to_point/PointToPointRouterServer.java
index 1cc63a8..11ca939 100644
--- a/src/main/java/com/conveyal/r5/point_to_point/PointToPointRouterServer.java
+++ b/src/main/java/com/conveyal/r5/point_to_point/PointToPointRouterServer.java
@@ -330,7 +330,7 @@ public class PointToPointRouterServer {
//TODO errorchecks
Boolean fullStateList = request.queryMap("full").booleanValue();
- RoutingVisitor routingVisitor = new RoutingVisitor(transportNetwork.streetLayer.edgeStore);
+ DebugRoutingVisitor debugRoutingVisitor = new DebugRoutingVisitor(transportNetwork.streetLayer.edgeStore);
if (fullStateList == null) {
fullStateList = false;
@@ -348,7 +348,7 @@ public class PointToPointRouterServer {
streetRouter.streetMode = streetMode;
// TODO use target pruning instead of a distance limit
- streetRouter.distanceLimitMeters = 100_000;
+ streetRouter.timeLimitSeconds = 90 * 60;
//Split for end coordinate
if (!streetRouter.setDestination(profileRequest.toLat, profileRequest.toLon)) {
content.put("errors", "Edge near the end coordinate wasn't found. Routing didn't start!");
@@ -359,15 +359,16 @@ public class PointToPointRouterServer {
return content;
}
if (fullStateList) {
- streetRouter.setRoutingVisitor(routingVisitor);
+ streetRouter.setRoutingVisitor(debugRoutingVisitor);
}
streetRouter.route();
+ streetRouter.printHull();
if (fullStateList) {
Map<String, Object> featureCollection = new HashMap<>(2);
featureCollection.put("type", "FeatureCollection");
- List<GeoJsonFeature> features = routingVisitor.getFeatures();
+ List<GeoJsonFeature> features = debugRoutingVisitor.getFeatures();
LOG.info("Num features:{}", features.size());
featureCollection.put("features", features);
@@ -400,18 +401,18 @@ public class PointToPointRouterServer {
Map<String, Object> featureCollection = new HashMap<>(2);
featureCollection.put("type", "FeatureCollection");
List<GeoJsonFeature> features = new ArrayList<>(10);
- GeoJsonFeature feature = new GeoJsonFeature(
+ /*GeoJsonFeature feature = new GeoJsonFeature(
fixedDegreesToFloating(destinationSplit.fixedLon), fixedDegreesToFloating(destinationSplit.fixedLat));
feature.addProperty("type", "Point on edge");
- features.add(feature);
+ features.add(feature);*/
VertexStore.Vertex vertex = transportNetwork.streetLayer.vertexStore.getCursor(destinationSplit.vertex0);
- feature = new GeoJsonFeature(vertex.getLon(), vertex.getLat());
+ /*feature = new GeoJsonFeature(vertex.getLon(), vertex.getLat());
feature.addProperty("type", "Edge start point");
feature.addProperty("vertex_idx", destinationSplit.vertex0);
feature.addProperty("distance_to_vertex", destinationSplit.distance0_mm/1000);
- features.add(feature);
+ features.add(feature);*/
transportNetwork.streetLayer.incomingEdges.get(destinationSplit.vertex0)
.forEach(edge_idx -> {
EdgeStore.Edge edge = transportNetwork.streetLayer.edgeStore.getCursor(edge_idx);
@@ -424,11 +425,11 @@ public class PointToPointRouterServer {
});
transportNetwork.streetLayer.vertexStore.getCursor(destinationSplit.vertex1);
- feature = new GeoJsonFeature(vertex.getLon(), vertex.getLat());
+ /*feature = new GeoJsonFeature(vertex.getLon(), vertex.getLat());
feature.addProperty("type", "Edge end point");
feature.addProperty("vertex_idx", destinationSplit.vertex1);
feature.addProperty("distance_to_vertex", destinationSplit.distance1_mm/1000);
- features.add(feature);
+ features.add(feature);*/
transportNetwork.streetLayer.incomingEdges.get(destinationSplit.vertex1)
.forEach(edge_idx -> {
EdgeStore.Edge edge = transportNetwork.streetLayer.edgeStore.getCursor(edge_idx);
diff --git a/src/main/java/com/conveyal/r5/point_to_point/builder/PointToPointQuery.java b/src/main/java/com/conveyal/r5/point_to_point/builder/PointToPointQuery.java
index 8c422bc..7891885 100644
--- a/src/main/java/com/conveyal/r5/point_to_point/builder/PointToPointQuery.java
+++ b/src/main/java/com/conveyal/r5/point_to_point/builder/PointToPointQuery.java
@@ -36,7 +36,7 @@ public class PointToPointQuery {
*
* It's not clear this has a major effect on speed, so we could consider removing it.
*/
- private static final int MAX_ACCESS_STOPS = 200;
+ public static final int MAX_ACCESS_STOPS = 200;
private final TransportNetwork transportNetwork;
@@ -156,6 +156,7 @@ public class PointToPointQuery {
if (transit) {
//Gets correct maxCar/Bike/Walk time in seconds for access leg based on mode since it depends on the mode
streetRouter.timeLimitSeconds = request.getTimeLimit(mode);
+ streetRouter.transitStopSearch = true;
} else {
//Time in direct search doesn't depend on mode
streetRouter.timeLimitSeconds = request.streetTime * 60;
@@ -243,6 +244,7 @@ public class PointToPointQuery {
//TODO: this must be reverse search
for(LegMode mode: request.egressModes) {
StreetRouter streetRouter = new StreetRouter(transportNetwork.streetLayer);
+ streetRouter.transitStopSearch = true;
if (currentlyUnsupportedModes.contains(mode)) {
continue;
}
@@ -377,6 +379,7 @@ public class PointToPointQuery {
private StreetRouter findParkRidePath(ProfileRequest request, StreetRouter streetRouter) {
streetRouter.streetMode = StreetMode.CAR;
streetRouter.timeLimitSeconds = request.maxCarTime * 60;
+ streetRouter.flagSearch = VertexStore.VertexFlag.PARK_AND_RIDE;
if(streetRouter.setOrigin(request.fromLat, request.fromLon)) {
streetRouter.route();
TIntObjectMap<StreetRouter.State> carParks = streetRouter.getReachedVertices(VertexStore.VertexFlag.PARK_AND_RIDE);
@@ -385,6 +388,7 @@ public class PointToPointQuery {
walking.streetMode = StreetMode.WALK;
walking.profileRequest = request;
walking.timeLimitSeconds = request.maxCarTime * 60;
+ walking.transitStopSearch = true;
walking.setOrigin(carParks, CAR_PARK_DROPOFF_TIME_S, CAR_PARK_DROPOFF_COST, LegMode.CAR_PARK);
walking.route();
walking.previousRouter = streetRouter;
@@ -412,6 +416,7 @@ public class PointToPointQuery {
streetRouter.streetMode = StreetMode.WALK;
// TODO add time and distance limits to routing, not just weight.
streetRouter.timeLimitSeconds = request.maxWalkTime * 60;
+ //streetRouter.flagSearch = VertexStore.VertexFlag.BIKE_SHARING;
if(streetRouter.setOrigin(request.fromLat, request.fromLon)) {
streetRouter.route();
//This finds all the nearest bicycle rent stations when walking
@@ -425,6 +430,7 @@ public class PointToPointQuery {
//This finds best cycling path from best start bicycle station to end bicycle station
StreetRouter bicycle = new StreetRouter(transportNetwork.streetLayer);
+ //bicycle.flagSearch = VertexStore.VertexFlag.BIKE_SHARING;
bicycle.previousRouter = streetRouter;
bicycle.streetMode = StreetMode.BICYCLE;
bicycle.profileRequest = request;
@@ -454,6 +460,9 @@ public class PointToPointQuery {
end.streetMode = StreetMode.WALK;
end.profileRequest = request;
end.timeLimitSeconds = request.maxBikeTime * 60;
+ if (!direct) {
+ end.transitStopSearch = true;
+ }
end.setOrigin(cycledStations, BIKE_RENTAL_DROPOFF_TIME_S, BIKE_RENTAL_DROPOFF_COST, LegMode.BICYCLE_RENT);
end.route();
end.previousRouter = bicycle;
diff --git a/src/main/java/com/conveyal/r5/profile/ProfileRequest.java b/src/main/java/com/conveyal/r5/profile/ProfileRequest.java
index 50d5802..ecd2fb7 100644
--- a/src/main/java/com/conveyal/r5/profile/ProfileRequest.java
+++ b/src/main/java/com/conveyal/r5/profile/ProfileRequest.java
@@ -467,4 +467,27 @@ public class ProfileRequest implements Serializable, Cloneable {
return streetTime * 60;
}
}
+
+
+ /**
+ * Returns minCar/BikeTime based on LegMode
+ *
+ * CAR_PARK has minCar time and BICYCLE_RENT has minBike time
+ *
+ * default is 0
+ *
+ * @param mode
+ * @return
+ */
+ @JsonIgnore
+ public int getMinTimeLimit(StreetMode mode) {
+ switch (mode) {
+ case CAR:
+ return minCarTime * 60;
+ case BICYCLE:
+ return minBikeTime * 60;
+ default:
+ return 0;
+ }
+ }
}
diff --git a/src/main/java/com/conveyal/r5/streets/StreetRouter.java b/src/main/java/com/conveyal/r5/streets/StreetRouter.java
index 3fb3970..aba1c1a 100644
--- a/src/main/java/com/conveyal/r5/streets/StreetRouter.java
+++ b/src/main/java/com/conveyal/r5/streets/StreetRouter.java
@@ -2,11 +2,16 @@ package com.conveyal.r5.streets;
import com.conveyal.r5.api.util.LegMode;
import com.conveyal.r5.common.SphericalDistanceLibrary;
+import com.conveyal.r5.point_to_point.builder.PointToPointQuery;
import com.conveyal.r5.profile.StreetMode;
import com.conveyal.r5.profile.ProfileRequest;
import com.conveyal.r5.transit.TransitLayer;
import com.conveyal.r5.util.TIntObjectHashMultimap;
import com.conveyal.r5.util.TIntObjectMultimap;
+import com.vividsolutions.jts.algorithm.ConvexHull;
+import com.vividsolutions.jts.geom.Coordinate;
+import com.vividsolutions.jts.geom.Geometry;
+import com.vividsolutions.jts.geom.GeometryFactory;
import gnu.trove.iterator.TIntIterator;
import gnu.trove.map.TIntIntMap;
import gnu.trove.map.TIntObjectMap;
@@ -34,6 +39,22 @@ public class StreetRouter {
public final StreetLayer streetLayer;
+ //
+
+ /**
+ *True if this is transitStop search
+ * This will stop search when maxStop stops will be found
+ *
+ * Otherwise search will be stopped when queue is empty or time/distance limit is tripped
+ */
+ public boolean transitStopSearch = false;
+
+ public VertexStore.VertexFlag flagSearch = null;
+
+ public int maxStops = PointToPointQuery.MAX_ACCESS_STOPS;
+
+ public int maxVertices = 20;
+
// TODO don't hardwire drive-on-right
private TurnCostCalculator turnCostCalculator;
@@ -143,6 +164,9 @@ public class StreetRouter {
* Note that the TransitLayer contains all the information about which street vertices are transit stops.
*/
public TIntIntMap getReachedStops() {
+ if (transitStopSearch && routingVisitor instanceof StopVisitor) {
+ return ((StopVisitor) routingVisitor).getStops();
+ }
TIntIntMap result = new TIntIntHashMap();
TransitLayer transitLayer = streetLayer.parentNetwork.transitLayer;
transitLayer.stopForStreetVertex.forEachEntry((streetVertex, stop) -> {
@@ -182,6 +206,9 @@ public class StreetRouter {
* @return a map where all the keys are vertex indexes with the particular flag and all the values are states.
*/
public TIntObjectMap<State> getReachedVertices (VertexStore.VertexFlag flag) {
+ if (flagSearch == flag && routingVisitor instanceof VertexFlagVisitor) {
+ return ((VertexFlagVisitor) routingVisitor).getVertices();
+ }
TIntObjectMap<State> result = new TIntObjectHashMap<>();
EdgeStore.Edge e = streetLayer.edgeStore.getCursor();
VertexStore.Vertex v = streetLayer.vertexStore.getCursor();
@@ -283,6 +310,32 @@ public class StreetRouter {
}
+ public Geometry getConvexHull() {
+ TIntIntMap m = getReachedVertices();
+ Coordinate[] points = new Coordinate[m.size()];
+ List<Coordinate> p = new ArrayList<>(m.size());
+ VertexStore.Vertex v = streetLayer.vertexStore.getCursor();
+ GeometryFactory gf = new GeometryFactory();
+
+ m.forEachKey(vidx -> {
+ v.seek(vidx);
+ p.add(new Coordinate(v.getLon(), v.getLat()));
+ return true;
+ });
+ points = p.toArray(points);
+ //GeometryCollection gc = new GeometryCollection(points, gf);
+ ConvexHull c = new ConvexHull(points, gf);
+
+ return c.getConvexHull();
+ }
+
+ public void printHull() {
+ Geometry hull = getConvexHull();
+
+ LOG.info("Hull:\n{}", hull.toText());
+ }
+
+
/**
* Finds closest vertex which has streetMode permissions
*
@@ -308,6 +361,9 @@ public class StreetRouter {
* warning is shown and both are used.
*/
public void route () {
+ long start = System.currentTimeMillis();
+ final int[] maxQueue = { 0 };
+ int vertices = 0;
long startTime = System.currentTimeMillis();
@@ -385,6 +441,11 @@ public class StreetRouter {
EdgeStore.Edge edge = streetLayer.edgeStore.getCursor();
+ if (transitStopSearch) {
+ routingVisitor = new StopVisitor(streetLayer, dominanceVariable,maxStops, profileRequest.getMinTimeLimit(streetMode));
+ } else if (flagSearch != null) {
+ routingVisitor = new VertexFlagVisitor(streetLayer, dominanceVariable, flagSearch, maxVertices, profileRequest.getMinTimeLimit(streetMode));
+ }
while (!queue.isEmpty()) {
State s0 = queue.poll();
@@ -418,7 +479,17 @@ public class StreetRouter {
if (s0.getRoutingVariable(dominanceVariable) > bestValueAtDestination) break;
// Hit RoutingVistor callbacks to monitor search progress.
- if (routingVisitor != null) routingVisitor.visitVertex(s0);
+ if (routingVisitor != null) {
+ routingVisitor.visitVertex(s0);
+
+ if (routingVisitor.shouldBreakSearch()) {
+ LOG.info("Routing visitor is breaking search");
+ break;
+ }
+ }
+ vertices++;
+
+
// If this state is at the destination, figure out the cost at the destination and use it for target pruning.
// TODO explain what "target pruning" is in this context and why we need it. It seems that this is mainly about traversing split streets.
@@ -442,16 +513,22 @@ public class StreetRouter {
s1.heuristic = calcHeuristic(s1);
bestStatesAtEdge.put(s1.backEdge, s1);
queue.add(s1);
+ maxQueue[0] = Math.max(maxQueue[0], queue.size());
}
}
return true; // Iteration over the edge list should continue.
});
}
+ long routingTimeMsec = System.currentTimeMillis() - start;
+ LOG.info("Routing for {} Time:{} min dist: {} m took {} msec", streetMode, timeLimitSeconds/60, distanceLimitMeters, routingTimeMsec);
+ LOG.info("Max Queue:{} states:{} memory:0 vertices:{}", maxQueue[0], bestStatesAtEdge.size(), vertices);
+
+
if (DEBUG_OUTPUT) {
debugPrintStream.close();
}
- long routingTimeMsec = System.currentTimeMillis() - startTime;
- LOG.debug("Routing took {} msec", routingTimeMsec);
+ /*long routingTimeMsec = System.currentTimeMillis() - startTime;
+ LOG.debug("Routing took {} msec", routingTimeMsec);*/
}
/**
@@ -761,4 +838,95 @@ public class StreetRouter {
DISTANCE_MILLIMETERS
}
}
+
+ private static class StopVisitor implements RoutingVisitor {
+ private final int minTravelTimeSeconds;
+ private final StreetLayer streetLayer;
+
+ private final State.RoutingVariable dominanceVariable;
+
+ private final int maxStops;
+
+ TIntIntMap stops = new TIntIntHashMap();
+
+ public StopVisitor(StreetLayer streetLayer, State.RoutingVariable dominanceVariable, int maxStops, int minTravelTimeSeconds) {
+ this.minTravelTimeSeconds = minTravelTimeSeconds;
+ this.streetLayer = streetLayer;
+ this.dominanceVariable = dominanceVariable;
+ this.maxStops = maxStops;
+ }
+
+ @Override
+ public void visitVertex(State state) {
+ int noKey = streetLayer.parentNetwork.transitLayer.stopForStreetVertex.getNoEntryKey();
+ int stop = streetLayer.parentNetwork.transitLayer.stopForStreetVertex.get(state.vertex);
+ if (stop != noKey) {
+ if (state.durationSeconds < minTravelTimeSeconds) {
+ return;
+ }
+ if (!stops.containsKey(stop) || stops.get(stop) > state.getRoutingVariable(
+ dominanceVariable)) {
+ stops.put(stop, state.getRoutingVariable(dominanceVariable));
+ }
+
+ }
+
+ }
+
+ public boolean shouldBreakSearch() {
+ return stops.size() >= this.maxStops;
+ }
+
+ public TIntIntMap getStops() {
+ return stops;
+ }
+ }
+
+ private static class VertexFlagVisitor implements RoutingVisitor {
+ private final int minTravelTimeSeconds;
+ private final StreetLayer streetLayer;
+ private final State.RoutingVariable dominanceVariable;
+ private final int maxVertices;
+
+ private final VertexStore.VertexFlag flag;
+ VertexStore.Vertex v;
+
+ TIntObjectMap<State> vertices = new TIntObjectHashMap<>();
+
+ public VertexFlagVisitor(StreetLayer streetLayer, State.RoutingVariable dominanceVariable, VertexStore.VertexFlag flag, int maxVertices, int minTravelTimeSeconds) {
+ this.minTravelTimeSeconds = minTravelTimeSeconds;
+ this.streetLayer = streetLayer;
+ this.dominanceVariable = dominanceVariable;
+ this.flag = flag;
+ this.maxVertices = maxVertices;
+ v = streetLayer.vertexStore.getCursor();
+ }
+
+ @Override
+ public void visitVertex(State state) {
+ if (state.vertex < 0) {
+ return;
+ }
+ //skips origin states for bikeShare/P+R
+ if(state.backState == null) {
+ return;
+ }
+ v.seek(state.vertex);
+ if (v.getFlag(flag) && state.durationSeconds > minTravelTimeSeconds) {
+ if (!vertices.containsKey(state.vertex) || vertices.get(state.vertex).getRoutingVariable(
+ dominanceVariable) > state.getRoutingVariable(dominanceVariable)) {
+ vertices.put(state.vertex, state);
+ }
+ }
+
+ }
+
+ public boolean shouldBreakSearch() {
+ return vertices.size() >= this.maxVertices;
+ }
+
+ public TIntObjectMap<State> getVertices() {
+ return vertices;
+ }
+ }
}
diff --git a/src/main/java/com/conveyal/r5/transit/TransportNetwork.java b/src/main/java/com/conveyal/r5/transit/TransportNetwork.java
index 0f15329..30c0020 100644
--- a/src/main/java/com/conveyal/r5/transit/TransportNetwork.java
+++ b/src/main/java/com/conveyal/r5/transit/TransportNetwork.java
@@ -76,7 +76,7 @@ public class TransportNetwork implements Serializable {
streetLayer.buildEdgeLists();
streetLayer.indexStreets();
transitLayer.rebuildTransientIndexes();
- transitLayer.buildStopTrees(null);
+ //transitLayer.buildStopTrees(null);
}
/**
@@ -172,7 +172,7 @@ public class TransportNetwork implements Serializable {
// Edge lists must be built after all inter-layer linking has occurred.
streetLayer.buildEdgeLists();
transitLayer.rebuildTransientIndexes();
- transitLayer.buildStopTrees(null);
+ //transitLayer.buildStopTrees(null);
// Create transfers
new TransferFinder(transportNetwork).findTransfers();
diff --git a/src/test/java/com/conveyal/r5/streets/TurnRestrictionTest.java b/src/test/java/com/conveyal/r5/streets/TurnRestrictionTest.java
index f152468..442ace9 100644
--- a/src/test/java/com/conveyal/r5/streets/TurnRestrictionTest.java
+++ b/src/test/java/com/conveyal/r5/streets/TurnRestrictionTest.java
@@ -228,7 +228,7 @@ public class TurnRestrictionTest extends TurnTest {
restrictTurn(false, EW, ENW);
restrictTurn(false, EW + 1, ES);
- RoutingVisitor countingVisitor = new RoutingVisitor(streetLayer.edgeStore) {
+ DebugRoutingVisitor countingVisitor = new DebugRoutingVisitor(streetLayer.edgeStore) {
public int count;
@Override
diff --git a/src/main/java/com/conveyal/r5/point_to_point/PointToPointRouterServer.java b/src/main/java/com/conveyal/r5/point_to_point/PointToPointRouterServer.java
index 1cc63a8..8377f77 100644
--- a/src/main/java/com/conveyal/r5/point_to_point/PointToPointRouterServer.java
+++ b/src/main/java/com/conveyal/r5/point_to_point/PointToPointRouterServer.java
@@ -330,7 +330,7 @@ public class PointToPointRouterServer {
//TODO errorchecks
Boolean fullStateList = request.queryMap("full").booleanValue();
- RoutingVisitor routingVisitor = new RoutingVisitor(transportNetwork.streetLayer.edgeStore);
+ DebugRoutingVisitor debugRoutingVisitor = new DebugRoutingVisitor(transportNetwork.streetLayer.edgeStore);
if (fullStateList == null) {
fullStateList = false;
@@ -359,7 +359,7 @@ public class PointToPointRouterServer {
return content;
}
if (fullStateList) {
- streetRouter.setRoutingVisitor(routingVisitor);
+ streetRouter.setRoutingVisitor(debugRoutingVisitor);
}
streetRouter.route();
@@ -367,7 +367,7 @@ public class PointToPointRouterServer {
if (fullStateList) {
Map<String, Object> featureCollection = new HashMap<>(2);
featureCollection.put("type", "FeatureCollection");
- List<GeoJsonFeature> features = routingVisitor.getFeatures();
+ List<GeoJsonFeature> features = debugRoutingVisitor.getFeatures();
LOG.info("Num features:{}", features.size());
featureCollection.put("features", features);
diff --git a/src/main/java/com/conveyal/r5/streets/DebugRoutingVisitor.java b/src/main/java/com/conveyal/r5/streets/DebugRoutingVisitor.java
new file mode 100644
index 0000000..879ce15
--- /dev/null
+++ b/src/main/java/com/conveyal/r5/streets/DebugRoutingVisitor.java
@@ -0,0 +1,52 @@
+package com.conveyal.r5.streets;
+
+import com.conveyal.r5.common.GeoJsonFeature;
+import com.conveyal.r5.profile.StreetMode;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Visitor for debugging purpose
+ *
+ * It outputs full state graph in plan debugger
+ * Created by mabu on 10.12.2015.
+ */
+public class DebugRoutingVisitor implements RoutingVisitor {
+
+ private List<GeoJsonFeature> features;
+ private final EdgeStore edgeStore;
+
+ /**
+ * Mode should be in the state itself
+ * @param edgeStore streetLayer edgeStore
+ *
+ */
+ public DebugRoutingVisitor(EdgeStore edgeStore) {
+ this.features = new ArrayList<>();
+ this.edgeStore = edgeStore;
+ }
+
+ /**
+ * Saves current state geometry mode and weight as geoJSON feature properties
+ *
+ * in list of features. It is used in full state graph when debugging
+ * @param state
+ */
+ @Override
+ public void visitVertex(StreetRouter.State state) {
+ Integer edgeIdx = state.backEdge;
+ if (!(edgeIdx == null || edgeIdx == -1)) {
+ EdgeStore.Edge edge = edgeStore.getCursor(edgeIdx);
+ GeoJsonFeature feature = new GeoJsonFeature(edge.getGeometry());
+ feature.addProperty("weight", state.weight);
+ feature.addProperty("mode", state.streetMode);
+ feature.addProperty("backEdge", state.backEdge);
+ features.add(feature);
+ }
+ }
+
+ public List<GeoJsonFeature> getFeatures() {
+ return features;
+ }
+}
diff --git a/src/main/java/com/conveyal/r5/streets/RoutingVisitor.java b/src/main/java/com/conveyal/r5/streets/RoutingVisitor.java
index 857695b..1be4638 100644
--- a/src/main/java/com/conveyal/r5/streets/RoutingVisitor.java
+++ b/src/main/java/com/conveyal/r5/streets/RoutingVisitor.java
@@ -1,51 +1,12 @@
package com.conveyal.r5.streets;
-import com.conveyal.r5.common.GeoJsonFeature;
-import com.conveyal.r5.profile.StreetMode;
-
-import java.util.ArrayList;
-import java.util.List;
-
/**
- * Visitor for debugging purpose
- *
- * It outputs full state graph in plan debugger
- * Created by mabu on 10.12.2015.
+ * Created by mabu on 23.8.2016.
*/
-public class RoutingVisitor {
-
- private List<GeoJsonFeature> features;
- private final EdgeStore edgeStore;
-
- /**
- * Mode should be in the state itself
- * @param edgeStore streetLayer edgeStore
- *
- */
- public RoutingVisitor(EdgeStore edgeStore) {
- this.features = new ArrayList<>();
- this.edgeStore = edgeStore;
- }
-
- /**
- * Saves current state geometry mode and weight as geoJSON feature properties
- *
- * in list of features. It is used in full state graph when debugging
- * @param state
- */
- public void visitVertex(StreetRouter.State state) {
- Integer edgeIdx = state.backEdge;
- if (!(edgeIdx == null || edgeIdx == -1)) {
- EdgeStore.Edge edge = edgeStore.getCursor(edgeIdx);
- GeoJsonFeature feature = new GeoJsonFeature(edge.getGeometry());
- feature.addProperty("weight", state.weight);
- feature.addProperty("mode", state.streetMode);
- feature.addProperty("backEdge", state.backEdge);
- features.add(feature);
- }
- }
-
- public List<GeoJsonFeature> getFeatures() {
- return features;
+public interface RoutingVisitor {
+ void visitVertex(StreetRouter.State state);
+ //If search should stop
+ default boolean shouldBreakSearch() {
+ return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment