use of org.opentripplanner.routing.graph.Graph 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.graph.Graph in project OpenTripPlanner by opentripplanner.
the class RoutersTest method testRouters.
@Test
public void testRouters() {
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("", new MemoryGraphSource(null, new Graph()));
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("", new Graph()));
otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "A", 0, 0, 0));
otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "B", 0, 1, 0));
otpServer.getGraphService().getRouter("A").graph.addVertex(new ExitVertex(null, "C", 1, 1, 0));
// this needs to be added since convex hull isn't lazy loaded anymore
otpServer.getGraphService().getRouter("A").graph.calculateConvexHull();
otpServer.getGraphService().getRouter("").graph.calculateConvexHull();
// this needs to be added since it is otherwise calculated during OSM/Transit loading
// which doesn't happen in this test
otpServer.getGraphService().getRouter("A").graph.calculateEnvelope();
otpServer.getGraphService().getRouter("").graph.calculateEnvelope();
Routers routerApi = new Routers();
routerApi.otpServer = otpServer;
RouterList routers = routerApi.getRouterIds();
assertEquals(2, routers.routerInfo.size());
RouterInfo router0 = routers.routerInfo.get(0);
RouterInfo router1 = routers.routerInfo.get(1);
RouterInfo otherRouter;
RouterInfo defaultRouter;
if (router0.routerId.equals("")) {
defaultRouter = router0;
otherRouter = router1;
} else {
defaultRouter = router1;
otherRouter = router0;
}
assertEquals("", defaultRouter.routerId);
assertEquals("A", otherRouter.routerId);
assertTrue(otherRouter.polygon.getArea() > 0);
}
use of org.opentripplanner.routing.graph.Graph 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.graph.Graph 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);
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class ConvertToFrequencyTest method testSimpleConversion.
/**
* The simplest case of frequency conversion: no weird loop routes or anything like that, travel times always same, etc.
*/
@Test
public void testSimpleConversion() throws Exception {
Graph gg = buildGraphNoTransit();
addTransit(gg);
link(gg);
gg.index(new DefaultStreetVertexIndexFactory());
ProfileRequest pr1 = new ProfileRequest();
pr1.date = new LocalDate(2015, 6, 10);
pr1.fromTime = 7 * 3600;
pr1.toTime = 9 * 3600;
pr1.fromLat = pr1.toLat = 39.9621;
pr1.fromLon = pr1.toLon = -83.0007;
pr1.accessModes = pr1.egressModes = pr1.directModes = new QualifiedModeSet("WALK");
pr1.transitModes = new TraverseModeSet("TRANSIT");
RepeatedRaptorProfileRouter rrpr1 = new RepeatedRaptorProfileRouter(gg, pr1);
rrpr1.route();
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();
assertFalse(rrpr1.raptorWorkerData.hasFrequencies);
assertTrue(rrpr2.raptorWorkerData.hasFrequencies);
RaptorWorkerTimetable tt = rrpr2.raptorWorkerData.timetablesForPattern.get(0);
assertEquals(FakeGraph.FREQUENCY, tt.headwaySecs[0]);
assertEquals(FakeGraph.TRAVEL_TIME, tt.frequencyTrips[0][2]);
}
Aggregations