use of org.opentripplanner.model.FlexStopLocation in project OpenTripPlanner by opentripplanner.
the class NearbyStopFinder method findNearbyStopsViaStreets.
/**
* Return all stops within a certain radius of the given vertex, using network distance along streets.
* If the origin vertex is a StopVertex, the result will include it.
*
* @param originVertices the origin point of the street search
* @param reverseDirection if true the paths returned instead originate at the nearby stops and have the
* originVertex as the destination
* @param removeTempEdges after creating a new routing request and routing context, remove all the temporary
* edges that are part of that context. NOTE: this will remove _all_ temporary edges
* coming out of the origin and destination vertices, including those in any other
* RoutingContext referencing them, making routing from/to them totally impossible.
* This is a stopgap solution until we rethink the lifecycle of RoutingContext.
*/
public List<StopAtDistance> findNearbyStopsViaStreets(Set<Vertex> originVertices, boolean reverseDirection, boolean removeTempEdges, RoutingRequest routingRequest) {
routingRequest.arriveBy = reverseDirection;
if (!reverseDirection) {
routingRequest.setRoutingContext(graph, originVertices, null);
} else {
routingRequest.setRoutingContext(graph, null, originVertices);
}
int walkTime = (int) (radiusMeters / new RoutingRequest().walkSpeed);
routingRequest.worstTime = routingRequest.dateTime + (reverseDirection ? -walkTime : walkTime);
routingRequest.disableRemainingWeightHeuristic = true;
routingRequest.rctx.remainingWeightHeuristic = new TrivialRemainingWeightHeuristic();
routingRequest.dominanceFunction = new DominanceFunction.MinimumWeight();
ShortestPathTree spt = astar.getShortestPathTree(routingRequest);
List<StopAtDistance> stopsFound = Lists.newArrayList();
Multimap<FlexStopLocation, State> locationsMap = ArrayListMultimap.create();
if (spt != null) {
// TODO use GenericAStar and a traverseVisitor? Add an earliestArrival switch to genericAStar?
for (State state : spt.getAllStates()) {
Vertex targetVertex = state.getVertex();
if (originVertices.contains(targetVertex))
continue;
if (targetVertex instanceof TransitStopVertex && state.isFinal()) {
stopsFound.add(StopAtDistance.stopAtDistanceForState(state, ((TransitStopVertex) targetVertex).getStop()));
}
if (OTPFeature.FlexRouting.isOn() && targetVertex instanceof StreetVertex && ((StreetVertex) targetVertex).flexStopLocations != null) {
for (FlexStopLocation flexStopLocation : ((StreetVertex) targetVertex).flexStopLocations) {
// This is for a simplification, so that we only return one vertex from each
// stop location. All vertices are added to the multimap, which is filtered
// below, so that only the closest vertex is added to stopsFound
locationsMap.put(flexStopLocation, state);
}
}
}
}
for (var locationStates : locationsMap.asMap().entrySet()) {
FlexStopLocation flexStopLocation = locationStates.getKey();
Collection<State> states = locationStates.getValue();
// Select the vertex from all vertices that are reachable per FlexStopLocation by taking
// the minimum walking distance
State min = Collections.min(states, (s1, s2) -> (int) (s1.walkDistance - s2.walkDistance));
stopsFound.add(StopAtDistance.stopAtDistanceForState(min, flexStopLocation));
}
/* Add the origin vertices if needed. The SPT does not include the initial state. FIXME shouldn't it? */
for (Vertex vertex : originVertices) {
if (vertex instanceof TransitStopVertex) {
stopsFound.add(new StopAtDistance((TransitStopVertex) vertex, 0, Collections.emptyList(), null, new State(vertex, routingRequest)));
}
}
if (removeTempEdges) {
routingRequest.cleanup();
}
return stopsFound;
}
use of org.opentripplanner.model.FlexStopLocation in project OpenTripPlanner by opentripplanner.
the class FlexLocationsToStreetEdgesMapper method buildGraph.
@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra, DataImportIssueStore issueStore) {
if (graph.locationsById.isEmpty()) {
return;
}
StreetVertexIndex streetIndex = new StreetVertexIndex(graph);
for (FlexStopLocation flexStopLocation : graph.locationsById.values()) {
for (Vertex vertx : streetIndex.getVerticesForEnvelope(flexStopLocation.getGeometry().getEnvelopeInternal())) {
// Check that the vertex is connected to both driveable and walkable edges
if (!(vertx instanceof StreetVertex)) {
continue;
}
if (!((StreetVertex) vertx).isEligibleForCarPickupDropoff()) {
continue;
}
// The street index overselects, so need to check for exact geometry inclusion
Point p = GeometryUtils.getGeometryFactory().createPoint(vertx.getCoordinate());
if (flexStopLocation.getGeometry().disjoint(p)) {
continue;
}
StreetVertex streetVertex = (StreetVertex) vertx;
if (streetVertex.flexStopLocations == null) {
streetVertex.flexStopLocations = new HashSet<>();
}
streetVertex.flexStopLocations.add(flexStopLocation);
}
}
}
Aggregations