Package org.opentripplanner.routing.edgetype

Examples of org.opentripplanner.routing.edgetype.TripPattern


        assertEquals("120W1320", itinerary.legs.get(3).tripId);

        // Now apply a real-time update: let the to-trip be early by 240 seconds,
        // resulting in a transfer time of 0 seconds
        Trip trip = graph.index.tripForId.get(new AgencyAndId("TriMet", "120W1320"));
        TripPattern pattern = graph.index.patternForTrip.get(trip);
        applyUpdateToTripPattern(pattern, "120W1320", "9756", 22, 41580, 41580,
                ScheduleRelationship.SCHEDULED, 0, serviceDate);

        // Do the planning again
        response = planner.getItineraries();
View Full Code Here


    }

    /** Check that bidirectional relationships between TripPatterns and Trips, Routes, and Stops are coherent. */
    public void testPatternsCoherent() {
        for (Trip trip : graph.index.tripForId.values()) {
            TripPattern pattern = graph.index.patternForTrip.get(trip);
            assertTrue(pattern.getTrips().contains(trip));
        }
        /* This one depends on a feed where each TripPattern appears on only one route. */
        for (Route route : graph.index.routeForId.values()) {
            for (TripPattern pattern : graph.index.patternsForRoute.get(route)) {
                assertEquals(pattern.route, route);
View Full Code Here

        trip.setId(agencyAndId);
        trip.setTripHeadsign("The right");

        TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
        StopPattern stopPattern = new StopPattern(stopTimes);
        TripPattern tripPattern = new TripPattern(route, stopPattern);

        when(depart.getTripPattern()).thenReturn(tripPattern);
        when(dwell.getTripPattern()).thenReturn(tripPattern);

        PatternHop patternHop0 = new PatternHop(depart, dwell, stopDepart, stopDwell, 0);
        PatternHop patternHop1 = new PatternHop(dwell, arrive, stopDwell, stopArrive, 1);

        hops.add(patternHop0);
        hops.add(patternHop1);

        when(graph.getEdges()).thenReturn(hops);
        when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
        when(dwell.getCoordinate()).thenReturn(new Coordinate(0, 0));
        when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
        routingRequest.from = new GenericLocation();
        routingRequest.startingTransitTripId = agencyAndId;
        when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(9);

        patternHop0.setGeometry(geometry);
        tripPattern.add(tripTimes);
        graph.index = new GraphIndex(graph);

        coordinates = new Coordinate[3];
        coordinates[0] = new Coordinate(3.5, 1.0);
        coordinates[1] = new Coordinate(5.0, 1.0);
View Full Code Here

        stopTimes.add(stopArriveTime);
        trip.setId(agencyAndId);

        TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
        StopPattern stopPattern = new StopPattern(stopTimes);
        TripPattern tripPattern = new TripPattern(route, stopPattern);

        when(depart.getTripPattern()).thenReturn(tripPattern);

        PatternHop patternHop = new PatternHop(depart, arrive, stopDepart, stopArrive, 0);

        when(graph.getEdges()).thenReturn(Collections.<Edge>singletonList(patternHop));
        when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
        when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
        routingRequest.from = new GenericLocation();
        routingRequest.startingTransitTripId = agencyAndId;
        when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(10);
        when(graph.getVertex("Station_0")).thenReturn(station0);
        when(graph.getVertex("Station_1")).thenReturn(station1);

        tripPattern.add(tripTimes);
        graph.index = new GraphIndex(graph);

        Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);

        assertEquals(coordinates[1].x, vertex.getX(), 0.0);
View Full Code Here

        stopTimes.add(stopArriveTime);
        trip.setId(agencyAndId);

        TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
        StopPattern stopPattern = new StopPattern(stopTimes);
        TripPattern tripPattern = new TripPattern(route, stopPattern);

        when(depart.getTripPattern()).thenReturn(tripPattern);
        when(dwell.getTripPattern()).thenReturn(tripPattern);

        PatternHop patternHop0 = new PatternHop(depart, dwell, stopDepart, stopDwell, 0);
        PatternHop patternHop1 = new PatternHop(dwell, arrive, stopDwell, stopArrive, 1);

        hops.add(patternHop0);
        hops.add(patternHop1);

        when(graph.getEdges()).thenReturn(hops);
        when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
        when(dwell.getCoordinate()).thenReturn(new Coordinate(0, 0));
        when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
        routingRequest.from = new GenericLocation();
        routingRequest.startingTransitTripId = agencyAndId;
        when(graph.getVertex("Station_0")).thenReturn(station0);
        when(graph.getVertex("Station_1")).thenReturn(station1);
        when(graph.getVertex("Station_2")).thenReturn(station2);

        tripPattern.add(tripTimes);
        graph.index = new GraphIndex(graph);

        when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(0);
        assertEquals(station0, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
View Full Code Here

                continue TRIP;
            }

            /* Get the existing TripPattern for this filtered StopPattern, or create one. */
            StopPattern stopPattern = new StopPattern(stopTimes);
            TripPattern tripPattern = tripPatterns.get(stopPattern);
            if (tripPattern == null) {
                tripPattern = new TripPattern(trip.getRoute(), stopPattern);
                tripPatterns.put(stopPattern, tripPattern);
            }

            /* Create a TripTimes object for this list of stoptimes, which form one trip. */
            TripTimes tripTimes = new TripTimes(trip, stopTimes, graph.deduplicator);

            /* If this trip is referenced by one or more lines in frequencies.txt, wrap it in a FrequencyEntry. */
            List<Frequency> frequencies = frequenciesForTrip.get(trip);
            if (frequencies != null && !(frequencies.isEmpty())) {
                for (Frequency freq : frequencies) {
                    tripPattern.add(new FrequencyEntry(freq, tripTimes));
                    freqCount++;
                }
                // TODO replace: createGeometry(graph, trip, stopTimes, hops);
            }

            /* This trip was not frequency-based. Add the TripTimes directly to the TripPattern's scheduled timetable. */
            else {
                tripPattern.add(tripTimes);
                nonFreqCount++;
            }
           
            // create geometries if they aren't already created
            // note that this is not only done on new trip patterns, because it is possible that
            // there would be a trip pattern with no geometry yet because it failed some of these tests
            if (!geometriesByTripPattern.containsKey(tripPattern) &&
                    trip.getShapeId() != null && trip.getShapeId().getId() != null &&
                    !trip.getShapeId().getId().equals("")) {
                // save the geometry to later be applied to the hops
                geometriesByTripPattern.put(tripPattern,  createGeometry(graph, trip, stopTimes));
            }


        } // end foreach TRIP
        LOG.info("Added {} frequency-based and {} single-trip timetable entries.", freqCount, nonFreqCount);

        /* Generate unique human-readable names for all the TableTripPatterns. */
        TripPattern.generateUniqueNames(tripPatterns.values());

        /* Generate unique short IDs for all the TableTripPatterns. */
        TripPattern.generateUniqueIds(tripPatterns.values());

        /* Loop over all new TripPatterns, setting the service codes. */
        for (TripPattern tripPattern : tripPatterns.values()) {
            tripPattern.makePatternVerticesAndEdges(graph, context);
           
            // add the geometries
            LineString[] geom = geometriesByTripPattern.get(tripPattern);
            if (geom != null) {
                for (int i = 0; i < tripPattern.hopEdges.length; i++) {
                    tripPattern.hopEdges[i].setGeometry(geom[i]);
                }
            }
           
            tripPattern.setServiceCodes(graph.serviceCodes); // TODO this could be more elegant
        }

        /* Identify interlined trips and create the necessary edges. */
        interline(tripPatterns.values());

View Full Code Here

                    if (prev.getDepartureTime(prev.getNumStops() - 1) > curr.getArrivalTime(0)) {
                        LOG.error("Trip times within block {} on service {} are not increasing on service {} after trip {}.",
                                block.blockId, block.serviceId, prev.trip.getId());
                        continue SERVICE_BLOCK;
                    }
                    TripPattern prevPattern = patternForTripTimes.get(prev);
                    TripPattern currPattern = patternForTripTimes.get(curr);
                    interlines.put(new P2<TripPattern>(prevPattern, currPattern), new P2<Trip>(prev.trip, curr.trip));
                }
                prev = curr;
            }
        }

        /*
          Create the PatternInterlineDwell edges linking together TripPatterns.
          All the pattern vertices and edges must already have been created.
         */
        for (P2<TripPattern> patterns : interlines.keySet()) {
            TripPattern prevPattern = patterns.first;
            TripPattern nextPattern = patterns.second;
            // This is a single (uni-directional) edge which may be traversed forward and backward.
            PatternInterlineDwell edge = new PatternInterlineDwell(prevPattern, nextPattern);
            for (P2<Trip> trips : interlines.get(patterns)) {
                edge.add(trips.first, trips.second);
            }
View Full Code Here

        if (route != null || trip != null || agency != null) {
            Collection<TripPattern> tripPatterns;

            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 {
               tripPatterns = graph.index.patternsForAgency.get(agency);
            }

            for (TripPattern tripPattern : tripPatterns) {
                if (direction != null && ! direction.equals(tripPattern.getDirection())) {
                    continue;
                }
                for (int i = 0; i < tripPattern.stopPattern.stops.length; i++) {
                    if (stop == null || stop.equals(tripPattern.stopPattern.stops[i])) {
                        graph.addAlertPatch(tripPattern.boardEdges[i], this);
View Full Code Here

        if (route != null || trip != null || agency != null) {
            Collection<TripPattern> tripPatterns;

            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 {
               tripPatterns = graph.index.patternsForAgency.get(agency);
            }

            for (TripPattern tripPattern : tripPatterns) {
                if (direction != null && ! direction.equals(tripPattern.getDirection())) {
                    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);
View Full Code Here

        LOG.info("To patterns/stops: {}", toStops);

        /* Enqueue an unfinished PatternRide for each pattern near the origin, grouped by Stop into unfinished Rides. */
        Map<StopCluster, Ride> initialRides = Maps.newHashMap(); // One ride per stop cluster
        for (Entry<TripPattern, StopAtDistance> entry : fromStops.entrySet()) {
            TripPattern pattern = entry.getKey();
            StopAtDistance sd = entry.getValue();
            if ( ! request.transitModes.contains(pattern.mode)) {
                continue; // FIXME why are we even storing these patterns?
            }
            /* Loop over stop clusters in case stop cluster appears more than once in the same pattern. */
            for (int i = 0; i < pattern.getStops().size(); ++i) {
                // FIXME using String identity equality for stop clusters on purpose
                if (sd.stop == graph.index.stopClusterForStop.get(pattern.getStops().get(i))) {
                    Ride ride = initialRides.get(sd.stop);
                    if (ride == null) {
                        ride = new Ride(sd.stop, null); // null previous ride because this is the first ride
                        ride.accessTime = sd.etime;
                        ride.accessDist = 0; // FIXME
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.