use of org.opentripplanner.routing.spt.ShortestPathTree 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.spt.ShortestPathTree 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.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.
the class AlertPatchTest method testTimeRanges.
public void testTimeRanges() {
AlertPatch snp1 = new AlertPatch();
snp1.setFeedId(feedId);
LinkedList<TimePeriod> timePeriods = new LinkedList<TimePeriod>();
long breakTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
// until the beginning of the day
timePeriods.add(new TimePeriod(0, breakTime));
long secondPeriodStartTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 7, 0, 0);
long secondPeriodEndTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 8, 0, 0, 0);
timePeriods.add(new TimePeriod(secondPeriodStartTime, secondPeriodEndTime));
snp1.setTimePeriods(timePeriods);
Alert note1 = Alert.createSimpleAlerts("The first note");
snp1.setAlert(note1);
snp1.setId("id1");
snp1.setStop(new AgencyAndId(feedId, "A"));
snp1.apply(graph);
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_e = graph.getVertex(feedId + ":E_arrive");
ShortestPathTree spt;
GraphPath path;
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
options.setRoutingContext(graph, stop_a, stop_e);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_e, true);
assertNotNull(path);
// expect no notes because we are during the break
State noAlertPatchesState = path.states.get(1);
Edge noAlertPatchesEdge = noAlertPatchesState.getBackEdge();
HashSet<Alert> noAlertPatchesAlerts = new HashSet<Alert>();
for (AlertPatch alertPatch : graph.getAlertPatches(noAlertPatchesEdge)) {
if (alertPatch.displayDuring(noAlertPatchesState)) {
noAlertPatchesAlerts.add(alertPatch.getAlert());
}
}
assertEquals(new HashSet<Alert>(), noAlertPatchesAlerts);
// now a trip during the second period
options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 8, 0, 0);
options.setRoutingContext(graph, stop_a, stop_e);
spt = aStar.getShortestPathTree(options);
// do not optimize because we want the first trip
path = spt.getPath(stop_e, false);
assertNotNull(path);
HashSet<Alert> expectedNotes = new HashSet<Alert>();
expectedNotes.add(note1);
State oneAlertPatchState = path.states.get(1);
Edge oneAlertPatchEdge = oneAlertPatchState.getBackEdge();
HashSet<Alert> oneAlertPatchAlerts = new HashSet<Alert>();
for (AlertPatch alertPatch : graph.getAlertPatches(oneAlertPatchEdge)) {
if (alertPatch.displayDuring(oneAlertPatchState)) {
oneAlertPatchAlerts.add(alertPatch.getAlert());
}
}
assertEquals(expectedNotes, oneAlertPatchAlerts);
}
use of org.opentripplanner.routing.spt.ShortestPathTree in project OpenTripPlanner by opentripplanner.
the class AlertPatchTest method testRouteNotePatch.
public void testRouteNotePatch() {
AlertPatch rnp1 = new AlertPatch();
rnp1.setFeedId(feedId);
rnp1.setTimePeriods(Collections.singletonList(new TimePeriod(0, // until ~1/1/2011
1000L * 60 * 60 * 24 * 365 * 40)));
Alert note1 = Alert.createSimpleAlerts("The route note");
rnp1.setAlert(note1);
rnp1.setId("id1");
// Routes isn't patched in tests through GtfsBundle, which is why we have have a reference to agency id here.
rnp1.setRoute(new AgencyAndId("agency", "1"));
rnp1.apply(graph);
Vertex stop_a = graph.getVertex(feedId + ":A");
Vertex stop_e = graph.getVertex(feedId + ":E_arrive");
ShortestPathTree spt;
GraphPath path;
options.setRoutingContext(graph, stop_a, stop_e);
spt = aStar.getShortestPathTree(options);
path = spt.getPath(stop_e, false);
assertNotNull(path);
HashSet<Alert> expectedAlerts = new HashSet<Alert>();
expectedAlerts.add(note1);
Edge actualEdge = path.states.get(2).getBackEdge();
HashSet<Alert> actualAlerts = new HashSet<Alert>();
for (AlertPatch alertPatch : graph.getAlertPatches(actualEdge)) {
actualAlerts.add(alertPatch.getAlert());
}
assertEquals(expectedAlerts, actualAlerts);
}
use of org.opentripplanner.routing.spt.ShortestPathTree 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