Search in sources :

Example 6 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.

the class GtfsGraphBuilderModuleTest method testBikesByDefault.

@Test
public void testBikesByDefault() throws IOException {
    // We configure two trip: one with unknown bikes_allowed and the second with no bikes
    // allowed.
    MockGtfs gtfs = getSimpleGtfs();
    gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,2");
    gtfs.putStopTimes("t0,t1", "s0,s1");
    List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
    bundleList.get(0).setDefaultBikesAllowed(true);
    _builder = new GtfsModule(bundleList);
    Graph graph = new Graph();
    _builder.buildGraph(graph, _extra);
    graph.index(new DefaultStreetVertexIndexFactory());
    // Feed id is used instead of the agency id for OBA entities.
    GtfsBundle gtfsBundle = bundleList.get(0);
    GtfsFeedId feedId = gtfsBundle.getFeedId();
    Trip trip = graph.index.tripForId.get(new AgencyAndId(feedId.getId(), "t0"));
    TripPattern pattern = graph.index.patternForTrip.get(trip);
    List<Trip> trips = pattern.getTrips();
    assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t0"))));
    assertEquals(BikeAccess.NOT_ALLOWED, BikeAccess.fromTrip(withId(trips, new AgencyAndId(feedId.getId(), "t1"))));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Test(org.junit.Test)

Example 7 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.

the class ConvertToFrequencyTest method testBidirectional.

/**
 * Test bidirectional conversion
 */
@Test
public void testBidirectional() throws Exception {
    Graph gg = buildGraphNoTransit();
    addTransitBidirectional(gg);
    link(gg);
    gg.index(new DefaultStreetVertexIndexFactory());
    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();
    assertTrue(rrpr2.raptorWorkerData.hasFrequencies);
    assertEquals(2, rrpr2.raptorWorkerData.timetablesForPattern.size());
    // make sure we got trips in both directions
    RaptorWorkerTimetable tt = rrpr2.raptorWorkerData.timetablesForPattern.get(0);
    RaptorWorkerTimetable tt2 = rrpr2.raptorWorkerData.timetablesForPattern.get(1);
    assertEquals(2, tt2.stopIndices.length);
    assertEquals(2, tt.stopIndices.length);
    assertEquals(tt.stopIndices[0], tt2.stopIndices[1]);
    assertEquals(tt.stopIndices[1], tt2.stopIndices[0]);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) ConvertToFrequency(org.opentripplanner.analyst.scenario.ConvertToFrequency) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) RaptorWorkerTimetable(org.opentripplanner.profile.RaptorWorkerTimetable) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) Scenario(org.opentripplanner.analyst.scenario.Scenario) Test(org.junit.Test)

Example 8 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.

the class InitialStopsTest method testInitialStopWalkSpeedIncrease.

/**
 * Test that increasing the walk speed on a walk-to-transit search
 * a) decreases or leaves unchanged all access times.
 * b) allows access to a superset of the originally accessible stops.
 * c) decreases at least some access times.
 *
 * There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
 */
@Test
public void testInitialStopWalkSpeedIncrease() throws Exception {
    Graph g = buildGraphNoTransit();
    addRegularStopGrid(g);
    addTransitMultipleLines(g);
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    ProfileRequest req = new ProfileRequest();
    req.fromLon = req.toLon = -83.0118;
    req.fromLat = req.toLat = 39.9908;
    req.date = new LocalDate(2015, 9, 17);
    req.bikeSpeed = 4.1f;
    req.walkSpeed = 1.3f;
    req.fromTime = 7 * 3600;
    req.toTime = 9 * 3600;
    req.maxBikeTime = 20;
    req.maxWalkTime = 20;
    req.transitModes = new TraverseModeSet("TRANSIT");
    req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("WALK");
    RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
    assertNotNull(data);
    RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
    TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
    assertFalse(initialStops1.isEmpty());
    // let's get crazy, set walk speed really high.
    req.walkSpeed = 25f;
    data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
    assertNotNull(data);
    rrpr = new RepeatedRaptorProfileRouter(g, req);
    TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
    // we should find decreases to at least some stops
    boolean foundDecreases = false;
    for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
        it.advance();
        // the reached stops from the faster search should be a superset of the reached stops from the slower search
        assertTrue(initialStops2.containsKey(it.key()));
        assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
        foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
    }
    assertTrue("No decreases were found due to increased walk speed", foundDecreases);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) TIntIntIterator(gnu.trove.iterator.TIntIntIterator) TaskStatistics(org.opentripplanner.analyst.cluster.TaskStatistics) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) RaptorWorkerData(org.opentripplanner.profile.RaptorWorkerData) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) TIntIntMap(gnu.trove.map.TIntIntMap) Test(org.junit.Test)

