Search in sources :

Example 1 with TripPattern

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

the class SkipStop method apply.

@Override
public Collection<TripPattern> apply(TripPattern original) {
    if (!couldMatch(original))
        return Arrays.asList(original);
    // figure out which stops we skip
    TIntList skippedStops = new TIntArrayList();
    // retained stops
    // we use stop times to carry a little additional information, e.g. pickup/dropoff type.
    List<StopTime> stopTimes = Lists.newArrayList();
    {
        int i = 0;
        for (Stop stop : original.getStops()) {
            if (stopId.contains(stop.getId().getId()))
                skippedStops.add(i);
            else {
                // make a fake stop time
                StopTime stopTime = new StopTime();
                stopTime.setStop(stop);
                stopTime.setPickupType(original.stopPattern.pickups[i]);
                stopTime.setDropOffType(original.stopPattern.dropoffs[i]);
                stopTimes.add(stopTime);
            }
            i++;
        }
    }
    if (skippedStops.isEmpty()) {
        LOG.warn("No stops found to skip on matched trip pattern {}", original);
        return Arrays.asList(original);
    }
    if (original.getStops().size() - skippedStops.size() < 2) {
        // TODO best way to handle this case?
        LOG.warn("Trip with skipped stops would have less that two stops for TripPattern {}, not skipping stops", original);
        return Arrays.asList(original);
    }
    // make the new stop pattern
    StopPattern sp = new StopPattern(stopTimes);
    TripPattern modified = new TripPattern(original.route, sp);
    // Any trips that are not matched keep the original trip pattern, so put them here.
    TripPattern originalClone = new TripPattern(original.route, original.stopPattern);
    // keep track of what we have to return
    boolean anyTripsMatched = false;
    boolean allTripsMatched = true;
    for (TripTimes tt : original.scheduledTimetable.tripTimes) {
        if (!matches(tt.trip)) {
            // this trip should not be modified
            allTripsMatched = false;
            originalClone.scheduledTimetable.addTripTimes(tt);
        } else {
            // This trip should be modified
            anyTripsMatched = true;
            modified.scheduledTimetable.addTripTimes(omitStops(tt, skippedStops.toArray()));
        }
    }
    for (FrequencyEntry fe : original.scheduledTimetable.frequencyEntries) {
        if (!matches(fe.tripTimes.trip)) {
            allTripsMatched = false;
            originalClone.scheduledTimetable.addFrequencyEntry(fe);
        } else {
            anyTripsMatched = true;
            TripTimes newtt = omitStops(fe.tripTimes, skippedStops.toArray());
            FrequencyEntry newfe = new FrequencyEntry(fe.startTime, fe.endTime, fe.headway, fe.exactTimes, newtt);
            modified.scheduledTimetable.addFrequencyEntry(newfe);
        }
    }
    if (!anyTripsMatched)
        return Arrays.asList(original);
    List<TripPattern> ret = Lists.newArrayList();
    ret.add(modified);
    if (!allTripsMatched)
        ret.add(originalClone);
    return ret;
}
Also used : StopPattern(org.opentripplanner.model.StopPattern) Stop(org.onebusaway.gtfs.model.Stop) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) FrequencyEntry(org.opentripplanner.routing.trippattern.FrequencyEntry) TIntList(gnu.trove.list.TIntList) TIntArrayList(gnu.trove.list.array.TIntArrayList) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 2 with TripPattern

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

the class TimetableSnapshotSource method getPatternForTripId.

/**
 * Retrieve a trip pattern given a feed id and trid id.
 *
 * @param feedId feed id for the trip id
 * @param tripId trip id without agency
 * @return trip pattern or null if no trip pattern was found
 */
private TripPattern getPatternForTripId(String feedId, String tripId) {
    Trip trip = graphIndex.tripForId.get(new AgencyAndId(feedId, tripId));
    TripPattern pattern = graphIndex.patternForTrip.get(trip);
    return pattern;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripPattern(org.opentripplanner.routing.edgetype.TripPattern)

Example 3 with TripPattern

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

the class IndexAPI method getTripsForRoute.

/**
 * Return all trips in any pattern on the given route.
 */
@GET
@Path("/routes/{routeId}/trips")
public Response getTripsForRoute(@PathParam("routeId") String routeIdString) {
    AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
    Route route = index.routeForId.get(routeId);
    if (route != null) {
        List<Trip> trips = Lists.newArrayList();
        Collection<TripPattern> patterns = index.patternsForRoute.get(route);
        for (TripPattern pattern : patterns) {
            trips.addAll(pattern.getTrips());
        }
        return Response.status(Status.OK).entity(TripShort.list(trips)).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 4 with TripPattern

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

the class IndexAPI method getStopsForTrip.

@GET
@Path("/trips/{tripId}/stops")
public Response getStopsForTrip(@PathParam("tripId") String tripIdString) {
    AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
    Trip trip = index.tripForId.get(tripId);
    if (trip != null) {
        TripPattern pattern = index.patternForTrip.get(trip);
        Collection<Stop> stops = pattern.getStops();
        return Response.status(Status.OK).entity(StopShort.list(stops)).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with TripPattern

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

the class IndexAPI method getStopsForRoute.

/**
 * Return all stops in any pattern on a given route.
 */
@GET
@Path("/routes/{routeId}/stops")
public Response getStopsForRoute(@PathParam("routeId") String routeIdString) {
    AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
    Route route = index.routeForId.get(routeId);
    if (route != null) {
        Set<Stop> stops = Sets.newHashSet();
        Collection<TripPattern> patterns = index.patternsForRoute.get(route);
        for (TripPattern pattern : patterns) {
            stops.addAll(pattern.getStops());
        }
        return Response.status(Status.OK).entity(StopShort.list(stops)).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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