Package org.opentripplanner.routing.core

Examples of org.opentripplanner.routing.core.ServiceDay


        Trip trip = states[states.length - 1].getBackTrip();

        if (trip != null) {
            Route route = trip.getRoute();
            Agency agency = route.getAgency();
            ServiceDay serviceDay = states[states.length - 1].getServiceDay();

            leg.agencyId = agency.getId();
            leg.agencyName = agency.getName();
            leg.agencyUrl = agency.getUrl();
            leg.headsign = states[states.length - 1].getBackDirection();
            leg.route = states[states.length - 1].getBackEdge().getName();
            leg.routeColor = route.getColor();
            leg.routeId = route.getId().getId();
            leg.routeLongName = route.getLongName();
            leg.routeShortName = route.getShortName();
            leg.routeTextColor = route.getTextColor();
            leg.routeType = route.getType();
            leg.tripId = trip.getId().getId();
            leg.tripShortName = trip.getTripShortName();
            leg.tripBlockId = trip.getBlockId();

            if (serviceDay != null) {
                leg.serviceDate = serviceDay.getServiceDate().getAsString();
            }

            if (leg.headsign == null) {
                leg.headsign = trip.getTripHeadsign();
            }
View Full Code Here


        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);
                int estTime = (int) Math.round(
                        depTime * fractionCovered + arrTime * (1 - fractionCovered));

                int time = serviceDay.secondsSinceMidnight(opt.dateTime);
                /*
                 * TODO Weight differently early vs late time, as the probability of any transit
                 * being late is higher than being early. However, this has impact if your bus is
                 * more than 12h late, I don't think this would happen really often.
                 */
                int deltaTime = Math.abs(time - estTime);
                if (deltaTime < minDelta) {
                    minDelta = deltaTime;
                    actDelta = time - estTime;
                    bestTripTimes = tripTimes;
                    bestServiceDay = serviceDay;
                }
            }
            if (minDelta > 60000) LOG.warn(       // Being more than 1h late should not happen often
                    "On-board depart: delta between scheduled/real-time and actual time suspiciously large: {} seconds.",
                    actDelta);
            else LOG.info(
                    "On-board depart: delta between scheduled/real-time and actual time is {} seconds.",
                    actDelta);
        } else {
            /* 2. Compute service day */
            for (ServiceDay serviceDay : ctx.serviceDays) {
                Timetable timetable = tripPattern.getUpdatedTimetable(opt, serviceDay);
                // Get the tripTimes including real-time updates for the serviceDay
                TripTimes tripTimes = timetable.getTripTimes(timetable.getTripIndex(tripId));

                int depTime = tripTimes.getDepartureTime(0);
                int arrTime = tripTimes.getArrivalTime(tripTimes.getNumStops() - 1);

                int time = serviceDay.secondsSinceMidnight(opt.dateTime);

                if (depTime <= time && time <= arrTime) {
                    bestTripTimes = tripTimes;
                    bestServiceDay = serviceDay;
                }
            }

            if (bestServiceDay == null) {
                throw new RuntimeException("Unable to determine on-board depart service day.");
            }

            int time = bestServiceDay.secondsSinceMidnight(opt.dateTime);

            /*
             * 3. Get the best hop from the list, given the parameters. This is done by finding the
             * last hop that has not yet departed.
             */
 
View Full Code Here

             * finding today's 25:00 trip we would never find tomorrow's 00:30 trip.
             */
            TripPattern tripPattern = this.getPattern();
            int bestWait = -1;
            TripTimes  bestTripTimes  = null;
            ServiceDay bestServiceDay = null;
            for (ServiceDay sd : rctx.serviceDays) {
                /* Find the proper timetable (updated or original) if there is a realtime snapshot. */
                Timetable timetable = tripPattern.getUpdatedTimetable(options, sd);
                /* Skip this day/timetable if no trip in it could possibly be useful. */
                // TODO disabled until frequency representation is stable, and min/max timetable times are set from frequencies
View Full Code Here

        graph.addAgency(ferryAgency);
        graph.timetableSnapshotSource = (timetableSnapshotSource);
        graph.addAlertPatch(e29, alertPatch);

        // Routing context creation and initialization
        ServiceDay serviceDay = new ServiceDay(graph, 0, calendarServiceImpl, null);

        // Temporary graph objects for onboard depart tests
        OnboardDepartVertex onboardDepartVertex = new OnboardDepartVertex("Onboard", 23.0, 12.0);
        OnBoardDepartPatternHop onBoardDepartPatternHop = new OnBoardDepartPatternHop(
                onboardDepartVertex, v12, firstTripPattern.scheduledTimetable.getTripTimes(0), serviceDay, 0, 0.5);
View Full Code Here

        PatternDepartVertex depart = mock(PatternDepartVertex.class);
        PatternArriveVertex dwell = mock(PatternArriveVertex.class);
        PatternArriveVertex arrive = mock(PatternArriveVertex.class);
        Graph graph = mock(Graph.class);
        RoutingRequest routingRequest = mock(RoutingRequest.class);
        ServiceDay serviceDay = mock(ServiceDay.class);

        when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));

        GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
        CoordinateSequenceFactory coordinateSequenceFactory =
                geometryFactory.getCoordinateSequenceFactory();
        CoordinateSequence coordinateSequence = coordinateSequenceFactory.create(coordinates);
        LineString geometry = new LineString(coordinateSequence, geometryFactory);
        ArrayList<Edge> hops = new ArrayList<Edge>(2);
        RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
        AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
        Route route = new Route();
        ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(3);
        StopTime stopDepartTime = new StopTime();
        StopTime stopDwellTime = new StopTime();
        StopTime stopArriveTime = new StopTime();
        Stop stopDepart = new Stop();
        Stop stopDwell = new Stop();
        Stop stopArrive = new Stop();
        Trip trip = new Trip();

        routingContext.serviceDays =
                new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
        route.setId(agencyAndId);
        stopDepart.setId(agencyAndId);
        stopDwell.setId(agencyAndId);
        stopArrive.setId(agencyAndId);
        stopDepartTime.setStop(stopDepart);
        stopDepartTime.setDepartureTime(0);
        stopDwellTime.setArrivalTime(20);
        stopDwellTime.setStop(stopDwell);
        stopDwellTime.setDepartureTime(40);
        stopArriveTime.setArrivalTime(60);
        stopArriveTime.setStop(stopArrive);
        stopTimes.add(stopDepartTime);
        stopTimes.add(stopDwellTime);
        stopTimes.add(stopArriveTime);
        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);
