use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class GtfsTest method plan.
public Leg[] plan(long dateTime, String fromVertex, String toVertex, String onTripId, boolean wheelchairAccessible, boolean preferLeastTransfers, TraverseMode preferredMode, String excludedRoute, String excludedStop, int legCount) {
final TraverseMode mode = preferredMode != null ? preferredMode : TraverseMode.TRANSIT;
RoutingRequest routingRequest = new RoutingRequest();
routingRequest.setNumItineraries(1);
routingRequest.setArriveBy(dateTime < 0);
routingRequest.dateTime = Math.abs(dateTime);
if (fromVertex != null && !fromVertex.isEmpty()) {
routingRequest.from = (new GenericLocation(null, feedId.getId() + ":" + fromVertex));
}
if (toVertex != null && !toVertex.isEmpty()) {
routingRequest.to = new GenericLocation(null, feedId.getId() + ":" + toVertex);
}
if (onTripId != null && !onTripId.isEmpty()) {
routingRequest.startingTransitTripId = (new AgencyAndId(feedId.getId(), onTripId));
}
routingRequest.setRoutingContext(graph);
routingRequest.setWheelchairAccessible(wheelchairAccessible);
routingRequest.transferPenalty = (preferLeastTransfers ? 300 : 0);
routingRequest.setModes(new TraverseModeSet(TraverseMode.WALK, mode));
// TODO route matcher still using underscores because it's quite nonstandard and should be eliminated from the 1.0 release rather than reworked
if (excludedRoute != null && !excludedRoute.isEmpty()) {
routingRequest.setBannedRoutes(feedId.getId() + "__" + excludedRoute);
}
if (excludedStop != null && !excludedStop.isEmpty()) {
routingRequest.setBannedStopsHard(feedId.getId() + ":" + excludedStop);
}
routingRequest.setOtherThanPreferredRoutesPenalty(0);
// The walk board cost is set low because it interferes with test 2c1.
// As long as boarding has a very low cost, waiting should not be "better" than riding
// since this makes interlining _worse_ than alighting and re-boarding the same line.
// TODO rethink whether it makes sense to weight waiting to board _less_ than 1.
routingRequest.setWaitReluctance(1);
routingRequest.setWalkBoardCost(30);
List<GraphPath> paths = new GraphPathFinder(router).getPaths(routingRequest);
TripPlan tripPlan = GraphPathToTripPlanConverter.generatePlan(paths, routingRequest);
// Stored in instance field for use in individual tests
itinerary = tripPlan.itinerary.get(0);
assertEquals(legCount, itinerary.legs.size());
return itinerary.legs.toArray(new Leg[legCount]);
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class AddTripPatternTest method testStopLinking.
/**
* Make sure that stops are properly linked into the graph
*/
@Test
public void testStopLinking() throws Exception {
AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
atp.timetables.add(getTimetable(true));
// get a graph
Graph g = buildGraphNoTransit();
link(g);
g.index(new DefaultStreetVertexIndexFactory());
// materialize the trip pattern
atp.materialize(g);
// there should be five stops because one point is not a stop
assertEquals(5, atp.temporaryStops.length);
// they should all be linked into the graph
for (int i = 0; i < atp.temporaryStops.length; i++) {
assertNotNull(atp.temporaryStops[i].sample);
assertNotNull(atp.temporaryStops[i].sample.v0);
assertNotNull(atp.temporaryStops[i].sample.v1);
}
// no services running: not needed for trips added on the fly.
TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, new BitSet(), DayOfWeek.WEDNESDAY);
Scenario scenario = new Scenario(0);
scenario.modifications = Lists.newArrayList(atp);
ProfileRequest req = new ProfileRequest();
req.scenario = scenario;
req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
RaptorWorkerData data = new RaptorWorkerData(g, window, req);
assertEquals(5, data.nStops);
// make sure we can find the stops
AStar aStar = new AStar();
RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
rr.from = new GenericLocation(39.963417, -82.980799);
rr.batch = true;
rr.setRoutingContext(g);
rr.batch = true;
ShortestPathTree spt = aStar.getShortestPathTree(rr);
TIntIntMap stops = data.findStopsNear(spt, g, false, 1.3f);
// we should have found stops
assertFalse(stops.isEmpty());
// ensure that the times made it into the data
// This assumes worst-case departure, and the first worst departure is 10:30 after the service
// starts running (dwell + headway)
assertEquals(4 * 3600 + 600 + 30, data.timetablesForPattern.get(0).getFrequencyDeparture(0, 0, 39 * 360, -1, null));
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class AddTripPatternTest method testTimetableTrips.
/**
* Test adding trips with a timetable rather than frequencies
*/
@Test
public void testTimetableTrips() throws Exception {
AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
atp.timetables.add(getTimetable(false));
// get a graph
Graph g = buildGraphNoTransit();
link(g);
g.index(new DefaultStreetVertexIndexFactory());
// materialize the trip pattern
atp.materialize(g);
// there should be five stops because one point is not a stop
assertEquals(5, atp.temporaryStops.length);
// they should all be linked into the graph
for (int i = 0; i < atp.temporaryStops.length; i++) {
assertNotNull(atp.temporaryStops[i].sample);
assertNotNull(atp.temporaryStops[i].sample.v0);
assertNotNull(atp.temporaryStops[i].sample.v1);
}
// no services running: not needed for trips added on the fly.
TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, new BitSet(), DayOfWeek.WEDNESDAY);
Scenario scenario = new Scenario(0);
scenario.modifications = Lists.newArrayList(atp);
ProfileRequest req = new ProfileRequest();
req.scenario = scenario;
req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
RaptorWorkerData data = new RaptorWorkerData(g, window, req);
assertEquals(5, data.nStops);
// make sure we can find the stops
AStar aStar = new AStar();
RoutingRequest rr = new RoutingRequest(TraverseMode.WALK);
rr.from = new GenericLocation(39.963417, -82.980799);
rr.batch = true;
rr.setRoutingContext(g);
rr.batch = true;
ShortestPathTree spt = aStar.getShortestPathTree(rr);
TIntIntMap stops = data.findStopsNear(spt, g, false, 1.3f);
// we should have found stops
assertFalse(stops.isEmpty());
// ensure that the times made it into the data
// This is after the first dwell time has been applied
assertEquals(7 * 3600 + 30, data.timetablesForPattern.get(0).getDeparture(0, 0));
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class AlertPatchTest method setUp.
public void setUp() throws Exception {
aStar = new AStar();
GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
options = new RoutingRequest();
graph = new Graph();
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
factory.run(graph);
graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
graph.index(new DefaultStreetVertexIndexFactory());
feedId = context.getFeedId().getId();
}
use of org.opentripplanner.routing.core.RoutingRequest in project OpenTripPlanner by opentripplanner.
the class TestAStar method testBasic.
public void testBasic() throws Exception {
GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.CALTRAIN_GTFS));
Graph gg = new Graph();
GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
factory.run(gg);
gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
RoutingRequest options = new RoutingRequest();
ShortestPathTree spt;
GraphPath path = null;
String feedId = gg.getFeedIds().iterator().next();
options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":Mountain View Caltrain"), true);
long endTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 13, 29, 0);
assertEquals(path.getEndTime(), endTime);
/* test backwards traversal */
options.setArriveBy(true);
options.dateTime = endTime;
options.setRoutingContext(gg, feedId + ":Millbrae Caltrain", feedId + ":Mountain View Caltrain");
spt = aStar.getShortestPathTree(options);
path = spt.getPath(gg.getVertex(feedId + ":Millbrae Caltrain"), true);
long expectedStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 39, 0);
assertTrue(path.getStartTime() - expectedStartTime <= 1);
}
Aggregations