Skip to content

Commit

Permalink
Correct flex edge mapping
Browse files Browse the repository at this point in the history
When creating itineraries for flex trips:
 * use the actual board / alight coordinates in leg.from / leg.to
 * always create a new leg when a FlexEdge is traversed
  • Loading branch information
flaktack committed Jun 4, 2021
1 parent d2687d9 commit 932f817
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/ext/java/org/opentripplanner/ext/flex/FlexLegMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static public void fixFlexTripLeg(Leg leg, FlexTripEdge flexTripEdge) {
}

public static void addFlexPlaces(Leg leg, FlexTripEdge flexEdge, Locale requestedLocale) {
leg.from = Place.forStop(flexEdge.s1, flexEdge.flexTemplate.fromStopIndex, null);
leg.to = Place.forStop(flexEdge.s2, flexEdge.flexTemplate.toStopIndex, null);
leg.from = Place.forFlexStop(flexEdge.s1, flexEdge.getFromVertex(), flexEdge.flexTemplate.fromStopIndex, null);
leg.to = Place.forFlexStop(flexEdge.s2, flexEdge.getToVertex(), flexEdge.flexTemplate.toStopIndex, null);
}
}
5 changes: 3 additions & 2 deletions src/ext/java/org/opentripplanner/ext/flex/FlexRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import java.util.Locale;
import org.opentripplanner.common.model.T2;
import org.opentripplanner.ext.flex.flexpathcalculator.FlexPathCalculator;
import org.opentripplanner.ext.flex.flexpathcalculator.StreetFlexPathCalculator;
Expand Down Expand Up @@ -88,7 +89,7 @@ public FlexRouter(
}
}

public Collection<Itinerary> createFlexOnlyItineraries() {
public Collection<Itinerary> createFlexOnlyItineraries(Locale locale) {
calculateFlexAccessTemplates();
calculateFlexEgressTemplates();

Expand All @@ -103,7 +104,7 @@ public Collection<Itinerary> createFlexOnlyItineraries() {
StopLocation transferStop = template.getTransferStop();
if (this.flexEgressTemplates.stream().anyMatch(t -> t.getAccessEgressStop().equals(transferStop))) {
for(NearbyStop egress : streetEgressByStop.get(transferStop)) {
Itinerary itinerary = template.createDirectItinerary(egress, arriveBy, departureTime, startOfTime);
Itinerary itinerary = template.createDirectItinerary(egress, arriveBy, departureTime, startOfTime, locale);
if (itinerary != null) {
itineraries.add(itinerary);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public FlexAccessTemplate(
}

public Itinerary createDirectItinerary(
NearbyStop egress, boolean arriveBy, int departureTime, ZonedDateTime startOfTime
NearbyStop egress, boolean arriveBy, int departureTime, ZonedDateTime startOfTime,
Locale locale
) {
List<Edge> egressEdges = egress.edges;

Expand Down Expand Up @@ -89,7 +90,7 @@ public Itinerary createDirectItinerary(

Itinerary itinerary = GraphPathToItineraryMapper.generateItinerary(
new GraphPath(state),
Locale.ENGLISH
locale
);

ZonedDateTime zdt = startOfTime.plusSeconds(timeShift);
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/opentripplanner/model/plan/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ public static Place forStop(StopLocation stop, Integer stopIndex, Integer stopSe
.build();
}

public static Place forFlexStop(
StopLocation stop,
Vertex vertex,
Integer stopIndex,
Integer stopSequence
) {
// The actual vertex is used because the StopLocation coordinates may not be equal to the vertex's
// coordinates.
return defaults(vertex, stop.getName())
.vertexType(VertexType.TRANSIT)
.stop(stop)
.stopIndex(stopIndex)
.stopSequence(stopSequence)
.build();
}

public static Place forStop(TransitStopVertex vertex, String name) {
return defaults(vertex, name)
.vertexType(VertexType.TRANSIT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private static State[][] sliceStates(State[] states) {
var modeChange = backMode != forwardMode && backMode != null && forwardMode != null;
var parkingChange = backState.isVehicleParked() != forwardState.isVehicleParked();
var rentalChange = isRentalPickUp(backState) || isRentalDropOff(backState);
var flexEdge = forwardState.getBackEdge() instanceof FlexTripEdge;

if (parkingChange) {
/* Remove the state for actually parking (traversing VehicleParkingEdge) from the
Expand All @@ -221,7 +222,7 @@ private static State[][] sliceStates(State[] states) {
legsIndexes.add(legIndexPairs);
legIndexPairs = new int[] {i + 1, states.length - 1};
}
else if (modeChange || rentalChange) {
else if (modeChange || rentalChange || flexEdge) {
legIndexPairs[1] = i;
legsIndexes.add(legIndexPairs);
legIndexPairs = new int[] {i, states.length - 1};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static List<Itinerary> route(
egressStops
);

return new ArrayList<>(flexRouter.createFlexOnlyItineraries());
return new ArrayList<>(flexRouter.createFlexOnlyItineraries(request.locale));
}
}
}

0 comments on commit 932f817

Please sign in to comment.