Search in sources :

Example 1 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class GtfsModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    // we're about to add another agency to the graph, so clear the cached timezone
    // in case it should change
    // OTP doesn't currently support multiple time zones in a single graph;
    // at least this way we catch the error and log it instead of silently ignoring
    // because the time zone from the first agency is cached
    graph.clearTimeZone();
    MultiCalendarServiceImpl service = new MultiCalendarServiceImpl();
    GtfsStopContext stopContext = new GtfsStopContext();
    try {
        for (GtfsBundle gtfsBundle : gtfsBundles) {
            // apply global defaults to individual GTFSBundles (if globals have been set)
            if (cacheDirectory != null && gtfsBundle.cacheDirectory == null)
                gtfsBundle.cacheDirectory = cacheDirectory;
            if (useCached != null && gtfsBundle.useCached == null)
                gtfsBundle.useCached = useCached;
            GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
            GtfsContext context = GtfsLibrary.createContext(gtfsBundle.getFeedId(), dao, service);
            GTFSPatternHopFactory hf = new GTFSPatternHopFactory(context);
            hf.setStopContext(stopContext);
            hf.setFareServiceFactory(_fareServiceFactory);
            hf.setMaxStopToShapeSnapDistance(gtfsBundle.getMaxStopToShapeSnapDistance());
            loadBundle(gtfsBundle, graph, dao);
            CalendarServiceDataFactoryImpl csfactory = new CalendarServiceDataFactoryImpl();
            csfactory.setGtfsDao(dao);
            CalendarServiceData data = csfactory.createData();
            service.addData(data, dao);
            hf.subwayAccessTime = gtfsBundle.subwayAccessTime;
            hf.maxInterlineDistance = gtfsBundle.maxInterlineDistance;
            hf.run(graph);
            if (gtfsBundle.doesTransfersTxtDefineStationPaths()) {
                hf.createTransfersTxtTransfers();
            }
            if (gtfsBundle.linkStopsToParentStations) {
                hf.linkStopsToParentStations(graph);
            }
            if (gtfsBundle.parentStationTransfers) {
                hf.createParentStationTransfers();
            }
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    // We need to save the calendar service data so we can use it later
    CalendarServiceData data = service.getData();
    graph.putService(CalendarServiceData.class, data);
    graph.updateTransitFeedValidity(data);
    graph.hasTransit = true;
    graph.calculateTransitCenter();
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) GtfsBundle(org.opentripplanner.graph_builder.model.GtfsBundle) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GtfsStopContext(org.opentripplanner.routing.edgetype.factory.GtfsStopContext) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) IOException(java.io.IOException) CalendarServiceDataFactoryImpl(org.opentripplanner.calendar.impl.CalendarServiceDataFactoryImpl) MultiCalendarServiceImpl(org.opentripplanner.calendar.impl.MultiCalendarServiceImpl)

Example 2 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TimetableSnapshotSourceTest method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    GtfsRelationalDao dao = context.getDao();
    feedId = context.getFeedId().getId();
    for (ShapePoint shapePoint : dao.getAllEntitiesForType(ShapePoint.class)) {
        shapePoint.getShapeId().setAgencyId(feedId);
    }
    for (Route route : dao.getAllEntitiesForType(Route.class)) {
        route.getId().setAgencyId(feedId);
    }
    for (Stop stop : dao.getAllEntitiesForType(Stop.class)) {
        stop.getId().setAgencyId(feedId);
    }
    for (Trip trip : dao.getAllEntitiesForType(Trip.class)) {
        trip.getId().setAgencyId(feedId);
    }
    for (ServiceCalendar serviceCalendar : dao.getAllEntitiesForType(ServiceCalendar.class)) {
        serviceCalendar.getServiceId().setAgencyId(feedId);
    }
    for (ServiceCalendarDate serviceCalendarDate : dao.getAllEntitiesForType(ServiceCalendarDate.class)) {
        serviceCalendarDate.getServiceId().setAgencyId(feedId);
    }
    for (FareAttribute fareAttribute : dao.getAllEntitiesForType(FareAttribute.class)) {
        fareAttribute.getId().setAgencyId(feedId);
    }
    for (Pathway pathway : dao.getAllEntitiesForType(Pathway.class)) {
        pathway.getId().setAgencyId(feedId);
    }
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.index(new DefaultStreetVertexIndexFactory());
    final TripDescriptor.Builder tripDescriptorBuilder = TripDescriptor.newBuilder();
    tripDescriptorBuilder.setTripId("1.1");
    tripDescriptorBuilder.setScheduleRelationship(TripDescriptor.ScheduleRelationship.CANCELED);
    final TripUpdate.Builder tripUpdateBuilder = TripUpdate.newBuilder();
    tripUpdateBuilder.setTrip(tripDescriptorBuilder);
    cancellation = tripUpdateBuilder.build().toByteArray();
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) TripUpdate(com.google.transit.realtime.GtfsRealtime.TripUpdate) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) DefaultStreetVertexIndexFactory(org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory) TripDescriptor(com.google.transit.realtime.GtfsRealtime.TripDescriptor) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 3 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TimetableTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    patternIndex = new HashMap<AgencyAndId, TripPattern>();
    for (TransitStopDepart tsd : Iterables.filter(graph.getVertices(), TransitStopDepart.class)) {
        for (TransitBoardAlight tba : Iterables.filter(tsd.getOutgoing(), TransitBoardAlight.class)) {
            if (!tba.boarding)
                continue;
            TripPattern pattern = tba.getPattern();
            for (Trip trip : pattern.getTrips()) {
                patternIndex.put(trip.getId(), pattern);
            }
        }
    }
    pattern = patternIndex.get(new AgencyAndId("agency", "1.1"));
    timetable = pattern.scheduledTimetable;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File) TransitStopDepart(org.opentripplanner.routing.vertextype.TransitStopDepart) BeforeClass(org.junit.BeforeClass)

