Search in sources :

Example 71 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class GtfsGraphBuilderModuleTest method testNoBikesByDefault.

@Test
public void testNoBikesByDefault() throws IOException {
    // We configure two trip: one with unknown bikes_allowed and the second with bikes
    // allowed.
    MockGtfs gtfs = getSimpleGtfs();
    gtfs.putTrips(2, "r0", "sid0", "bikes_allowed=0,1");
    gtfs.putStopTimes("t0,t1", "s0,s1");
    List<GtfsBundle> bundleList = getGtfsAsBundleList(gtfs);
    bundleList.get(0).setDefaultBikesAllowed(false);
    builder = new GtfsModule(bundleList, ServiceDateInterval.unbounded());
    Graph graph = new Graph();
    builder.buildGraph(graph, _extra);
    graph.index();
    // 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.getTripForId().get(new FeedScopedId(feedId.getId(), "t0"));
    TripPattern pattern = graph.index.getPatternForTrip().get(trip);
    List<Trip> trips = pattern.getTrips();
    assertEquals(BikeAccess.UNKNOWN, BikeAccess.fromTrip(withId(trips, new FeedScopedId(feedId.getId(), "t0"))));
    assertEquals(BikeAccess.ALLOWED, BikeAccess.fromTrip(withId(trips, new FeedScopedId(feedId.getId(), "t1"))));
}
Also used : Trip(org.opentripplanner.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) MockGtfs(org.opentripplanner.gtfs.MockGtfs) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripPattern(org.opentripplanner.model.TripPattern) Test(org.junit.Test)

Example 72 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class RaptorRoutingRequestTransitDataCreatorTest method testMergeTripPatterns.

@Test
public void testMergeTripPatterns() {
    TripTimes[] times = new TripTimes[] { null };
    LocalDate first = LocalDate.of(2019, 3, 30);
    LocalDate second = LocalDate.of(2019, 3, 31);
    LocalDate third = LocalDate.of(2019, 4, 1);
    ZonedDateTime startOfTime = DateMapper.asStartOfService(second, ZoneId.of("Europe/London"));
    // Total available trip patterns
    TripPatternWithRaptorStopIndexes tripPattern1 = new TripPatternWithId(new FeedScopedId("", "1"), null, null);
    TripPatternWithRaptorStopIndexes tripPattern2 = new TripPatternWithId(new FeedScopedId("", "2"), null, null);
    TripPatternWithRaptorStopIndexes tripPattern3 = new TripPatternWithId(new FeedScopedId("", "3"), null, null);
    List<Map<FeedScopedId, TripPatternForDate>> tripPatternsForDates = new ArrayList<>();
    // TripPatterns valid for 1st day in search range
    Map<FeedScopedId, TripPatternForDate> tripPatternForDatesById = new HashMap<>();
    tripPatternForDatesById.put(tripPattern1.getId(), new TripPatternForDate(tripPattern1, times, first));
    tripPatternForDatesById.put(tripPattern2.getId(), new TripPatternForDate(tripPattern2, times, first));
    tripPatternForDatesById.put(tripPattern3.getId(), new TripPatternForDate(tripPattern1, times, first));
    tripPatternsForDates.add(tripPatternForDatesById);
    // TripPatterns valid for 2nd day in search range
    Map<FeedScopedId, TripPatternForDate> tripPatternForDatesById2 = new HashMap<>();
    tripPatternForDatesById2.put(tripPattern2.getId(), new TripPatternForDate(tripPattern2, times, second));
    tripPatternForDatesById2.put(tripPattern3.getId(), new TripPatternForDate(tripPattern3, times, second));
    tripPatternsForDates.add(tripPatternForDatesById2);
    // TripPatterns valid for 3rd day in search range
    Map<FeedScopedId, TripPatternForDate> tripPatternForDatesById3 = new HashMap<>();
    tripPatternForDatesById3.put(tripPattern1.getId(), new TripPatternForDate(tripPattern1, times, third));
    tripPatternForDatesById3.put(tripPattern3.getId(), new TripPatternForDate(tripPattern3, times, third));
    tripPatternsForDates.add(tripPatternForDatesById3);
    // Patterns containing trip schedules for all 3 days. Trip schedules for later days are offset in time when requested.
    List<TripPatternForDates> combinedTripPatterns = RaptorRoutingRequestTransitDataCreator.merge(startOfTime, tripPatternsForDates);
    // Check the number of trip schedules available for each pattern after combining dates in the search range
    assertEquals(2, combinedTripPatterns.get(0).numberOfTripSchedules());
    assertEquals(2, combinedTripPatterns.get(1).numberOfTripSchedules());
    assertEquals(3, combinedTripPatterns.get(2).numberOfTripSchedules());
    // Verify that the per-day offsets were calculated correctly
    // DST - Clocks go forward on March 31st
    assertEquals(-82800, ((TripScheduleWithOffset) combinedTripPatterns.get(2).getTripSchedule(0)).getSecondsOffset());
    assertEquals(0, ((TripScheduleWithOffset) combinedTripPatterns.get(2).getTripSchedule(1)).getSecondsOffset());
    assertEquals(86400, ((TripScheduleWithOffset) combinedTripPatterns.get(2).getTripSchedule(2)).getSecondsOffset());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) TripPatternForDate(org.opentripplanner.routing.algorithm.raptor.transit.TripPatternForDate) ZonedDateTime(java.time.ZonedDateTime) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) FeedScopedId(org.opentripplanner.model.FeedScopedId) TripPatternWithRaptorStopIndexes(org.opentripplanner.routing.algorithm.raptor.transit.TripPatternWithRaptorStopIndexes) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 73 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class RoutingServiceTest method testIdLookup.

