Package org.opentripplanner.routing.edgetype

Examples of org.opentripplanner.routing.edgetype.TripPattern


            String alightRule = null;

            for (int j = 1; j < legsStates[i].length; j++) {
                if (legsStates[i][j].getBackEdge() instanceof PatternEdge) {
                    PatternEdge patternEdge = (PatternEdge) legsStates[i][j].getBackEdge();
                    TripPattern tripPattern = patternEdge.getPattern();

                    Integer fromIndex = legs.get(i).from.stopIndex;
                    Integer toIndex = legs.get(i).to.stopIndex;

                    int boardType = (fromIndex != null) ? (tripPattern.getBoardType(fromIndex)) : 0;
                    int alightType = (toIndex != null) ? (tripPattern.getAlightType(toIndex)) : 0;

                    boardRule = getBoardAlightMessage(boardType);
                    alightRule = getBoardAlightMessage(alightType);
                }
                if (legsStates[i][j].getBackEdge() instanceof PathwayEdge) {
View Full Code Here


        opt.rctx = ctx;

        /* 1. Get the list of PatternHop for the given trip ID. */
        AgencyAndId tripId = opt.startingTransitTripId;
        Trip trip = ctx.graph.index.tripForId.get(tripId);
        TripPattern tripPattern = ctx.graph.index.patternForTrip.get(trip);
        if (tripPattern == null) {
            // TODO Shouldn't we bailout on a normal trip plan here, returning null ?
            throw new IllegalArgumentException("Unknown/invalid trip ID: " + tripId);
        }
        List<PatternHop> hops = tripPattern.getPatternHops();

        Double lon = opt.from.lng; // Origin point, optional
        Double lat = opt.from.lat;
        PatternStopVertex nextStop;
        TripTimes bestTripTimes = null;
        ServiceDay bestServiceDay = null;
        int bestStopIndex = 0;
        double fractionCovered;
        LineString geomRemaining;

        Coordinate point = lon == null || lat == null ? null : new Coordinate(lon, lat);
        if (point != null) {
            /*
             * 2. Get the best hop from the list, given the parameters. Currently look for nearest hop,
             * taking into account shape if available. If no shape are present, the computed hop and
             * fraction may be a bit away from what it should be.
             */
            PatternHop bestHop = null;
            double minDist = Double.MAX_VALUE;
            for (PatternHop hop : hops) {
                LineString line = hop.getGeometry();
                double dist = distanceLibrary.fastDistance(point, line);
                if (dist < minDist) {
                    minDist = dist;
                    bestHop = hop;
                }
            }
            if (minDist > 1000) LOG.warn(
                    "On-board depart: origin point suspiciously away from nearest trip shape ({} meters)",
                    minDist);
            else LOG.info("On-board depart: origin point {} meters away from hop shape", minDist);

            /*
             * 3. Compute the fraction covered percentage of the current hop. This assume a constant
             * trip speed alongside the whole hop: this should be quite precise for small hops
             * (buses), a bit less for longer ones (long distance train). Shape linear distance is
             * of no help here, as the unit is arbitrary (and probably usually a distance).
             */
            LineString geometry = bestHop.getGeometry();
            P2<LineString> geomPair = GeometryUtils.splitGeometryAtPoint(geometry, point);
            geomRemaining = geomPair.second;
            double total = distanceLibrary.fastLength(geometry);
            double remaining = distanceLibrary.fastLength(geomRemaining);
            fractionCovered = total > 0.0 ? (double) (1.0 - remaining / total) : 0.0;

            nextStop = (PatternStopVertex) bestHop.getToVertex();
            bestStopIndex = bestHop.getStopIndex();

            /*
             * 4. Compute service day based on given departure day/time relative to
             * scheduled/real-time trip time for hop. This is needed as for some trips any service
             * day can apply.
             */
            int minDelta = Integer.MAX_VALUE;
            int actDelta = 0;
            for (ServiceDay serviceDay : ctx.serviceDays) {
                TripPattern pattern = nextStop.getTripPattern();
                Timetable timetable = pattern.getUpdatedTimetable(opt, serviceDay);
                // Get the tripTimes including real-time updates for the serviceDay
                TripTimes tripTimes = timetable.getTripTimes(timetable.getTripIndex(tripId));

                int depTime = tripTimes.getDepartureTime(bestStopIndex);
                int arrTime = tripTimes.getArrivalTime(bestStopIndex + 1);
View Full Code Here

    protected boolean handleScheduledTrip(TripUpdate tripUpdate, String feedId, ServiceDate serviceDate) {
        TripDescriptor tripDescriptor = tripUpdate.getTrip();
        // This does not include Agency ID or feed ID, trips are feed-unique and we currently assume a single static feed.
        String tripId = tripDescriptor.getTripId();
        TripPattern pattern = getPatternForTripId(tripId);

        if (pattern == null) {
            LOG.warn("No pattern found for tripId {}, skipping TripUpdate.", tripId);
            return false;
        }
View Full Code Here

    protected boolean handleCanceledTrip(TripUpdate tripUpdate, String agencyId,
                                         ServiceDate serviceDate) {
        TripDescriptor tripDescriptor = tripUpdate.getTrip();
        String tripId = tripDescriptor.getTripId(); // This does not include Agency ID, trips are feed-unique.
        TripPattern pattern = getPatternForTripId(tripId);

        if (pattern == null) {
            LOG.warn("No pattern found for tripId {}, skipping TripUpdate.", tripId);
            return false;
        }
View Full Code Here

                map.put(trip.getId().getId(), trip);
            }
            graphIndex.tripForIdWithoutAgency = map;
        }
        Trip trip = graphIndex.tripForIdWithoutAgency.get(tripIdWithoutAgency);
        TripPattern pattern = graphIndex.patternForTrip.get(trip);
        return pattern;
    }
View Full Code Here

        for (Edge edge : edges) {
            vertices.add(edge.getFromVertex());
            vertices.add(edge.getToVertex());
            if (edge instanceof TablePatternEdge) {
                TablePatternEdge patternEdge = (TablePatternEdge) edge;
                TripPattern pattern = patternEdge.getPattern();
                patternForId.put(pattern.code, pattern);
            }
        }
        for (Vertex vertex : vertices) {
            vertexForId.put(vertex.getLabel(), vertex);
            if (vertex instanceof TransitStop) {
                TransitStop transitStop = (TransitStop) vertex;
                Stop stop = transitStop.getStop();
                stopForId.put(stop.getId(), stop);
                stopVertexForStop.put(stop, transitStop);
                stopsForParentStation.put(stop.getParentStation(), stop);
            }
        }
        for (TransitStop stopVertex : stopVertexForStop.values()) {
            Envelope envelope = new Envelope(stopVertex.getCoordinate());
            stopSpatialIndex.insert(envelope, stopVertex);
        }
        for (TripPattern pattern : patternForId.values()) {
            patternsForAgency.put(pattern.route.getAgency(), pattern);
            patternsForRoute.put(pattern.route, pattern);
            for (Trip trip : pattern.getTrips()) {
                patternForTrip.put(trip, pattern);
                tripForId.put(trip.getId(), trip);
            }
            for (Stop stop: pattern.getStops()) {
                patternsForStop.put(stop, pattern);
            }
        }
        for (Route route : patternsForRoute.asMap().keySet()) {
            routeForId.put(route.getId(), route);
View Full Code Here

        }
        /* Now filter the transfers down to eliminate long series of transfers in shared trunks. */
        LOG.info("Filtering out long series of transfers on trunks shared between patterns.");
        for (P2<TripPattern> pair : transfers.keySet()) {
            ProfileTransfer.GoodTransferList list = transfers.get(pair);
            TripPattern fromPattern = pair.first; // TODO consider using second (think of express-local transfers in NYC)
            Map<StopCluster, ProfileTransfer> transfersByFromCluster = Maps.newHashMap();
            for (ProfileTransfer transfer : list.good) {
                transfersByFromCluster.put(transfer.sc1, transfer);
            }
            List<ProfileTransfer> retainedTransfers = Lists.newArrayList();
View Full Code Here

   @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();
       }
   }
View Full Code Here

    @Path("/trips/{tripId}/semanticHash")
    public Response getSemanticHashForTrip (@PathParam("tripId") String tripIdString) {
        AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
        Trip trip = index.tripForId.get(tripId);
        if (trip != null) {
            TripPattern pattern = index.patternForTrip.get(trip);
            String hashString = pattern.semanticHashString(trip);
            return Response.status(Status.OK).entity(hashString).build();
        } else {
            return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
        }
    }
View Full Code Here

   @Path("/trips/{tripId}/stoptimes")
   public Response getStoptimesForTrip (@PathParam("tripId") String tripIdString) {
       AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
       Trip trip = index.tripForId.get(tripId);
       if (trip != null) {
           TripPattern pattern = index.patternForTrip.get(trip);
           Timetable table = pattern.scheduledTimetable;
           return Response.status(Status.OK).entity(TripTimeShort.fromTripTimes(table, trip)).build();
       } else {
           return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
       }
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.edgetype.TripPattern

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.