use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.
the class RepeatedRaptorProfileRouter method findInitialStops.
/**
* Find all transit stops accessible by streets around the origin, leaving behind a shortest path tree of the
* reachable area in the field preTransitSpt.
*
* @param data the raptor data table to use. If this is null (i.e. there is no transit) range is extended,
* and we don't care if we actually find any stops, we just want the tree of on-street distances.
*/
@VisibleForTesting
public TIntIntMap findInitialStops(boolean dest, RaptorWorkerData data) {
LOG.info("Finding initial stops");
double lat = dest ? request.toLat : request.fromLat;
double lon = dest ? request.toLon : request.fromLon;
QualifiedModeSet modes = dest ? request.egressModes : request.accessModes;
RoutingRequest rr = new RoutingRequest(modes);
rr.batch = true;
rr.from = new GenericLocation(lat, lon);
// rr.walkSpeed = request.walkSpeed;
rr.to = rr.from;
rr.setRoutingContext(graph);
rr.dateTime = request.date.toDateMidnight(DateTimeZone.forTimeZone(graph.getTimeZone())).getMillis() / 1000 + request.fromTime;
rr.walkSpeed = request.walkSpeed;
rr.bikeSpeed = request.bikeSpeed;
if (data == null) {
// Non-transit mode. Search out to the full 120 minutes.
// Should really use directModes.
rr.worstTime = rr.dateTime + RaptorWorker.MAX_DURATION;
rr.dominanceFunction = new DominanceFunction.EarliestArrival();
} else {
// Transit mode, limit pre-transit travel.
if (rr.modes.contains(TraverseMode.BICYCLE)) {
rr.dominanceFunction = new DominanceFunction.EarliestArrival();
rr.worstTime = rr.dateTime + request.maxBikeTime * 60;
} else {
// We use walk-distance limiting and a least-walk dominance function in order to be consistent with egress walking
// which is implemented this way because walk times can change when walk speed changes. Also, walk times are floating
// point and can change slightly when streets are split. Street lengths are internally fixed-point ints, which do not
// suffer from roundoff. Great care is taken when splitting to preserve sums.
// When cycling, this is not an issue; we already have an explicitly asymmetrical search (cycling at the origin, walking at the destination),
// so we need not preserve symmetry.
// We use the max walk time for the search at the origin, but we clamp it to MAX_WALK_METERS so that we don;t
// have every transit stop in the state as an initial transit stop if someone sets max walk time to four days,
// and so that symmetry is preserved.
// FIXME kind of arbitrary
rr.maxWalkDistance = Math.min(request.maxWalkTime * 60 * request.walkSpeed, GraphIndex.MAX_WALK_METERS);
rr.softWalkLimiting = false;
rr.dominanceFunction = new DominanceFunction.LeastWalk();
}
}
rr.numItineraries = 1;
rr.longDistance = true;
AStar aStar = new AStar();
preTransitSpt = aStar.getShortestPathTree(rr, 5);
// otherwise return null and leave preTransitSpt around for later use.
if (data != null) {
TIntIntMap accessTimes = data.findStopsNear(preTransitSpt, graph, rr.modes.contains(TraverseMode.BICYCLE), request.walkSpeed);
LOG.info("Found {} transit stops", accessTimes.size());
return accessTimes;
} else {
return null;
}
}
use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.
the class ConvertToFrequencyTest method testBidirectional.
/**
* Test bidirectional conversion
*/
@Test
public void testBidirectional() throws Exception {
Graph gg = buildGraphNoTransit();
addTransitBidirectional(gg);
link(gg);
gg.index(new DefaultStreetVertexIndexFactory());
ProfileRequest pr2 = new ProfileRequest();
pr2.date = new LocalDate(2015, 6, 10);
pr2.fromTime = 7 * 3600;
pr2.toTime = 9 * 3600;
pr2.fromLat = pr2.toLat = 39.9621;
pr2.fromLon = pr2.toLon = -83.0007;
pr2.accessModes = pr2.egressModes = pr2.directModes = new QualifiedModeSet("WALK");
pr2.transitModes = new TraverseModeSet("TRANSIT");
ConvertToFrequency ctf = new ConvertToFrequency();
ctf.groupBy = ConvertToFrequency.ConversionGroup.ROUTE_DIRECTION;
ctf.routeId = new String[] { "route" };
ctf.windowStart = 5 * 3600;
ctf.windowEnd = 10 * 3600;
pr2.scenario = new Scenario(0);
pr2.scenario.modifications = Arrays.asList(ctf);
RepeatedRaptorProfileRouter rrpr2 = new RepeatedRaptorProfileRouter(gg, pr2);
rrpr2.route();
assertTrue(rrpr2.raptorWorkerData.hasFrequencies);
assertEquals(2, rrpr2.raptorWorkerData.timetablesForPattern.size());
// make sure we got trips in both directions
RaptorWorkerTimetable tt = rrpr2.raptorWorkerData.timetablesForPattern.get(0);
RaptorWorkerTimetable tt2 = rrpr2.raptorWorkerData.timetablesForPattern.get(1);
assertEquals(2, tt2.stopIndices.length);
assertEquals(2, tt.stopIndices.length);
assertEquals(tt.stopIndices[0], tt2.stopIndices[1]);
assertEquals(tt.stopIndices[1], tt2.stopIndices[0]);
}
use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.
the class TestBikeRental method testBasic.
public void testBasic() throws Exception {
// generate a very simple graph
Graph graph = new Graph();
StreetVertex v1 = new IntersectionVertex(graph, "v1", -77.0492, 38.856, "v1");
StreetVertex v2 = new IntersectionVertex(graph, "v2", -77.0492, 38.857, "v2");
StreetVertex v3 = new IntersectionVertex(graph, "v3", -77.0492, 38.858, "v3");
@SuppressWarnings("unused") Edge walk = new StreetEdge(v1, v2, GeometryUtils.makeLineString(-77.0492, 38.856, -77.0492, 38.857), "S. Crystal Dr", 87, StreetTraversalPermission.PEDESTRIAN, false);
@SuppressWarnings("unused") Edge mustBike = new StreetEdge(v2, v3, GeometryUtils.makeLineString(-77.0492, 38.857, -77.0492, 38.858), "S. Crystal Dr", 87, StreetTraversalPermission.BICYCLE, false);
AStar aStar = new AStar();
// it is impossible to get from v1 to v3 by walking
RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK,TRANSIT"));
options.setRoutingContext(graph, v1, v3);
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(v3, false);
assertNull(path);
// or biking + walking (assuming walking bikes is disallowed)
options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
options.freezeTraverseMode();
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
assertNull(path);
// so we add a bike share
BikeRentalStation station = new BikeRentalStation();
station.id = "id";
station.name = new NonLocalizedString("station");
station.x = -77.049;
station.y = 36.856;
station.bikesAvailable = 5;
station.spacesAvailable = 5;
BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
new StreetBikeRentalLink(stationVertex, v2);
new StreetBikeRentalLink(v2, stationVertex);
Set<String> networks = new HashSet<String>(Arrays.asList("default"));
new RentABikeOnEdge(stationVertex, stationVertex, networks);
new RentABikeOffEdge(stationVertex, stationVertex, networks);
// but we can't get off the bike at v3, so we still fail
options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
options.freezeTraverseMode();
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
// null is returned because the only state at the target is not final
assertNull(path);
BikeRentalStation station2 = new BikeRentalStation();
station2.id = "id2";
station2.name = new NonLocalizedString("station2");
station2.x = -77.049;
station2.y = 36.857;
station2.bikesAvailable = 5;
station2.spacesAvailable = 5;
BikeRentalStationVertex stationVertex2 = new BikeRentalStationVertex(graph, station2);
new StreetBikeRentalLink(stationVertex2, v3);
new StreetBikeRentalLink(v3, stationVertex2);
new RentABikeOnEdge(stationVertex2, stationVertex2, networks);
new RentABikeOffEdge(stationVertex2, stationVertex2, networks);
// now we succeed!
options = new RoutingRequest();
new QualifiedModeSet("BICYCLE_RENT,TRANSIT").applyToRoutingRequest(options);
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
assertNotNull(path);
}
use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.
the class InitialStopsTest method testInitialStopWalkSpeedIncrease.
/**
* Test that increasing the walk speed on a walk-to-transit search
* a) decreases or leaves unchanged all access times.
* b) allows access to a superset of the originally accessible stops.
* c) decreases at least some access times.
*
* There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
*/
@Test
public void testInitialStopWalkSpeedIncrease() throws Exception {
Graph g = buildGraphNoTransit();
addRegularStopGrid(g);
addTransitMultipleLines(g);
link(g);
g.index(new DefaultStreetVertexIndexFactory());
ProfileRequest req = new ProfileRequest();
req.fromLon = req.toLon = -83.0118;
req.fromLat = req.toLat = 39.9908;
req.date = new LocalDate(2015, 9, 17);
req.bikeSpeed = 4.1f;
req.walkSpeed = 1.3f;
req.fromTime = 7 * 3600;
req.toTime = 9 * 3600;
req.maxBikeTime = 20;
req.maxWalkTime = 20;
req.transitModes = new TraverseModeSet("TRANSIT");
req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("WALK");
RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
assertFalse(initialStops1.isEmpty());
// let's get crazy, set walk speed really high.
req.walkSpeed = 25f;
data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
// we should find decreases to at least some stops
boolean foundDecreases = false;
for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
it.advance();
// the reached stops from the faster search should be a superset of the reached stops from the slower search
assertTrue(initialStops2.containsKey(it.key()));
assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
}
assertTrue("No decreases were found due to increased walk speed", foundDecreases);
}
use of org.opentripplanner.api.parameter.QualifiedModeSet in project OpenTripPlanner by opentripplanner.
the class InitialStopsTest method testInitialStopBikeSpeedIncrease.
/**
* Test that increasing the bike speed on a bike-to-transit search
* a) decreases or leaves unchanged all access times.
* b) allows access to a superset of the originally accessible stops.
*
* There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
*/
@Test
public void testInitialStopBikeSpeedIncrease() throws Exception {
Graph g = buildGraphNoTransit();
addRegularStopGrid(g);
addTransitMultipleLines(g);
link(g);
g.index(new DefaultStreetVertexIndexFactory());
ProfileRequest req = new ProfileRequest();
req.fromLon = req.toLon = -83.0118;
req.fromLat = req.toLat = 39.9908;
req.date = new LocalDate(2015, 9, 17);
req.bikeSpeed = 4.1f;
req.walkSpeed = 1.3f;
req.fromTime = 7 * 3600;
req.toTime = 9 * 3600;
req.maxBikeTime = 20;
req.transitModes = new TraverseModeSet("TRANSIT");
req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("BICYCLE");
RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
assertFalse(initialStops1.isEmpty());
// let's get crazy, set bike speed really high.
req.bikeSpeed = 25f;
data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
// we should find decreases to at least some stops
boolean foundDecreases = false;
for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
it.advance();
// the reached stops from the faster search should be a superset of the reached stops from the slower search
assertTrue(initialStops2.containsKey(it.key()));
assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
}
assertTrue(foundDecreases);
}
Aggregations