public void testIdLookup() {
    /* Graph vertices */
    for (Vertex vertex : graph.getVertices()) {
        if (vertex instanceof TransitStopVertex) {
            Stop stop = ((TransitStopVertex) vertex).getStop();
            Vertex index_vertex = graph.index.getStopVertexForStop().get(stop);
            assertEquals(index_vertex, vertex);
        }
    }
    /* Agencies */
    String feedId = graph.getFeedIds().iterator().next();
    Agency agency;
    agency = graph.index.getAgencyForId(new FeedScopedId(feedId, "azerty"));
    assertNull(agency);
    agency = graph.index.getAgencyForId(new FeedScopedId(feedId, "agency"));
    assertEquals(agency.getId().toString(), feedId + ":" + "agency");
    assertEquals(agency.getName(), "Fake Agency");
    /* Stops */
    graph.index.getStopForId(new FeedScopedId("X", "Y"));
/* Trips */
// graph.index.tripForId;
// graph.index.routeForId;
// graph.index.serviceForId;
// graph.index.patternForId;
}
Also used : TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) Agency(org.opentripplanner.model.Agency) Stop(org.opentripplanner.model.Stop) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) FeedScopedId(org.opentripplanner.model.FeedScopedId)

Example 74 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class RoutingServiceTest method testSpatialIndex.

public void testSpatialIndex() {
    String feedId = graph.getFeedIds().iterator().next();
    Stop stopJ = graph.index.getStopForId(new FeedScopedId(feedId, "J"));
    Stop stopL = graph.index.getStopForId(new FeedScopedId(feedId, "L"));
    Stop stopM = graph.index.getStopForId(new FeedScopedId(feedId, "M"));
    TransitStopVertex stopvJ = graph.index.getStopVertexForStop().get(stopJ);
    TransitStopVertex stopvL = graph.index.getStopVertexForStop().get(stopL);
    TransitStopVertex stopvM = graph.index.getStopVertexForStop().get(stopM);
    // There are a two other stops within 100 meters of stop J.
    Envelope env = new Envelope(new Coordinate(stopJ.getLon(), stopJ.getLat()));
    env.expandBy(SphericalDistanceLibrary.metersToLonDegrees(100, stopJ.getLat()), SphericalDistanceLibrary.metersToDegrees(100));
    List<TransitStopVertex> stops = graph.index.getStopSpatialIndex().query(env);
    assertTrue(stops.contains(stopvJ));
    assertTrue(stops.contains(stopvL));
    assertTrue(stops.contains(stopvM));
    // Query can overselect
    assertTrue(stops.size() >= 3);
}
Also used : Stop(org.opentripplanner.model.Stop) Coordinate(org.locationtech.jts.geom.Coordinate) TransitStopVertex(org.opentripplanner.routing.vertextype.TransitStopVertex) FeedScopedId(org.opentripplanner.model.FeedScopedId) Envelope(org.locationtech.jts.geom.Envelope)

Example 75 with FeedScopedId

use of org.opentripplanner.model.FeedScopedId in project OpenTripPlanner by opentripplanner.

the class TestFares method testFareComponent.

