use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class GraphPathToTripPlanConverterTest method testEmptyGraphPath.
/**
* Test that empty graph paths throw a TrivialPathException
*/
@Test(expected = TrivialPathException.class)
public void testEmptyGraphPath() {
RoutingRequest options = new RoutingRequest();
Graph graph = new Graph();
ExitVertex vertex = new ExitVertex(graph, "Vertex", 0, 0, 0);
options.rctx = new RoutingContext(options, graph, vertex, vertex);
GraphPath graphPath = new GraphPath(new State(options), false);
GraphPathToTripPlanConverter.generateItinerary(graphPath, false, false, locale);
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class GtfsTest method setUp.
protected void setUp() {
File gtfs = new File("src/test/resources/" + getFeedName());
File gtfsRealTime = new File("src/test/resources/" + getFeedName() + ".pb");
GtfsBundle gtfsBundle = new GtfsBundle(gtfs);
feedId = new GtfsFeedId.Builder().id("FEED").build();
gtfsBundle.setFeedId(feedId);
List<GtfsBundle> gtfsBundleList = Collections.singletonList(gtfsBundle);
GtfsModule gtfsGraphBuilderImpl = new GtfsModule(gtfsBundleList);
alertsUpdateHandler = new AlertsUpdateHandler();
graph = new Graph();
router = new Router("TEST", graph);
gtfsBundle.setTransfersTxtDefinesStationPaths(true);
gtfsGraphBuilderImpl.buildGraph(graph, null);
// Set the agency ID to be used for tests to the first one in the feed.
agencyId = graph.getAgencies(feedId.getId()).iterator().next().getId();
System.out.printf("Set the agency ID for this test to %s\n", agencyId);
graph.index(new DefaultStreetVertexIndexFactory());
timetableSnapshotSource = new TimetableSnapshotSource(graph);
timetableSnapshotSource.purgeExpiredData = (false);
graph.timetableSnapshotSource = (timetableSnapshotSource);
alertPatchServiceImpl = new AlertPatchServiceImpl(graph);
alertsUpdateHandler.setAlertPatchService(alertPatchServiceImpl);
alertsUpdateHandler.setFeedId(feedId.getId());
try {
final boolean fullDataset = false;
InputStream inputStream = new FileInputStream(gtfsRealTime);
FeedMessage feedMessage = FeedMessage.PARSER.parseFrom(inputStream);
List<FeedEntity> feedEntityList = feedMessage.getEntityList();
List<TripUpdate> updates = new ArrayList<TripUpdate>(feedEntityList.size());
for (FeedEntity feedEntity : feedEntityList) {
updates.add(feedEntity.getTripUpdate());
}
timetableSnapshotSource.applyTripUpdates(graph, fullDataset, updates, feedId.getId());
alertsUpdateHandler.update(feedMessage);
} catch (Exception exception) {
}
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class AddTripPatternTest method testTransfers.
/**
* Make sure that transfers work
*/
@Test
public void testTransfers() throws Exception {
AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
atp.timetables.add(getTimetable(false));
AddTripPattern atp2 = getAddTripPattern(RouteSelector.BEXLEY_CMH);
atp2.timetables.add(getTimetable(true));
// get a graph
Graph g = buildGraphNoTransit();
addTransit(g);
link(g);
g.index(new DefaultStreetVertexIndexFactory());
// materialize the trip pattern
atp.materialize(g);
atp2.materialize(g);
TimeWindow window = new TimeWindow(7 * 3600, 9 * 3600, g.index.servicesRunning(new LocalDate(2015, 6, 10)), DayOfWeek.WEDNESDAY);
Scenario scenario = new Scenario(0);
scenario.modifications = Lists.newArrayList(atp, atp2);
ProfileRequest req = new ProfileRequest();
req.scenario = scenario;
req.boardingAssumption = RaptorWorkerTimetable.BoardingAssumption.WORST_CASE;
RaptorWorkerData data = new RaptorWorkerData(g, window, req);
// make sure that we have transfers a) between the new lines b) from the new lines
// to the existing lines c) from the existing lines to the new lines
// stop IDs in the data will be 0 and 1 for existing stops, 2 - 6 for Broad/High and 7 - 11 for Bexley/CMH
int[] txFromExisting = data.transfersForStop.get(0);
if (txFromExisting.length == 0)
txFromExisting = data.transfersForStop.get(1);
// make sure there's a transfer to stop 4 (Broad/High)
// the AddTripPattern instructions are processed in order
// also recall that each transfer has two ints in the array as it's a jagged array of
// dest_pattern, distance
assertTrue(txFromExisting.length > 0);
boolean foundTx = false;
for (int i = 0; i < txFromExisting.length; i += 2) {
if (txFromExisting[i] == 4) {
foundTx = true;
break;
}
}
assertTrue("transfer from existing to new", foundTx);
// Check that there are transfers from the new route to the existing route
// This is the stop at Broad and High
int[] txToExisting = data.transfersForStop.get(4);
assertTrue(txToExisting.length > 0);
foundTx = false;
for (int i = 0; i < txToExisting.length; i += 2) {
if (txToExisting[i] == 0 || txToExisting[i] == 1) {
// stop from existing route
foundTx = true;
break;
}
}
assertTrue("transfer from new to existing", foundTx);
// Check that there are transfers between the new routes
int[] txBetweenNew = data.transfersForStop.get(7);
assertTrue(txBetweenNew.length > 0);
foundTx = false;
for (int i = 0; i < txBetweenNew.length; i += 2) {
if (txBetweenNew[i] == 2) {
foundTx = true;
break;
}
}
assertTrue(foundTx);
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class AddTripPatternTest method integrationTest.
/**
* Test the full routing
*/
@Test
public void integrationTest() throws Exception {
Graph g = buildGraphNoTransit();
addTransit(g);
link(g);
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;
RepeatedRaptorProfileRouter rrpr1 = new RepeatedRaptorProfileRouter(g, 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;
AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
atp.timetables.add(getTimetable(true));
pr2.scenario = new Scenario(0);
pr2.scenario.modifications = Arrays.asList(atp);
RepeatedRaptorProfileRouter rrpr2 = new RepeatedRaptorProfileRouter(g, pr2);
rrpr2.route();
boolean foundDecrease = false;
// make sure that travel time did not increase
for (TObjectIntIterator<Vertex> vit = rrpr1.timeSurfaceRangeSet.min.times.iterator(); vit.hasNext(); ) {
vit.advance();
int time2 = rrpr2.timeSurfaceRangeSet.min.getTime(vit.key());
assertTrue(time2 <= vit.value());
if (time2 < vit.value())
foundDecrease = true;
}
assertTrue("found decreases in travel time due to adding route", foundDecrease);
}
use of org.opentripplanner.routing.graph.Graph in project OpenTripPlanner by opentripplanner.
the class RoutersTest method getRouterInfoReturnsFirstAndLastValidDateForGraph.
@Test
public void getRouterInfoReturnsFirstAndLastValidDateForGraph() {
final CalendarServiceData calendarService = new CalendarServiceData();
final List<ServiceDate> serviceDates = new ArrayList<ServiceDate>() {
{
add(new ServiceDate(2015, 10, 1));
add(new ServiceDate(2015, 11, 1));
}
};
calendarService.putServiceDatesForServiceId(new AgencyAndId("NA", "1"), serviceDates);
final Graph graph = new Graph();
graph.updateTransitFeedValidity(calendarService);
graph.expandToInclude(0, 100);
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", graph));
Routers routerApi = new Routers();
routerApi.otpServer = otpServer;
RouterInfo info = routerApi.getGraphId("A");
assertNotNull(info.transitServiceStarts);
assertNotNull(info.transitServiceEnds);
assertTrue(info.transitServiceStarts < info.transitServiceEnds);
}
Aggregations