use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class PreAlightEdge method traverse.
@Override
public State traverse(State s0) {
RoutingRequest options = s0.getOptions();
// Ignore this edge if its stop is banned
if (!options.bannedStops.isEmpty()) {
if (options.bannedStops.matches(((TransitStop) tov).getStop())) {
return null;
}
}
if (!options.bannedStopsHard.isEmpty()) {
if (options.bannedStopsHard.matches(((TransitStop) tov).getStop())) {
return null;
}
}
if (options.arriveBy) {
// options can be used to find transit stops without boarding vehicles.
if (!options.modes.isTransit())
return null;
TransitStop toVertex = (TransitStop) getToVertex();
// If we've hit our transfer limit, don't go any further
if (s0.getNumBoardings() > options.maxTransfers)
return null;
/* apply transfer rules */
/*
* look in the global transfer table for the rules from the previous stop to this stop.
*/
long t0 = s0.getTimeSeconds();
long slack;
if (s0.isEverBoarded()) {
slack = options.transferSlack - options.boardSlack;
} else {
slack = options.alightSlack;
}
long alight_before = t0 - slack;
int transfer_penalty = 0;
// penalize transfers more heavily if requested by the user
if (s0.isEverBoarded()) {
// this is not the first boarding, therefore we must have "transferred" -- whether
// via a formal transfer or by walking.
transfer_penalty += options.transferPenalty;
}
StateEditor s1 = s0.edit(this);
s1.setTimeSeconds(alight_before);
long wait_cost = t0 - alight_before;
s1.incrementWeight(wait_cost + transfer_penalty);
s1.setBackMode(getMode());
return s1.makeState();
} else {
/* Forward traversal: not so much to do */
StateEditor s1 = s0.edit(this);
TransitStop toVertex = (TransitStop) getToVertex();
s1.alightTransit();
s1.incrementTimeInSeconds(options.alightSlack);
s1.setBackMode(getMode());
return s1.makeState();
}
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class RentABikeAbstractEdge method traverseDropoff.
protected State traverseDropoff(State s0) {
RoutingRequest options = s0.getOptions();
/*
* To dropoff a bike, we need to have rented one.
*/
if (!s0.isBikeRenting() || !hasCompatibleNetworks(networks, s0.getBikeRentalNetworks()))
return null;
BikeRentalStationVertex pickup = (BikeRentalStationVertex) tov;
if (options.useBikeRentalAvailabilityInformation && pickup.getSpacesAvailable() == 0) {
return null;
}
StateEditor s1e = s0.edit(this);
s1e.incrementWeight(options.arriveBy ? options.bikeRentalPickupCost : options.bikeRentalDropoffCost);
s1e.incrementTimeInSeconds(options.arriveBy ? options.bikeRentalPickupTime : options.bikeRentalDropoffTime);
s1e.setBikeRenting(false);
s1e.setBackMode(TraverseMode.WALK);
State s1 = s1e.makeState();
return s1;
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class RentABikeAbstractEdge method traverseRent.
protected State traverseRent(State s0) {
RoutingRequest options = s0.getOptions();
/*
* If we already have a bike (rented or own) we won't go any faster by having a second one.
*/
if (!s0.getNonTransitMode().equals(TraverseMode.WALK))
return null;
/*
* To rent a bike, we need to have BICYCLE in allowed modes.
*/
if (!options.modes.contains(TraverseMode.BICYCLE))
return null;
BikeRentalStationVertex dropoff = (BikeRentalStationVertex) tov;
if (options.useBikeRentalAvailabilityInformation && dropoff.getBikesAvailable() == 0) {
return null;
}
StateEditor s1 = s0.edit(this);
s1.incrementWeight(options.arriveBy ? options.bikeRentalDropoffCost : options.bikeRentalPickupCost);
s1.incrementTimeInSeconds(options.arriveBy ? options.bikeRentalDropoffTime : options.bikeRentalPickupTime);
s1.setBikeRenting(true);
s1.setBikeRentalNetwork(networks);
s1.setBackMode(s0.getNonTransitMode());
State s1b = s1.makeState();
return s1b;
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TripTimes method tripAcceptable.
/**
* Once a trip has been found departing or arriving at an appropriate time, check whether that
* trip fits other restrictive search criteria such as bicycle and wheelchair accessibility
* and transfers with minimum time or forbidden transfers.
*/
public boolean tripAcceptable(final State state0, final int stopIndex) {
final RoutingRequest options = state0.getOptions();
final BannedStopSet banned = options.bannedTrips.get(trip.getId());
if (banned != null && banned.contains(stopIndex)) {
return false;
}
if (options.wheelchairAccessible && trip.getWheelchairAccessible() != 1) {
return false;
}
// Establish whether we have a rented _or_ owned bicycle.
final boolean bicycle = state0.getNonTransitMode() == TraverseMode.BICYCLE;
if (bicycle && BikeAccess.fromTrip(trip) != BikeAccess.ALLOWED) {
return false;
}
return true;
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestHalfEdges method testRouteToSameEdge.
@Test
public void testRouteToSameEdge() {
RoutingRequest options = new RoutingRequest();
HashSet<Edge> turns = new HashSet<Edge>();
turns.add(left);
turns.add(leftBack);
TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(left.getGeometry()), true);
assertEquals(start.getX(), end.getX(), 0.0001);
assertTrue(start.getY() < end.getY());
Collection<Edge> edges = end.getIncoming();
assertEquals(2, edges.size());
long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
options.dateTime = startTime;
options.setRoutingContext(graph, start, end);
options.setMaxWalkDistance(Double.MAX_VALUE);
ShortestPathTree spt = aStar.getShortestPathTree(options);
GraphPath path = spt.getPath(end, false);
assertNotNull("There must be a path from start to end", path);
assertEquals(1, path.edges.size());
options.cleanup();
}
Aggregations