public void testFareComponent() throws Exception {
    Graph gg = new Graph();
    GtfsContext context = contextBuilder(ConstantsForTests.FARE_COMPONENT_GTFS).build();
    GeometryAndBlockProcessor factory = new GeometryAndBlockProcessor(context);
    factory.run(gg);
    gg.putService(CalendarServiceData.class, context.getCalendarServiceData());
    String feedId = gg.getFeedIds().iterator().next();
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/Los_Angeles", 2009, 8, 7, 12, 0, 0);
    ShortestPathTree spt;
    GraphPath path;
    Fare fare;
    List<FareComponent> fareComponents = null;
    FareService fareService = gg.getService(FareService.class);
    Money tenUSD = new Money(new WrappedCurrency("USD"), 1000);
    // A -> B, base case
    options.setRoutingContext(gg, feedId + ":A", feedId + ":B");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":B"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
    // D -> E, null case
    options.setRoutingContext(gg, feedId + ":D", feedId + ":E");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":E"), true);
    // was: fareService.getCost(path);
    fare = null;
    assertNull(fare);
    // A -> C, 2 components in a path
    options.setRoutingContext(gg, feedId + ":A", feedId + ":C");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":C"), true);
    // was:  fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 2);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
    assertEquals(fareComponents.get(1).price, tenUSD);
    assertEquals(fareComponents.get(1).fareId, new FeedScopedId(feedId, "BC"));
    assertEquals(fareComponents.get(1).routes.get(0), new FeedScopedId("agency", "2"));
    // B -> D, 2 fully connected components
    options.setRoutingContext(gg, feedId + ":B", feedId + ":D");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":D"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "BD"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "2"));
    assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "3"));
    // E -> G, missing in between fare
    options.setRoutingContext(gg, feedId + ":E", feedId + ":G");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":G"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "EG"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "5"));
    assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "6"));
    // C -> E, missing fare after
    options.setRoutingContext(gg, feedId + ":C", feedId + ":E");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":E"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "CD"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "3"));
    // D -> G, missing fare before
    options.setRoutingContext(gg, feedId + ":D", feedId + ":G");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":G"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 1);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "EG"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "5"));
    assertEquals(fareComponents.get(0).routes.get(1), new FeedScopedId("agency", "6"));
    // A -> D, use individual component parts
    options.setRoutingContext(gg, feedId + ":A", feedId + ":D");
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(feedId + ":D"), true);
    // was: fareService.getCost(path);
    fare = null;
    fareComponents = fare.getDetails(FareType.regular);
    assertEquals(fareComponents.size(), 2);
    assertEquals(fareComponents.get(0).price, tenUSD);
    assertEquals(fareComponents.get(0).fareId, new FeedScopedId(feedId, "AB"));
    assertEquals(fareComponents.get(0).routes.get(0), new FeedScopedId("agency", "1"));
    assertEquals(fareComponents.get(1).price, tenUSD);
    assertEquals(fareComponents.get(1).fareId, new FeedScopedId(feedId, "BD"));
    assertEquals(fareComponents.get(1).routes.get(0), new FeedScopedId("agency", "2"));
    assertEquals(fareComponents.get(1).routes.get(1), new FeedScopedId("agency", "3"));
}
Also used : GeometryAndBlockProcessor(org.opentripplanner.graph_builder.module.geometry.GeometryAndBlockProcessor) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) FareService(org.opentripplanner.routing.services.FareService) Fare(org.opentripplanner.routing.core.Fare) Money(org.opentripplanner.routing.core.Money) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) FeedScopedId(org.opentripplanner.model.FeedScopedId) RoutingRequest(org.opentripplanner.routing.api.request.RoutingRequest) FareComponent(org.opentripplanner.routing.core.FareComponent)

Aggregations

FeedScopedId (org.opentripplanner.model.FeedScopedId)117 Trip (org.opentripplanner.model.Trip)32 Test (org.junit.Test)29 Stop (org.opentripplanner.model.Stop)25 TripPattern (org.opentripplanner.model.TripPattern)25 ServiceDate (org.opentripplanner.model.calendar.ServiceDate)21 ArrayList (java.util.ArrayList)20 Route (org.opentripplanner.model.Route)15 HashSet (java.util.HashSet)11 List (java.util.List)11 Agency (org.opentripplanner.model.Agency)11 Collection (java.util.Collection)9 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 ZonedDateTime (java.time.ZonedDateTime)8 TransitEntity (org.opentripplanner.model.TransitEntity)8 RoutingService (org.opentripplanner.routing.RoutingService)8 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)8 Notice (org.opentripplanner.model.Notice)7 Station (org.opentripplanner.model.Station)7