Example 4 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TestHopFactory method setUp.

public void setUp() throws Exception {
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.FAKE_GTFS));
    graph = new Graph();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.run(graph);
    graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    feedId = context.getFeedId().getId();
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) File(java.io.File)

Example 5 with GTFSPatternHopFactory

use of org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory in project OpenTripPlanner by opentripplanner.

the class TestFares method testKCM.

public void testKCM() throws Exception {
    Graph gg = new Graph();
    GtfsContext context = GtfsLibrary.readGtfs(new File(ConstantsForTests.KCM_GTFS));
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(context);
    factory.setFareServiceFactory(new SeattleFareServiceFactory());
    factory.run(gg);
    gg.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    RoutingRequest options = new RoutingRequest();
    String feedId = gg.getFeedIds().iterator().next();
    String vertex0 = feedId + ":2010";
    String vertex1 = feedId + ":2140";
    ShortestPathTree spt;
    GraphPath path = null;
    FareService fareService = gg.getService(FareService.class);
    long offPeakStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2016, 5, 24, 5, 0, 0);
    options.dateTime = offPeakStartTime;
    options.setRoutingContext(gg, vertex0, vertex1);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(vertex1), true);
    Fare costOffPeak = fareService.getCost(path);
    assertEquals(costOffPeak.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 250));
    long onPeakStartTime = TestUtils.dateInSeconds("America/Los_Angeles", 2016, 5, 24, 8, 0, 0);
    options.dateTime = onPeakStartTime;
    options.setRoutingContext(gg, vertex0, vertex1);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(gg.getVertex(vertex1), true);
    Fare costOnPeak = fareService.getCost(path);
    assertEquals(costOnPeak.getFare(FareType.regular), new Money(new WrappedCurrency("USD"), 275));
}
Also used : SeattleFareServiceFactory(org.opentripplanner.routing.impl.SeattleFareServiceFactory) GtfsContext(org.opentripplanner.gtfs.GtfsContext) GraphPath(org.opentripplanner.routing.spt.GraphPath) WrappedCurrency(org.opentripplanner.routing.core.WrappedCurrency) GTFSPatternHopFactory(org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory) 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) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) File(java.io.File)

Aggregations

GTFSPatternHopFactory (org.opentripplanner.routing.edgetype.factory.GTFSPatternHopFactory)15 File (java.io.File)14 Graph (org.opentripplanner.routing.graph.Graph)13 GtfsContext (org.opentripplanner.gtfs.GtfsContext)10 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)5 GraphPath (org.opentripplanner.routing.spt.GraphPath)4 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)4 IOException (java.io.IOException)3 BeforeClass (org.junit.BeforeClass)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 Fare (org.opentripplanner.routing.core.Fare)3 Money (org.opentripplanner.routing.core.Money)3 WrappedCurrency (org.opentripplanner.routing.core.WrappedCurrency)3 FareService (org.opentripplanner.routing.services.FareService)3 Trip (org.onebusaway.gtfs.model.Trip)2 StreetLinkerModule (org.opentripplanner.graph_builder.module.StreetLinkerModule)2 DefaultStreetVertexIndexFactory (org.opentripplanner.routing.impl.DefaultStreetVertexIndexFactory)2 TransitStopDepart (org.opentripplanner.routing.vertextype.TransitStopDepart)2 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)1 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)1