use of org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule in project OpenTripPlanner by opentripplanner.
the class SpeedTestRequest method createRangeRaptorRequest.
RaptorRequest<TripSchedule> createRangeRaptorRequest(SpeedTestProfile profile, int numOfExtraTransfers, boolean oneIterationOnly, EgressAccessRouter streetRouter) {
// Add half of the extra time to departure and half to the arrival
int expandSearchSec = EXPAND_SEARCH_WINDOW_HOURS * 3600 / 2;
RaptorRequestBuilder<TripSchedule> builder = new RaptorRequestBuilder<>();
builder.searchParams().boardSlackInSeconds(120).timetableEnabled(true).numberOfAdditionalTransfers(numOfExtraTransfers);
if (testCase.departureTime != TestCase.NOT_SET) {
builder.searchParams().earliestDepartureTime(testCase.departureTime - expandSearchSec);
}
if (testCase.arrivalTime != TestCase.NOT_SET) {
builder.searchParams().latestArrivalTime(testCase.arrivalTime + expandSearchSec);
}
if (testCase.window != TestCase.NOT_SET) {
builder.searchParams().searchWindowInSeconds(testCase.window + 2 * expandSearchSec);
}
if (oneIterationOnly) {
builder.searchParams().searchOneIterationOnly();
}
builder.enableOptimization(Optimization.PARALLEL);
builder.profile(profile.raptorProfile);
for (Optimization it : profile.optimizations) {
builder.enableOptimization(it);
}
if (profile.raptorProfile.isOneOf(RaptorProfile.NO_WAIT_STD, RaptorProfile.NO_WAIT_BEST_TIME)) {
builder.searchParams().searchOneIterationOnly();
}
builder.slackProvider(new SlackProvider(config.request.transferSlack, config.request.boardSlack, config.request.boardSlackForMode, config.request.alightSlack, config.request.alightSlackForMode));
builder.searchDirection(profile.direction);
addAccessEgressStopArrivals(streetRouter.getAccessTimesInSecondsByStopIndex(), builder.searchParams()::addAccessStop);
addAccessEgressStopArrivals(streetRouter.getEgressTimesInSecondsByStopIndex(), builder.searchParams()::addEgressStop);
addDebugOptions(builder, opts);
RaptorRequest<TripSchedule> req = builder.build();
if (opts.debugRequest()) {
System.err.println("-> Request: " + req);
}
return req;
}
use of org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule in project OpenTripPlanner by opentripplanner.
the class RaptorPathToItineraryMapper method extractTransitLegCoordinates.
private List<Coordinate> extractTransitLegCoordinates(TransitPathLeg<TripSchedule> pathLeg) {
List<Coordinate> transitLegCoordinates = new ArrayList<>();
TripPattern tripPattern = pathLeg.trip().getOriginalTripPattern();
TripSchedule tripSchedule = pathLeg.trip();
boolean boarded = false;
for (int j = 0; j < tripPattern.stopPattern.stops.length; j++) {
int currentStopIndex = transitLayer.getStopIndex().indexByStop.get(tripPattern.getStop(j));
if (boarded) {
transitLegCoordinates.addAll(Arrays.asList(tripPattern.getHopGeometry(j - 1).getCoordinates()));
}
if (!boarded && tripSchedule.departure(j) == pathLeg.fromTime() && currentStopIndex == pathLeg.fromStop()) {
boarded = true;
}
if (boarded && tripSchedule.arrival(j) == pathLeg.toTime() && currentStopIndex == pathLeg.toStop()) {
break;
}
}
return transitLegCoordinates;
}
use of org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule in project OpenTripPlanner by opentripplanner.
the class RideMapper method rideForTransitPathLeg.
public static Ride rideForTransitPathLeg(TransitPathLeg leg, TransitLayer transitLayer) {
TransitPathLeg<TripSchedule> transitPathLeg = leg.asTransitLeg();
TripSchedule tripSchedule = transitPathLeg.trip();
Ride ride = new Ride();
TripPattern tripPattern = tripSchedule.getOriginalTripPattern();
ride.firstStop = transitLayer.getStopByIndex(transitPathLeg.fromStop());
ride.lastStop = transitLayer.getStopByIndex(transitPathLeg.toStop());
ride.startZone = ride.firstStop.getFirstZoneAsString();
ride.endZone = ride.lastStop.getFirstZoneAsString();
// In almost all cases (except some loop routes) this should get the right set of zones passed through.
// We don't have the position of the stops within the pattern so can't readily get more accurate than this.
boolean onBoard = false;
for (Stop stop : tripPattern.getStops()) {
if (stop == ride.firstStop) {
onBoard = true;
}
if (onBoard) {
ride.zones.add(stop.getFirstZoneAsString());
if (stop == ride.lastStop)
break;
}
}
ride.agency = tripPattern.route.getAgency().getId();
ride.route = tripPattern.route.getId();
ride.trip = tripSchedule.getOriginalTripTimes().trip.getId();
// TODO verify that times are in seconds after midnight
ride.startTime = transitPathLeg.fromTime();
ride.endTime = transitPathLeg.toTime();
// In the default fare service, we classify rides by mode.
ride.classifier = tripPattern.getMode();
return ride;
}
use of org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule in project OpenTripPlanner by opentripplanner.
the class RaptorRequestMapper method mapRequest.
public static RaptorRequest<TripSchedule> mapRequest(RoutingRequest request, ZonedDateTime startOfTime, Collection<? extends RaptorTransfer> accessTimes, Collection<? extends RaptorTransfer> egressTimes) {
RaptorRequestBuilder<TripSchedule> builder = new RaptorRequestBuilder<>();
int time = DateMapper.secondsSinceStartOfTime(startOfTime, request.getDateTime().toInstant());
if (request.arriveBy) {
builder.searchParams().latestArrivalTime(time);
} else {
builder.searchParams().earliestDepartureTime(time);
}
if (request.maxTransfers != null) {
builder.searchParams().maxNumberOfTransfers(request.maxTransfers);
}
builder.profile(RaptorProfile.MULTI_CRITERIA).enableOptimization(Optimization.PARETO_CHECK_AGAINST_DESTINATION).slackProvider(new SlackProvider(request.transferSlack, request.boardSlack, request.boardSlackForMode, request.alightSlack, request.alightSlackForMode));
builder.searchParams().searchWindow(request.searchWindow).addAccessStops(accessTimes.stream().map(t -> (RaptorTransfer) t).collect(Collectors.toList())).addEgressStops(egressTimes.stream().map(t -> (RaptorTransfer) t).collect(Collectors.toList())).boardSlackInSeconds(request.boardSlack).timetableEnabled(true);
builder.mcCostFactors().waitReluctanceFactor(request.waitReluctance).walkReluctanceFactor(request.walkReluctance);
return builder.build();
}
use of org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule in project OpenTripPlanner by opentripplanner.
the class ItineraryMapper method createItinerary.
private Itinerary createItinerary(Path<TripSchedule> path, StopAtDistance accessPath, StopAtDistance egressPath) {
if (path == null) {
return null;
}
Itinerary itinerary = new Itinerary();
itinerary.walkDistance = 0.0;
itinerary.transitTime = 0;
itinerary.waitingTime = 0;
itinerary.weight = path.cost();
int numberOfTransits = 0;
// Access leg
Leg leg = new Leg();
AccessPathLeg<TripSchedule> accessLeg = path.accessLeg();
leg.startTime = accessLeg.fromTime();
leg.endTime = accessLeg.toTime();
leg.from = request.tc().fromPlace;
leg.to = request.tc().toPlace;
leg.mode = WALK;
leg.distance = accessPath.distance;
itinerary.addLeg(leg);
PathLeg<TripSchedule> pathLeg = accessLeg.nextLeg();
int previousArrivalTime = -1;
while (pathLeg.isTransitLeg() || pathLeg.isTransferLeg()) {
leg = new Leg();
// Transfer leg if present
if (pathLeg.isTransferLeg()) {
TransferPathLeg<?> it = pathLeg.asTransferLeg();
previousArrivalTime = it.toTime();
leg.startTime = it.fromTime();
leg.endTime = previousArrivalTime;
leg.mode = WALK;
leg.from = mapToPlace(it.fromStop());
leg.to = mapToPlace(it.toStop());
// distanceMMToMeters (transferPath.getDistance());
leg.distance = -1.0;
} else {
// Transit leg
TransitPathLeg<TripSchedule> it = pathLeg.asTransitLeg();
itinerary.transitTime += it.toTime() - it.fromTime();
itinerary.waitingTime += it.fromTime() - previousArrivalTime;
previousArrivalTime = it.toTime();
++numberOfTransits;
leg.distance = 0.0;
TripSchedule tripSchedule = it.trip();
TripPattern tripPattern = tripSchedule.getOriginalTripPattern();
Route routeInfo = tripPattern.route;
leg.from = mapToPlace(it.fromStop());
leg.to = mapToPlace(it.toStop());
leg.route = routeInfo.getShortName();
leg.agencyName = routeInfo.getAgency().getName();
leg.tripShortName = tripSchedule.getOriginalTripPattern().name;
leg.agencyId = routeInfo.getAgency().getId();
leg.routeShortName = routeInfo.getShortName();
leg.routeLongName = routeInfo.getLongName();
leg.mode = TraverseMode.fromTransitMode(tripSchedule.getOriginalTripPattern().getMode());
leg.startTime = it.fromTime();
leg.endTime = it.toTime();
}
itinerary.addLeg(leg);
pathLeg = pathLeg.nextLeg();
}
// Egress leg
leg = new Leg();
EgressPathLeg<TripSchedule> egressLeg = pathLeg.asEgressLeg();
leg.startTime = egressLeg.fromTime();
leg.endTime = egressLeg.toTime();
leg.from = mapToPlace(egressLeg.fromStop());
leg.to = request.tc().toPlace;
leg.mode = WALK;
leg.distance = egressPath.distance;
itinerary.addLeg(leg);
itinerary.startTime = itinerary.legs.get(0).startTime;
itinerary.endTime = leg.endTime;
itinerary.duration = itinerary.endTime - itinerary.startTime;
// The number of transfers is the number of transits minus one, we can NOT count the number of Transfers
// in the path or itinerary, because transfers at the same stop does not produce a transfer object, just two
// transits following each other.
itinerary.transfers = numberOfTransits - 1;
return itinerary;
}
Aggregations