View Full Code Here

        TransitStop station1 = mock(TransitStop.class);
        PatternDepartVertex depart = mock(PatternDepartVertex.class);
        PatternArriveVertex arrive = mock(PatternArriveVertex.class);
        Graph graph = mock(Graph.class);
        RoutingRequest routingRequest = mock(RoutingRequest.class);
        ServiceDay serviceDay = mock(ServiceDay.class);

        when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
        when(station0.getX()).thenReturn(coordinates[0].x);
        when(station0.getY()).thenReturn(coordinates[0].y);
        when(station1.getX()).thenReturn(coordinates[1].x);
        when(station1.getY()).thenReturn(coordinates[1].y);

        RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
        AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
        Route route = new Route();
        ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2);
        StopTime stopDepartTime = new StopTime();
        StopTime stopArriveTime = new StopTime();
        Stop stopDepart = new Stop();
        Stop stopArrive = new Stop();
        Trip trip = new Trip();

        routingContext.serviceDays =
                new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
        route.setId(agencyAndId);
        stopDepart.setId(new AgencyAndId("Station", "0"));
        stopArrive.setId(new AgencyAndId("Station", "1"));
        stopDepartTime.setStop(stopDepart);
        stopDepartTime.setDepartureTime(0);
        stopArriveTime.setArrivalTime(10);
        stopArriveTime.setStop(stopArrive);
        stopTimes.add(stopDepartTime);
        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);
View Full Code Here

        PatternDepartVertex depart = mock(PatternDepartVertex.class);
        PatternArriveVertex dwell = mock(PatternArriveVertex.class);
        PatternArriveVertex arrive = mock(PatternArriveVertex.class);
        Graph graph = mock(Graph.class);
        RoutingRequest routingRequest = mock(RoutingRequest.class);
        ServiceDay serviceDay = mock(ServiceDay.class);

        when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));

        ArrayList<Edge> hops = new ArrayList<Edge>(2);
        RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
        AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
        Route route = new Route();
        ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2);
        StopTime stopDepartTime = new StopTime();
        StopTime stopDwellTime = new StopTime();
        StopTime stopArriveTime = new StopTime();
        Stop stopDepart = new Stop();
        Stop stopDwell = new Stop();
        Stop stopArrive = new Stop();
        Trip trip = new Trip();

        routingContext.serviceDays =
                new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
        route.setId(agencyAndId);
        stopDepart.setId(new AgencyAndId("Station", "0"));
        stopDwell.setId(new AgencyAndId("Station", "1"));
        stopArrive.setId(new AgencyAndId("Station", "2"));
        stopDepartTime.setStop(stopDepart);
        stopDepartTime.setDepartureTime(0);
        stopDwellTime.setArrivalTime(20);
        stopDwellTime.setStop(stopDwell);
        stopDwellTime.setDepartureTime(40);
        stopArriveTime.setArrivalTime(60);
        stopArriveTime.setStop(stopArrive);
        stopTimes.add(stopDepartTime);
        stopTimes.add(stopDwellTime);
        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));

        when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(20);
        assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));

        when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(30);
        assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));

        when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(40);
        assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));

        when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(60);
        assertEquals(station2, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    }
View Full Code Here

        int tripIndex = this.trips.indexOf(trip);
        return getResolvedTripTimes(tripIndex, state0);
    }

    public TripTimes getResolvedTripTimes(int tripIndex, State state0) {
        ServiceDay serviceDay = state0.getServiceDay();
        RoutingRequest options = state0.getOptions();
        Timetable timetable = getUpdatedTimetable(options, serviceDay);
        return timetable.getTripTimes(tripIndex);
    }
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.core.ServiceDay

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.