Search in sources :

Example 21 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class AlertPatch method remove.

public void remove(Graph graph) {
    Agency agency = null;
    if (feedId != null) {
        Map<String, Agency> agencies = graph.index.agenciesForFeedId.get(feedId);
        agency = this.agency != null ? agencies.get(this.agency) : null;
    }
    Route route = this.route != null ? graph.index.routeForId.get(this.route) : null;
    Stop stop = this.stop != null ? graph.index.stopForId.get(this.stop) : null;
    Trip trip = this.trip != null ? graph.index.tripForId.get(this.trip) : null;
    if (route != null || trip != null || agency != null) {
        Collection<TripPattern> tripPatterns = null;
        if (trip != null) {
            tripPatterns = new LinkedList<TripPattern>();
            TripPattern tripPattern = graph.index.patternForTrip.get(trip);
            if (tripPattern != null) {
                tripPatterns.add(tripPattern);
            }
        } else if (route != null) {
            tripPatterns = graph.index.patternsForRoute.get(route);
        } else {
            // Find patterns for the feed.
            tripPatterns = graph.index.patternsForFeedId.get(feedId);
        }
        if (tripPatterns != null) {
            for (TripPattern tripPattern : tripPatterns) {
                if (direction != null && !direction.equals(tripPattern.getDirection())) {
                    continue;
                }
                if (directionId != -1 && directionId != tripPattern.directionId) {
                    continue;
                }
                for (int i = 0; i < tripPattern.stopPattern.stops.length; i++) {
                    if (stop == null || stop.equals(tripPattern.stopPattern.stops[i])) {
                        graph.removeAlertPatch(tripPattern.boardEdges[i], this);
                        graph.removeAlertPatch(tripPattern.alightEdges[i], this);
                    }
                }
            }
        }
    } else if (stop != null) {
        TransitStop transitStop = graph.index.stopVertexForStop.get(stop);
        for (Edge edge : transitStop.getOutgoing()) {
            if (edge instanceof PreBoardEdge) {
                graph.removeAlertPatch(edge, this);
                break;
            }
        }
        for (Edge edge : transitStop.getIncoming()) {
            if (edge instanceof PreAlightEdge) {
                graph.removeAlertPatch(edge, this);
                break;
            }
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) PreBoardEdge(org.opentripplanner.routing.edgetype.PreBoardEdge) Agency(org.onebusaway.gtfs.model.Agency) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) PreAlightEdge(org.opentripplanner.routing.edgetype.PreAlightEdge) PreAlightEdge(org.opentripplanner.routing.edgetype.PreAlightEdge) PreBoardEdge(org.opentripplanner.routing.edgetype.PreBoardEdge) Edge(org.opentripplanner.routing.graph.Edge) Route(org.onebusaway.gtfs.model.Route)

Example 22 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class NearbyStopFinder method findNearbyStopsConsideringPatterns.

/**
 * Find all unique nearby stops that are the closest stop on some trip pattern.
 * Note that the result will include the origin vertex if it is an instance of TransitStop.
 * This is intentional: we don't want to return the next stop down the line for trip patterns that pass through the
 * origin vertex.
 */
public Set<StopAtDistance> findNearbyStopsConsideringPatterns(Vertex vertex) {
    /* Track the closest stop on each pattern passing nearby. */
    SimpleIsochrone.MinMap<TripPattern, StopAtDistance> closestStopForPattern = new SimpleIsochrone.MinMap<TripPattern, StopAtDistance>();
    /* Iterate over nearby stops via the street network or using straight-line distance, depending on the graph. */
    for (NearbyStopFinder.StopAtDistance stopAtDistance : findNearbyStops(vertex)) {
        /* Filter out destination stops that are already reachable via pathways or transfers. */
        // FIXME why is the above comment relevant here? how does the next line achieve this?
        TransitStop ts1 = stopAtDistance.tstop;
        if (!ts1.isStreetLinkable())
            continue;
        /* Consider this destination stop as a candidate for every trip pattern passing through it. */
        for (TripPattern pattern : graph.index.patternsForStop.get(ts1.getStop())) {
            closestStopForPattern.putMin(pattern, stopAtDistance);
        }
    }
    /* Make a transfer from the origin stop to each destination stop that was the closest stop on any pattern. */
    Set<StopAtDistance> uniqueStops = Sets.newHashSet();
    uniqueStops.addAll(closestStopForPattern.values());
    return uniqueStops;
}
Also used : SimpleIsochrone(org.opentripplanner.api.resource.SimpleIsochrone) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TripPattern(org.opentripplanner.routing.edgetype.TripPattern)

Example 23 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern 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 24 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class GTFSPatternHopFactoryTest method testBikesAllowed.

@Test
public void testBikesAllowed() throws IOException {
    MockGtfs gtfs = MockGtfs.create();
    gtfs.putAgencies(1);
    gtfs.putRoutes(1);
    gtfs.putStops(2);
    gtfs.putCalendars(1);
    gtfs.putTrips(1, "r0", "sid0", "bikes_allowed=1");
    gtfs.putStopTimes("t0", "s0,s1");
    gtfs.putLines("frequencies.txt", "trip_id,start_time,end_time,headway_secs", "t0,09:00:00,17:00:00,300");
    GtfsFeedId feedId = new GtfsFeedId.Builder().id("FEED").build();
    GTFSPatternHopFactory factory = new GTFSPatternHopFactory(GtfsLibrary.createContext(feedId, gtfs.read()));
    Graph graph = new Graph();
    factory.run(graph);
    for (Edge edge : graph.getEdges()) {
        if (edge instanceof TransitBoardAlight) {
            TripPattern pattern = ((TransitBoardAlight) edge).getPattern();
        // TODO assertTrue(pattern.getBikesAllowed());
        }
    }
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) GtfsFeedId(org.opentripplanner.graph_builder.module.GtfsFeedId) TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) MockGtfs(org.onebusaway.gtfs.services.MockGtfs) Edge(org.opentripplanner.routing.graph.Edge) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Test(org.junit.Test)

