Search in sources :

Example 56 with Graph

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);
}
Also used : ExitVertex(org.opentripplanner.routing.vertextype.ExitVertex) RoutingContext(org.opentripplanner.routing.core.RoutingContext) Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 57 with Graph

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) {
    }
}
Also used : TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Router(org.opentripplanner.standalone.Router) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) AlertPatchServiceImpl(org.opentripplanner.routing.impl.AlertPatchServiceImpl) FileInputStream(java.io.FileInputStream) FeedMessage(com.google.transit.realtime.GtfsRealtime.FeedMessage) GtfsModule(org.opentripplanner.graph_builder.module.GtfsModule) Graph(org.opentripplanner.routing.graph.Graph) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) FeedEntity(com.google.transit.realtime.GtfsRealtime.FeedEntity) File(java.io.File) TimetableSnapshotSource(org.opentripplanner.updater.stoptime.TimetableSnapshotSource) AlertsUpdateHandler(org.opentripplanner.updater.alerts.AlertsUpdateHandler)

Example 58 with Graph

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);
}
Also used : FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 59 with Graph

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);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 60 with Graph

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);
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) GraphService(org.opentripplanner.routing.services.GraphService) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) OTPServer(org.opentripplanner.standalone.OTPServer) MemoryGraphSource(org.opentripplanner.routing.impl.MemoryGraphSource) RouterInfo(org.opentripplanner.api.model.RouterInfo) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Graph (org.opentripplanner.routing.graph.Graph)105 Test (org.junit.Test)39 File (java.io.File)28 Vertex (org.opentripplanner.routing.graph.Vertex)27 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)24 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)20 Edge (org.opentripplanner.routing.graph.Edge)19 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)19 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)19 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)14 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)14 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)13 GTFSPatternHopFactory (org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory)13 GraphPath (org.opentripplanner.routing.spt.GraphPath)13 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)13 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)11 ArrayList (java.util.ArrayList)10 Before (org.junit.Before)10 Trip (org.onebusaway.gtfs.model.Trip)9