Skip to content

Commit

Permalink
add allowed OOST
Browse files Browse the repository at this point in the history
  • Loading branch information
mbsalvatore committed Feb 15, 2024
1 parent 8f6c104 commit 25c792b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public Transfer findTransfer(
return stop2StopTransfers.get(new P2<>(fromStop, toStop));
}

@Nullable
public Transfer findStopToStopTransfer(StopLocation fromStop, StopLocation toStop){
return stop2StopTransfers.get(new P2<>(fromStop, toStop));
}

void add(Transfer transfer) {
TransferPoint from = transfer.getFrom();
TransferPoint to = transfer.getTo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import java.util.*;
import javax.annotation.Nullable;
import org.opentripplanner.ext.flex.FlexAccessEgress;
import org.opentripplanner.model.Stop;
import org.opentripplanner.model.TransitMode;
import org.opentripplanner.model.*;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.routing.algorithm.filterchain.ItineraryFilter;
import org.opentripplanner.routing.algorithm.mapping.RaptorPathToItineraryMapper;
Expand Down Expand Up @@ -36,6 +35,7 @@
import org.opentripplanner.routing.api.response.TripSearchMetadata;
import org.opentripplanner.routing.core.State;
import org.opentripplanner.routing.edgetype.StreetTransitEntranceLink;
import org.opentripplanner.routing.edgetype.StreetTransitStopLink;
import org.opentripplanner.routing.error.RoutingValidationException;
import org.opentripplanner.routing.framework.DebugTimingAggregator;
import org.opentripplanner.routing.graph.Edge;
Expand Down Expand Up @@ -257,8 +257,8 @@ private Collection<Itinerary> routeTransit(Router router) {
// TODO
for (Path<TripSchedule> path : paths) {
// Convert the Raptor/Astar paths to OTP API Itineraries
Itinerary itinerary = null;
if (subwayHasNoOutOfSystemTransfer(path)) {
Itinerary itinerary = null;
if (subwayHasNoOutOfSystemTransfer(path, transitLayer)) {
try {
itinerary = itineraryMapper.createItinerary(path);
} catch (Exception e) {
Expand Down Expand Up @@ -291,7 +291,7 @@ private Collection<Itinerary> routeTransit(Router router) {
return itineraries;
}

private boolean subwayHasNoOutOfSystemTransfer(Path<TripSchedule> path) {
private boolean subwayHasNoOutOfSystemTransfer(Path<TripSchedule> path, TransitLayer transitLayer) {

boolean enteredSubway = false;
boolean exitedSubway = false;
Expand Down Expand Up @@ -319,31 +319,55 @@ private boolean subwayHasNoOutOfSystemTransfer(Path<TripSchedule> path) {
if (leg.isTransferLeg()) {
List<Edge> edges = ((TransferWithDuration) leg.asTransferLeg().transfer()).transfer().getEdges();
for (Edge e : edges) {
if (e instanceof StreetTransitEntranceLink && enteredSubway) {
if (!(e.getToVertex() instanceof TransitEntranceVertex)) {
if (isTransitEntranceLink(e) && enteredSubway) {
if (!(e.getToVertex() instanceof TransitEntranceVertex || e.getToVertex() instanceof TransitStopVertex)) {
//Exiting subway
exitedSubway = true;
continue;
}
TransitEntranceVertex transitEntranceVertex = (TransitEntranceVertex) e.getToVertex();
boolean isSubwayEntrance = transitEntranceVertex.getEntrance().getStopId().getFeedId().equals("MTASBWY");
boolean isSubwayEntrance = false;
if (e.getToVertex() instanceof TransitEntranceVertex) {
TransitEntranceVertex transitEntranceVertex = (TransitEntranceVertex) e.getToVertex();
isSubwayEntrance = transitEntranceVertex.getEntrance().getStopId().getFeedId().equals("2");
} else if (e.getToVertex() instanceof TransitStopVertex) {
TransitStopVertex transitStopVertex = (TransitStopVertex) e.getToVertex();
StationElement stationElement = transitStopVertex.getStationElement();
isSubwayEntrance = stationElement.getStopId().getFeedId().equals("2");
}

if (!isSubwayEntrance) {
//We have entered non-subway transit therefore reset out of system subway tracking
exitedSubway = false;
enteredSubway = false;
continue;
}
if (exitedSubway)
//CANNOT RE-ENTER SUBWAY!
return false;
exitedSubway = true;
if (exitedSubway) {
//CANNOT RE-ENTER SUBWAY! ...
//... Unless this is an allowed out of system transfer
List<StopLocation> stopLocations = transitLayer.getStopIndex().stopsByIndex;
StopLocation fromStopLocation = stopLocations.get(leg.fromStop());
StopLocation toStopLocation = stopLocations.get(leg.toStop());
org.opentripplanner.model.transfer.Transfer allowedTransfer = transitLayer.getTransferService().findStopToStopTransfer(fromStopLocation, toStopLocation);
if (allowedTransfer == null)
return false;
else {
exitedSubway = false;
enteredSubway = false;
}
} else {
exitedSubway = true;
}
}
}
}
}
return true;
}

private boolean isTransitEntranceLink(Edge e) {
return e instanceof StreetTransitEntranceLink || e instanceof StreetTransitStopLink;
}

private RaptorRoutingRequestTransitData createRequestTransitDataProvider(
TransitLayer transitLayer,
Graph graph
Expand Down

0 comments on commit 25c792b

Please sign in to comment.