Example 25 with TripPattern

use of org.opentripplanner.routing.edgetype.TripPattern in project OpenTripPlanner by opentripplanner.

the class TimetableFilterTest method testSkipStopInMiddle.

/**
 * test modifying trip patterns
 */
@Test
public void testSkipStopInMiddle() {
    SkipStop ss = new SkipStop();
    ss.routeId = Arrays.asList(route.getId().getId());
    ss.agencyId = agency.getId();
    ss.stopId = Arrays.asList(stops[2].getId().getId());
    Collection<TripPattern> result = ss.apply(pattern);
    assertEquals(1, result.size());
    TripPattern newtp = result.iterator().next();
    assertNotSame(pattern, newtp);
    // TODO getNumScheduledTrips is zero - why?
    assertEquals(2, newtp.scheduledTimetable.tripTimes.size());
    assertEquals(2, newtp.scheduledTimetable.frequencyEntries.size());
    assertEquals(3, newtp.stopPattern.size);
    // make sure the times are correct
    assertEquals(pattern.scheduledTimetable.tripTimes.get(0).getDepartureTime(0), newtp.scheduledTimetable.tripTimes.get(0).getDepartureTime(0));
    // after the skipped stop: dwell times should be removed
    assertEquals(pattern.scheduledTimetable.tripTimes.get(0).getDepartureTime(3) - 30, newtp.scheduledTimetable.tripTimes.get(0).getDepartureTime(2));
    assertEquals(pattern.stopPattern.stops[3], newtp.stopPattern.stops[2]);
    // and for the frequency entry
    // make sure the times are correct
    assertEquals(pattern.scheduledTimetable.frequencyEntries.get(0).tripTimes.getDepartureTime(0), newtp.scheduledTimetable.frequencyEntries.get(0).tripTimes.getDepartureTime(0));
    // after the skipped stop: dwell times should be removed
    assertEquals(pattern.scheduledTimetable.frequencyEntries.get(0).tripTimes.getDepartureTime(3) - 30, newtp.scheduledTimetable.frequencyEntries.get(0).tripTimes.getDepartureTime(2));
}
Also used : TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Test(org.junit.Test)

Aggregations

TripPattern (org.opentripplanner.routing.edgetype.TripPattern)53 Stop (org.onebusaway.gtfs.model.Stop)23 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)23 Trip (org.onebusaway.gtfs.model.Trip)20 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)19 TripTimes (org.opentripplanner.routing.trippattern.TripTimes)19 Test (org.junit.Test)14 Route (org.onebusaway.gtfs.model.Route)14 Timetable (org.opentripplanner.routing.edgetype.Timetable)11 ArrayList (java.util.ArrayList)10 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Edge (org.opentripplanner.routing.graph.Edge)9 StopTime (org.onebusaway.gtfs.model.StopTime)8 StopPattern (org.opentripplanner.model.StopPattern)8 TimetableSnapshot (org.opentripplanner.routing.edgetype.TimetableSnapshot)8 Graph (org.opentripplanner.routing.graph.Graph)8 Agency (org.onebusaway.gtfs.model.Agency)7 ServiceDay (org.opentripplanner.routing.core.ServiceDay)7 FrequencyEntry (org.opentripplanner.routing.trippattern.FrequencyEntry)7