Example 9 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory in project OpenTripPlanner by opentripplanner.

the class InitialStopsTest method testInitialStopBikeSpeedIncrease.

/**
 * Test that increasing the bike speed on a bike-to-transit search
 * a) decreases or leaves unchanged all access times.
 * b) allows access to a superset of the originally accessible stops.
 *
 * There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
 */
@Test
public void testInitialStopBikeSpeedIncrease() throws Exception {
    Graph g = buildGraphNoTransit();
    addRegularStopGrid(g);
    addTransitMultipleLines(g);
    link(g);
    g.index(new DefaultStreetVertexIndexFactory());
    ProfileRequest req = new ProfileRequest();
    req.fromLon = req.toLon = -83.0118;
    req.fromLat = req.toLat = 39.9908;
    req.date = new LocalDate(2015, 9, 17);
    req.bikeSpeed = 4.1f;
    req.walkSpeed = 1.3f;
    req.fromTime = 7 * 3600;
    req.toTime = 9 * 3600;
    req.maxBikeTime = 20;
    req.transitModes = new TraverseModeSet("TRANSIT");
    req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("BICYCLE");
    RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
    assertNotNull(data);
    RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
    TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
    assertFalse(initialStops1.isEmpty());
    // let's get crazy, set bike speed really high.
    req.bikeSpeed = 25f;
    data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
    assertNotNull(data);
    rrpr = new RepeatedRaptorProfileRouter(g, req);
    TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
    // we should find decreases to at least some stops
    boolean foundDecreases = false;
    for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
        it.advance();
        // the reached stops from the faster search should be a superset of the reached stops from the slower search
        assertTrue(initialStops2.containsKey(it.key()));
        assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
        foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
    }
    assertTrue(foundDecreases);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) TIntIntIterator(gnu.trove.iterator.TIntIntIterator) TaskStatistics(org.opentripplanner.analyst.cluster.TaskStatistics) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) RaptorWorkerData(org.opentripplanner.profile.RaptorWorkerData) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) TIntIntMap(gnu.trove.map.TIntIntMap) Test(org.junit.Test)

Example 10 with DefaultStreetVertexIndexFactory

use of org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory 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)

Aggregations

DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)21 Graph (org.opentripplanner.routing.graph.Graph)19 Test (org.junit.Test)11 FakeGraph (org.opentripplanner.graph_builder.module.FakeGraph)10 LocalDate (org.joda.time.LocalDate)6 File (java.io.File)5 QualifiedModeSet (org.opentripplanner.api.parameter.QualifiedModeSet)5 GraphBuilder (org.opentripplanner.graph_builder.GraphBuilder)5 ProfileRequest (org.opentripplanner.profile.ProfileRequest)5 RepeatedRaptorProfileRouter (org.opentripplanner.profile.RepeatedRaptorProfileRouter)5 TraverseModeSet (org.opentripplanner.routing.core.TraverseModeSet)5 TIntIntMap (gnu.trove.map.TIntIntMap)4 CommandLineParameters (org.opentripplanner.standalone.CommandLineParameters)4 GtfsBundle (org.opentripplanner.graph_builder.model.GtfsBundle)3 AStar (org.opentripplanner.routing.algorithm.AStar)3 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)3 Router (org.opentripplanner.standalone.Router)3 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)2 LineString (com.vividsolutions.jts.geom.LineString)2 TIntIntIterator (gnu.trove.iterator.TIntIntIterator)2