Skip to content

Commit

Permalink
VGF-61 use DRT params to determine drive time
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjacobs committed Aug 24, 2017
1 parent 5fcdcf8 commit e1e5dc5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 17 deletions.
Expand Up @@ -135,7 +135,7 @@ public boolean temporallyViable(ServiceDay sd, long searchTime, int bestWait, bo
* @return the TripTimes object representing the (possibly updated) best trip, or null if no * @return the TripTimes object representing the (possibly updated) best trip, or null if no
* trip matches both the time and other criteria. * trip matches both the time and other criteria.
*/ */
public TripTimes getNextTrip(State s0, ServiceDay serviceDay, int stopIndex, boolean boarding, double flexOffsetScale, int preBoardVehicleTime, int postAlightVehicleTime) { public TripTimes getNextTrip(State s0, ServiceDay serviceDay, int stopIndex, boolean boarding, double flexOffsetScale, int preBoardDirectTime, int postAlightDirectTime) {
/* Search at the state's time, but relative to midnight on the given service day. */ /* Search at the state's time, but relative to midnight on the given service day. */
int time = serviceDay.secondsSinceMidnight(s0.getTimeSeconds()); int time = serviceDay.secondsSinceMidnight(s0.getTimeSeconds());
// NOTE the time is sometimes negative here. That is fine, we search for the first trip of the day. // NOTE the time is sometimes negative here. That is fine, we search for the first trip of the day.
Expand Down Expand Up @@ -168,7 +168,8 @@ public TripTimes getNextTrip(State s0, ServiceDay serviceDay, int stopIndex, boo
if (stopIndex + 1 < tt.getNumStops() && flexOffsetScale != 0.0) { if (stopIndex + 1 < tt.getNumStops() && flexOffsetScale != 0.0) {
adjustment = (int) Math.round(flexOffsetScale*tt.getRunningTime(stopIndex)); adjustment = (int) Math.round(flexOffsetScale*tt.getRunningTime(stopIndex));
} }
int depTime = tt.getDepartureTime(stopIndex) + adjustment - preBoardVehicleTime; int vehicleTime = (preBoardDirectTime == 0) ? 0 : tt.getDemandResponseMaxTime(preBoardDirectTime);
int depTime = tt.getDepartureTime(stopIndex) + adjustment - vehicleTime;
if (depTime < 0) continue; // negative values were previously used for canceled trips/passed stops/skipped stops, but if (depTime < 0) continue; // negative values were previously used for canceled trips/passed stops/skipped stops, but
// now its not sure if this check should be still in place because there is a boolean field // now its not sure if this check should be still in place because there is a boolean field
// for canceled trips // for canceled trips
Expand All @@ -181,7 +182,8 @@ public TripTimes getNextTrip(State s0, ServiceDay serviceDay, int stopIndex, boo
if (stopIndex - 1 >= 0 && flexOffsetScale != 0.0) { if (stopIndex - 1 >= 0 && flexOffsetScale != 0.0) {
adjustment = (int) Math.round(flexOffsetScale*tt.getRunningTime(stopIndex - 1)); adjustment = (int) Math.round(flexOffsetScale*tt.getRunningTime(stopIndex - 1));
} }
int arvTime = tt.getArrivalTime(stopIndex) + adjustment + postAlightVehicleTime; int vehicleTime = (postAlightDirectTime == 0) ? 0 : tt.getDemandResponseMaxTime(postAlightDirectTime);
int arvTime = tt.getArrivalTime(stopIndex) + adjustment + vehicleTime;
if (arvTime < 0) continue; if (arvTime < 0) continue;
if (arvTime <= adjustedTime && arvTime > bestTime) { if (arvTime <= adjustedTime && arvTime > bestTime) {
bestTrip = tt; bestTrip = tt;
Expand Down Expand Up @@ -229,7 +231,7 @@ public TripTimes getNextTrip(State s0, ServiceDay serviceDay, int stopIndex, boo
} }


// could integrate with getNextTrip // could integrate with getNextTrip
public TripTimes getNextCallNRideTrip(State s0, ServiceDay serviceDay, int stopIndex, boolean boarding, int travelTime) { public TripTimes getNextCallNRideTrip(State s0, ServiceDay serviceDay, int stopIndex, boolean boarding, int directTime) {
/* Search at the state's time, but relative to midnight on the given service day. */ /* Search at the state's time, but relative to midnight on the given service day. */
int time = serviceDay.secondsSinceMidnight(s0.getTimeSeconds()); int time = serviceDay.secondsSinceMidnight(s0.getTimeSeconds());
// NOTE the time is sometimes negative here. That is fine, we search for the first trip of the day. // NOTE the time is sometimes negative here. That is fine, we search for the first trip of the day.
Expand All @@ -255,7 +257,7 @@ public TripTimes getNextCallNRideTrip(State s0, ServiceDay serviceDay, int stopI
bestTime = depTime; bestTime = depTime;
} }
} else { } else {
int arvTime = tt.getCallAndRideAlightTime(stopIndex, adjustedTime, travelTime); int arvTime = tt.getCallAndRideAlightTime(stopIndex, adjustedTime, directTime);
if (arvTime < 0) continue; if (arvTime < 0) continue;
if (arvTime <= adjustedTime && arvTime > bestTime) { if (arvTime <= adjustedTime && arvTime > bestTime) {
bestTrip = tt; bestTrip = tt;
Expand Down
Expand Up @@ -59,7 +59,7 @@ public TripTimes getNextTrip(State s0, ServiceDay sd) {
if (hop.isUnscheduled()) { if (hop.isUnscheduled()) {
RoutingRequest options = s0.getOptions(); RoutingRequest options = s0.getOptions();
Timetable timetable = getPattern().getUpdatedTimetable(options, sd); Timetable timetable = getPattern().getUpdatedTimetable(options, sd);
int time = hop.getRunningTime(s0); int time = (int) Math.round(hop.timeLowerBound(options));
return timetable.getNextCallNRideTrip(s0, sd, getStopIndex(), boarding, time); return timetable.getNextCallNRideTrip(s0, sd, getStopIndex(), boarding, time);
} }
double adjustment = boarding ? startIndex : -1 * (1 - endIndex); double adjustment = boarding ? startIndex : -1 * (1 - endIndex);
Expand All @@ -77,18 +77,26 @@ public int calculateWait(State s0, ServiceDay sd, TripTimes tripTimes) {
int scheduledTime = tripTimes.getCallAndRideBoardTime(getStopIndex(), currTime); int scheduledTime = tripTimes.getCallAndRideBoardTime(getStopIndex(), currTime);
return (int) (sd.time(scheduledTime) - s0.getTimeSeconds()); return (int) (sd.time(scheduledTime) - s0.getTimeSeconds());
} else { } else {
int scheduledTime = tripTimes.getCallAndRideAlightTime(getStopIndex(), currTime, hop.getRunningTime(s0)); int scheduledTime = tripTimes.getCallAndRideAlightTime(getStopIndex(), currTime, (int) hop.timeLowerBound(s0.getOptions()));
return (int) (s0.getTimeSeconds() - (sd.time(scheduledTime))); return (int) (s0.getTimeSeconds() - (sd.time(scheduledTime)));
} }
} }
int stopIndex = getStopIndex(); int stopIndex = getStopIndex();
if (boarding) { if (boarding) {
int startVehicleTime = hop.getStartVehicleTime();
if (startVehicleTime != 0) {
startVehicleTime = tripTimes.getDemandResponseMaxTime(startVehicleTime);
}
int offset = (int) Math.round(startIndex * (tripTimes.getRunningTime(stopIndex))); int offset = (int) Math.round(startIndex * (tripTimes.getRunningTime(stopIndex)));
return (int)(sd.time(tripTimes.getDepartureTime(stopIndex) + offset) - s0.getTimeSeconds()) - hop.getStartVehicleTime(); return (int)(sd.time(tripTimes.getDepartureTime(stopIndex) + offset - startVehicleTime) - s0.getTimeSeconds());
} }
else { else {
int endVehicleTime = hop.getEndVehicleTime();
if (endVehicleTime != 0) {
endVehicleTime = tripTimes.getDemandResponseMaxTime(endVehicleTime);
}
int offset = (int) Math.round((1-endIndex) * (tripTimes.getRunningTime(stopIndex - 1))); int offset = (int) Math.round((1-endIndex) * (tripTimes.getRunningTime(stopIndex - 1)));
return (int)(s0.getTimeSeconds() - sd.time(tripTimes.getArrivalTime(stopIndex) - offset)) + hop.getEndVehicleTime(); return (int)(s0.getTimeSeconds() - sd.time(tripTimes.getArrivalTime(stopIndex) - offset + endVehicleTime));
} }
} }


Expand Down
Expand Up @@ -43,6 +43,7 @@ public class PartialPatternHop extends PatternHop {
private LineString displayGeometry; private LineString displayGeometry;


// if we have this, it's a deviated-route hop // if we have this, it's a deviated-route hop
// these are "direct" times, ie drive times without DRT service parameteers applied
private int startVehicleTime = 0; private int startVehicleTime = 0;
private int endVehicleTime = 0; private int endVehicleTime = 0;
private LineString startGeometry; private LineString startGeometry;
Expand Down Expand Up @@ -145,16 +146,20 @@ public double timeLowerBound(RoutingRequest options) {


@Override @Override
public int getRunningTime(State s0) { public int getRunningTime(State s0) {
TripTimes tt = s0.getTripTimes();
int vehicleTime = startVehicleTime + endVehicleTime;
if (vehicleTime > 0) {
vehicleTime = tt.getDemandResponseMaxTime(vehicleTime);
}
if (originalHopLength == 0) { if (originalHopLength == 0) {
return startVehicleTime + endVehicleTime; return vehicleTime;
} }
double startPct = startIndex / originalHopLength; double startPct = startIndex / originalHopLength;
double endPct = endIndex / originalHopLength; double endPct = endIndex / originalHopLength;
TripTimes tt = s0.getTripTimes();
// necessary so rounding happens using the same coefficients as in FlexTransitBoardAlight // necessary so rounding happens using the same coefficients as in FlexTransitBoardAlight
int arr = tt.getArrivalTime(stopIndex + 1) - (int) Math.round((1 - endPct) * (tt.getRunningTime(stopIndex))); int arr = tt.getArrivalTime(stopIndex + 1) - (int) Math.round((1 - endPct) * (tt.getRunningTime(stopIndex)));
int dep = tt.getDepartureTime(stopIndex) + (int) Math.round(startPct * (tt.getRunningTime(stopIndex))); int dep = tt.getDepartureTime(stopIndex) + (int) Math.round(startPct * (tt.getRunningTime(stopIndex)));
return (arr - dep) + startVehicleTime + endVehicleTime; return (arr - dep) + vehicleTime;
} }


@Override @Override
Expand Down
Expand Up @@ -19,6 +19,7 @@ the License, or (at your option) any later version.
import org.opentripplanner.routing.core.State; import org.opentripplanner.routing.core.State;
import org.opentripplanner.routing.edgetype.PatternHop; import org.opentripplanner.routing.edgetype.PatternHop;
import org.opentripplanner.routing.edgetype.TemporaryEdge; import org.opentripplanner.routing.edgetype.TemporaryEdge;
import org.opentripplanner.routing.trippattern.TripTimes;
import org.opentripplanner.routing.vertextype.PatternStopVertex; import org.opentripplanner.routing.vertextype.PatternStopVertex;


/** /**
Expand All @@ -28,12 +29,16 @@ the License, or (at your option) any later version.
public class TemporaryDirectPatternHop extends TemporaryPartialPatternHop implements TemporaryEdge { public class TemporaryDirectPatternHop extends TemporaryPartialPatternHop implements TemporaryEdge {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


private int time; /*
* This is the direct time a car would take to do this hop. Based on DRT service parameters,
* it actually may take a different amount of time.
*/
private int directTime;


public TemporaryDirectPatternHop(PatternHop hop, PatternStopVertex from, PatternStopVertex to, Stop fromStop, Stop toStop, LineString geometry, int time) { public TemporaryDirectPatternHop(PatternHop hop, PatternStopVertex from, PatternStopVertex to, Stop fromStop, Stop toStop, LineString geometry, int time) {
super(hop, from, to, fromStop, toStop); super(hop, from, to, fromStop, toStop);
setGeometry(geometry); setGeometry(geometry);
this.time = time; this.directTime = time;
} }


@Override @Override
Expand All @@ -53,12 +58,13 @@ public boolean isTrivial() {


@Override @Override
public double timeLowerBound(RoutingRequest options) { public double timeLowerBound(RoutingRequest options) {
return time; return directTime;
} }


@Override @Override
public int getRunningTime(State s0) { public int getRunningTime(State s0) {
return time; TripTimes tt = s0.getTripTimes();
return tt.getDemandResponseMaxTime(directTime);
} }


@Override @Override
Expand All @@ -76,4 +82,8 @@ public void dispose() {
fromv.removeOutgoing(this); fromv.removeOutgoing(this);
tov.removeIncoming(this); tov.removeIncoming(this);
} }

public int getDirectTime() {
return directTime;
}
} }
Expand Up @@ -323,12 +323,27 @@ public int getCallAndRideBoardTime(int stop, long currTime) {
return (int) Math.min(Math.max(currTime, getDepartureTime(stop)), getArrivalTime(stop + 1)); return (int) Math.min(Math.max(currTime, getDepartureTime(stop)), getArrivalTime(stop + 1));
} }


public int getCallAndRideAlightTime(int stop, long currTime, int travelTime) { public int getCallAndRideAlightTime(int stop, long currTime, int directTime) {
int travelTime = getDemandResponseMaxTime(directTime);
currTime -= travelTime; currTime -= travelTime;
int startOfService = (int) Math.min(Math.max(currTime, getDepartureTime(stop - 1)), getArrivalTime(stop)); int startOfService = (int) Math.min(Math.max(currTime, getDepartureTime(stop - 1)), getArrivalTime(stop));
return startOfService + travelTime; return startOfService + travelTime;
} }


public int getDemandResponseMaxTime(int directTime) {
if (maxTravelTime != null) {
return (int) Math.round(maxTravelTime.process(directTime));
}
return directTime;
}

public int getDemandResponseAvgTime(int directTime) {
if (avgTravelTime != null) {
return (int) Math.round(avgTravelTime.process(directTime));
}
return directTime;
}

/** /**
* @return true if this TripTimes represents an unmodified, scheduled trip from a published * @return true if this TripTimes represents an unmodified, scheduled trip from a published
* timetable or false if it is a updated, cancelled, or otherwise modified one. This * timetable or false if it is a updated, cancelled, or otherwise modified one. This
Expand Down

0 comments on commit e1e5dc5

Please sign in to comment.