Examples of RoutingRequest


Examples of org.opentripplanner.routing.core.RoutingRequest

    private static final Logger LOG = LoggerFactory.getLogger(OnBoardDepartServiceImpl.class);

    @Override
    public Vertex setupDepartOnBoard(RoutingContext ctx) {
        DistanceLibrary distanceLibrary = SphericalDistanceLibrary.getInstance();
        RoutingRequest opt = ctx.opt;
        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);
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

        snapButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String locString = (String) JOptionPane.showInputDialog(frame, "Location string",
                        "");
                GenericLocation loc = GenericLocation.fromOldStyleString(locString);
                RoutingRequest rr = new RoutingRequest();
                Vertex v = graph.streetIndex.getVertexForLocation(
                        loc, rr);
                showGraph.highlightVertex(v);
            }
        });
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

        modeSet.setCustomMotorVehicle(cmvCheckBox.isSelected());
        // must set generic transit mode last, and only when it is checked
        // otherwise 'false' will clear trainish and busish
        if (transitCheckBox.isSelected())
            modeSet.setTransit(true);
        RoutingRequest options = new RoutingRequest(modeSet);
        options.setArriveBy(arriveByCheckBox.isSelected());
        options.setWalkBoardCost(Integer.parseInt(boardingPenaltyField.getText()) * 60); // override low 2-4 minute values
        // TODO LG Add ui element for bike board cost (for now bike = 2 * walk)
        options.setBikeBoardCost(Integer.parseInt(boardingPenaltyField.getText()) * 60 * 2);
        // there should be a ui element for walk distance and optimize type
        options.setOptimize( getSelectedOptimizeType() );
        options.setMaxWalkDistance(Integer.parseInt(maxWalkField.getText()));
        options.setDateTime(when);
        options.setFromString(from);
        options.setToString(to);
        options.walkSpeed = Float.parseFloat(walkSpeed.getText());
        options.bikeSpeed = Float.parseFloat(bikeSpeed.getText());
        options.heuristicWeight = (Float.parseFloat(heuristicWeight.getText()));
        options.softWalkLimiting = ( softWalkLimiting.isSelected() );
        options.softWalkPenalty = (Float.parseFloat(softWalkPenalty.getText()));
        options.softWalkOverageRate = (Float.parseFloat(this.softWalkOverageRate.getText()));
        options.numItineraries = 1;
        System.out.println("--------");
        System.out.println("Path from " + from + " to " + to + " at " + when);
        System.out.println("\tModes: " + modeSet);
        System.out.println("\tOptions: " + options);
       
        options.numItineraries = ( Integer.parseInt( this.nPaths.getText() ) );
       
        // apply callback if the options call for it
        if( dontUseGraphicalCallbackCheckBox.isSelected() ){
          sptServiceFactory.setTraverseVisitor(null);
        } else {
          sptServiceFactory.setTraverseVisitor(new VisualTraverseVisitor(showGraph));
        }
       
        // set up a visitor to the path service so we can get the SPT as it's generated
        SPTVisitor vis = new SPTVisitor();
        pathservice.setSPTVisitor(vis);
       
        long t0 = System.currentTimeMillis();
        // TODO: check options properly intialized (AMB)
        List<GraphPath> paths = pathservice.getPaths(options);
        long dt = System.currentTimeMillis() - t0;
        searchTimeElapsedLabel.setText( "search time elapsed: "+dt+"ms" );
       
        // grab the spt from the visitor
        spt = vis.spt;
        showGraph.setSPT(spt);
        System.out.println( "got spt:"+spt );
       
        if (paths == null) {
            System.out.println("no path");
            showGraph.highlightGraphPath(null);
            return;
        }
       
        // now's a convenient time to set graphical SPT weights
        showGraph.simpleSPT.setWeights();
                       
        showPathsInPanel(paths);
       
        // now's a good time to set showGraph's SPT drawing weights
        showGraph.setSPTFlattening( Float.parseFloat(sptFlattening.getText()) );
        showGraph.setSPTThickness( Float.parseFloat(sptThickness.getText()) );
        showGraph.redraw();
       
        options.cleanup();
    }
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

     *
     * @param arrivalTimeAtStop TODO: clarify what this is.
     */
    public State traverse(State s0, long arrivalTimeAtStop) {
        RoutingContext rctx    = s0.getContext();
        RoutingRequest options = s0.getOptions();

        /* If the user requested a wheelchair accessible trip, check whether and this stop is not accessible. */
        if (options.wheelchairAccessible && ! getPattern().wheelchairAccessible(stopIndex)) {
            return null;
        };

        /*
         * Determine whether we are going onto or off of transit. Entering and leaving transit is
         * not the same thing as boarding and alighting. When arriveBy == true, we are entering
         * transit when traversing an alight edge backward.
         */
        boolean leavingTransit =
                ( boarding &&  options.arriveBy) ||
                (!boarding && !options.arriveBy);

        /* TODO pull on/off transit out into two functions. */
        if (leavingTransit) {
            /* We are leaving transit, not as much to do. */
            // When a dwell edge has been eliminated, do not alight immediately after boarding.
            // Perhaps this should be handled by PathParser.
            if (s0.getBackEdge() instanceof TransitBoardAlight) {
                return null;
            }
            StateEditor s1 = s0.edit(this);
            s1.setTripId(null);
            s1.setLastAlightedTimeSeconds(s0.getTimeSeconds());
            // Store the stop we are alighting at, for computing stop-to-stop transfer times,
            // preferences, and permissions.
            // The vertices in the transfer table are stop arrives/departs, not pattern
            // arrives/departs, so previousStop is direction-dependent.
            s1.setPreviousStop(getStop());
            s1.setLastPattern(this.getPattern());

            /* Determine the wait. */
            if (arrivalTimeAtStop > 0) { // FIXME what is this arrivalTimeAtStop?
                int wait = (int) Math.abs(s0.getTimeSeconds() - arrivalTimeAtStop);
               
                s1.incrementTimeInSeconds(wait);
                // this should only occur at the beginning
                s1.incrementWeight(wait * options.waitAtBeginningFactor);

                s1.setInitialWaitTimeSeconds(wait);

                //LOG.debug("Initial wait time set to {} in PatternBoard", wait);
            }
           
            // during reverse optimization, board costs should be applied to PatternBoards
            // so that comparable trip plans result (comparable to non-optimized plans)
            if (options.reverseOptimizing)
                s1.incrementWeight(options.getBoardCost(s0.getNonTransitMode()));

            if (options.reverseOptimizeOnTheFly) {
                TripPattern pattern = getPattern();
                int thisDeparture = s0.getTripTimes().getDepartureTime(stopIndex);
                int numTrips = getPattern().getNumScheduledTrips();
                int nextDeparture;

                s1.setLastNextArrivalDelta(Integer.MAX_VALUE);

                for (int tripIndex = 0; tripIndex < numTrips; tripIndex++) {
                    Timetable timetable = pattern.getUpdatedTimetable(options, s0.getServiceDay());
                    nextDeparture = timetable.getTripTimes(tripIndex).getDepartureTime(stopIndex);
       
                    if (nextDeparture > thisDeparture) {
                        s1.setLastNextArrivalDelta(nextDeparture - thisDeparture);
                        break;
                    }
                }
            }           

            s1.setBackMode(getMode());
            return s1.makeState();
        } else {
            /* We are going onto transit and must look for a suitable transit trip on this pattern. */  
           
            /* Disallow ever re-boarding the same trip pattern. */
            if (s0.getLastPattern() == this.getPattern()) {
                return null;
            }
           
            /* Check this pattern's mode against those allowed in the request. */
            if (!options.modes.get(modeMask)) {
                return null;
            }

            /* We assume all trips in a pattern are on the same route. Check if that route is banned. */
            if (options.bannedRoutes != null && options.bannedRoutes.matches(getPattern().route)) {
                // TODO: remove route checks in/after the trip search
                return null;
            }
           
            /*
             * Find the next boarding/alighting time relative to the current State. Check lists of
             * transit serviceIds running yesterday, today, and tomorrow relative to the initial
             * state. Choose the closest board/alight time among trips starting yesterday, today, or
             * tomorrow. Note that we cannot skip searching on service days that have not started
             * yet: Imagine a state at 23:59 Sunday, that should take a bus departing at 00:01
             * Monday (and coded on Monday in the GTFS); disallowing Monday's departures would
             * produce a strange plan. We also can't break off the search after we find trips today.
             * Imagine a trip on a pattern at 25:00 today and another trip on the same pattern at
             * 00:30 tommorrow. The 00:30 trip should be taken, but if we stopped the search after
             * 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
                // However, experiments seem to show very little measurable improvement here (due to cache locality?)
                // if ( ! timetable.temporallyViable(sd, s0.getTimeSeconds(), bestWait, boarding)) continue;
                /* Find the next or prev departure depending on final boolean parameter. */
                TripTimes tripTimes = timetable.getNextTrip(s0, sd, stopIndex, boarding);
                if (tripTimes != null) {
                    /* Wait is relative to departures on board and arrivals on alight. */
                    int wait = boarding ?
                        (int)(sd.time(tripTimes.getDepartureTime(stopIndex)) - s0.getTimeSeconds()):
                        (int)(s0.getTimeSeconds() - sd.time(tripTimes.getArrivalTime(stopIndex)));
                    /* A trip was found. The wait should be non-negative. */
                    if (wait < 0) LOG.error("Negative wait time when boarding.");
                    /* Track the soonest departure over all relevant schedules. */
                    if (bestWait < 0 || wait < bestWait) {
                        bestWait       = wait;
                        bestServiceDay = sd;
                        bestTripTimes  = tripTimes;
                    }
                }
            }
            if (bestWait < 0) return null; // no appropriate trip was found
            Trip trip = bestTripTimes.trip;
           
            /* check if route and/or Agency are banned for this plan */
            // FIXME this should be done WHILE searching for a trip.
            if (options.tripIsBanned(trip)) return null;

            /* Check if route is preferred by the user. */
            long preferences_penalty = options.preferencesPenaltyForRoute(getPattern().route);
           
            /* Compute penalty for non-preferred transfers. */
            int transferPenalty = 0;
            /* If this is not the first boarding, then we are transferring. */
            if (s0.isEverBoarded()) {
                TransferTable transferTable = options.getRoutingContext().transferTable;
                int transferTime = transferTable.getTransferTime(s0.getPreviousStop(),
                                   getStop(), s0.getPreviousTrip(), trip, boarding);
                transferPenalty  = transferTable.determineTransferPenalty(transferTime,
                                   options.nonpreferredTransferPenalty);
            }           

            /* Found a trip to board. Now make the child state. */
            StateEditor s1 = s0.edit(this);
            s1.setBackMode(getMode());
            s1.setServiceDay(bestServiceDay);
            // Save the trip times in the State to ensure that router has a consistent view
            // and constant-time access to them.
            s1.setTripTimes(bestTripTimes);
            s1.incrementTimeInSeconds(bestWait);
            s1.incrementNumBoardings();
            s1.setTripId(trip.getId());
            s1.setPreviousTrip(trip);
            s1.setZone(getPattern().getZone(stopIndex));
            s1.setRoute(trip.getRoute().getId());

            double wait_cost = bestWait;

            if (!s0.isEverBoarded() && !options.reverseOptimizing) {
                wait_cost *= options.waitAtBeginningFactor;
                s1.setInitialWaitTimeSeconds(bestWait);
            } else {
                wait_cost *= options.waitReluctance;
            }
           
            s1.incrementWeight(preferences_penalty);
            s1.incrementWeight(transferPenalty);

            // when reverse optimizing, the board cost needs to be applied on
            // alight to prevent state domination due to free alights
            if (options.reverseOptimizing) {
                s1.incrementWeight(wait_cost);
            } else {
                s1.incrementWeight(wait_cost + options.getBoardCost(s0.getNonTransitMode()));
            }
           
            // On-the-fly reverse optimization
            // determine if this needs to be reverse-optimized.
            // The last alight can be moved forward by bestWait (but no further) without
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

    private double maxTransitSpeed;
    private double requiredWalkDistance;

    @Override
    public void initialize(RoutingRequest options, Vertex origin, Vertex target, long abortTime) {
        RoutingRequest req = options;
        this.transit = req.modes.isTransit();
        maxStreetSpeed = req.getStreetSpeedUpperBound();
        maxTransitSpeed = req.getTransitSpeedUpperBound();
        targetX = target.getX();
        targetY = target.getY();
        requiredWalkDistance = determineRequiredWalkDistance(req);
        walkReluctance = req.walkReluctance;
    }
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

     * more than one trip on the same route at once (return more than one state).
     * The current implementation is a sketch and does not adequately
     */
    public Collection<StopTimesInPattern> stopTimesForStop(Stop stop) {
        List<StopTimesInPattern> ret = Lists.newArrayList();
        RoutingRequest req = new RoutingRequest();
        req.setRoutingContext(graph, (Vertex)null, (Vertex)null);
        State state = new State(req);
        for (TripPattern pattern : patternsForStop.get(stop)) {
            StopTimesInPattern times = new StopTimesInPattern(pattern);
            // Should actually be getUpdatedTimetable
            Timetable table = pattern.scheduledTimetable;
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

        double maxWeight = Double.MAX_VALUE;
        double maxWalk = options.getMaxWalkDistance();
        double initialMaxWalk = maxWalk;
        long maxTime = options.arriveBy ? 0 : Long.MAX_VALUE;
        RoutingRequest currOptions;
       
        SPTService sptService = this.sptServiceFactory.instantiate();
       
        while (paths.size() < options.numItineraries) {
            currOptions = optionQueue.poll();
            if (currOptions == null) {
                LOG.debug("Ran out of options to try.");
                break;
            }
            currOptions.setMaxWalkDistance(maxWalk);
           
            // apply appropriate timeout
            double timeout = paths.isEmpty() ? firstPathTimeout : multiPathTimeout;
           
            // options.worstTime = maxTime;
            //options.maxWeight = maxWeight;
            long subsearchBeginTime = System.currentTimeMillis();
           
            LOG.debug("BEGIN SUBSEARCH");
            ShortestPathTree spt = sptService.getShortestPathTree(currOptions, timeout);
            if (spt == null) {
                // Serious failure, no paths provided. This could be signaled with an exception.
                LOG.warn("Aborting search. {} paths found, elapsed time {} sec",
                        paths.size(), (System.currentTimeMillis() - searchBeginTime) / 1000.0);
                break;
            }
            List<GraphPath> somePaths = spt.getPaths(); // somePaths may be empty, but is never null.
            LOG.debug("END SUBSEARCH ({} msec of {} msec total)",
                    System.currentTimeMillis() - subsearchBeginTime,
                    System.currentTimeMillis() - searchBeginTime);
            LOG.debug("SPT provides {} paths to target.", somePaths.size());

            /* First, accumulate any new paths found into the list of itineraries. */
            for (GraphPath path : somePaths) {
                if ( ! paths.contains(path)) {
                    if (path.getWalkDistance() > maxWalk) {
                        maxWalk = path.getWalkDistance() * 1.25;
                    }
                    paths.add(path);
                    LOG.debug("New trips: {}", path.getTrips());
                    // ban the trips in this path
                    // unless is is a non-transit trip (in which case this would cause a useless retry)
                    if ( ! path.getTrips().isEmpty()) {
                        RoutingRequest newOptions = currOptions.clone();
                        for (AgencyAndId trip : path.getTrips()) {
                            newOptions.banTrip(trip);
                        }
                        if (!optionQueue.contains(newOptions)) {
                            optionQueue.add(newOptions);
                        }
                    }          
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

    }

    @Override
    public State traverse(State state0) {

        RoutingRequest options = state0.getOptions();
        Trip oldTrip = state0.getBackTrip();
        Trip newTrip = options.arriveBy ? trips.inverse().get(oldTrip) : trips.get(oldTrip);
        if (newTrip == null) return null;

        TripPattern newPattern;
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

        this.permission = permission;
    }
   
    @Override
    public State traverse(State s0) {
        RoutingRequest options = s0.getOptions();

        if (options.wheelchairAccessible && !wheelchairAccessible) {
            return null;
        }
       
View Full Code Here

Examples of org.opentripplanner.routing.core.RoutingRequest

        super(from, to, networks);
    }

    @Override
    public State traverse(State s0) {
        RoutingRequest options = s0.getOptions();
        if (options.arriveBy) {
            return super.traverseDropoff(s0);
        } else {
            return super.traverseRent(s0);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.