Package org.opentripplanner.routing.spt

Examples of org.opentripplanner.routing.spt.ShortestPathTree


            LOG.debug("cannot set RoutingContext: " + e.toString());
            LOG.debug("cannot set RoutingContext: setting mode=WALK");
            sptRequestA.setMode(TraverseMode.WALK); // fall back to walk mode
            sptRequestA.setRoutingContext(graphService.getGraph());
        }
        ShortestPathTree sptA = sptService.getShortestPathTree(sptRequestA);
        StreetLocation origin = (StreetLocation) sptRequestA.rctx.fromVertex;
        sptRequestA.cleanup(); // remove inserted points

        // create a LineString for display
        Coordinate pathToStreetCoords[] = new Coordinate[2];
        pathToStreetCoords[0] = dropPoint;
        pathToStreetCoords[1] = origin.getCoordinate();
        LineString pathToStreet = gf.createLineString(pathToStreetCoords);

        // get distance between origin and drop point for time correction
        double distanceToRoad = this.distanceLibrary.distance(origin.getY(), origin.getX(),
                dropPoint.y, dropPoint.x);
        long offRoadTimeCorrection = (long) (distanceToRoad / this.offRoadWalkspeed);

        //
        // --- filter the states ---
        //
        Set<Coordinate> visitedCoords = new HashSet<Coordinate>();
        ArrayList<Edge> allConnectingEdges = new ArrayList<Edge>();
        Coordinate coords[] = null;
        long maxTime = (long) walkInSec - offRoadTimeCorrection;
        // System.out.println("Reducing walktime from: " + (int)(walkmins * 60) + "sec to " + maxTime + "sec due to initial walk of " + distanceToRoad
        // + "m");

        // if the initial walk is already to long, there is no need to parse...
        if (maxTime <= 0) {
            noRoadNearBy = true;
            long timeToWalk = (long) walkInSec;
            long timeBetweenStates = offRoadTimeCorrection;
            long timeMissing = timeToWalk;
            double fraction = (double) timeMissing / (double) timeBetweenStates;
            pathToStreet = getSubLineString(pathToStreet, fraction);
            LOG.debug(
                    "no street found within giving travel time (for off-road walkspeed: {} m/sec)",
                    this.offRoadWalkspeed);
        } else {
            noRoadNearBy = false;
            Map<ReversibleLineStringWrapper, Edge> connectingEdgesMap = Maps.newHashMap();
            for (State state : sptA.getAllStates()) {
                long et = state.getElapsedTimeSeconds();
                if (et <= maxTime) {
                    // -- filter points, as the same coordinate may be passed several times due to the graph structure
                    // in a Calgary suburb family homes neighborhood with a 15min walkshed it filtered about
                    // 250 points away (while 145 were finally displayed)
View Full Code Here


           
          req.setRoutingContext(graph);
         
            EarliestArrivalSPTService sptService = new EarliestArrivalSPTService();
            sptService.maxDuration = (60 * cutoffMinutes);
            ShortestPathTree spt = sptService.getShortestPathTree(req);
            req.cleanup();
            if (spt != null) {
                TimeSurface surface = new TimeSurface(spt);
                surface.params = Maps.newHashMap();
                for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
View Full Code Here

        long t0 = System.currentTimeMillis();
        sptRequest.worstTime = (sptRequest.dateTime
                + (sptRequest.arriveBy ? -isoChroneRequest.maxCutoffSec : isoChroneRequest.maxCutoffSec));
        sptRequest.batch = true;
        sptRequest.setRoutingContext(graphService.getGraph(sptRequest.routerId));
        final ShortestPathTree spt = sptService.getShortestPathTree(sptRequest);
        sptRequest.cleanup();

        // 2. Compute the set of initial points
        long t1 = System.currentTimeMillis();
        List<Coordinate> initialPoints = computeInitialPoints(spt);
View Full Code Here

    }

    /** @return the shortest path, or null if none is found */
    public ShortestPathTree getShortestPathTree(RoutingRequest options, double relTimeoutSeconds,
            SearchTerminationStrategy terminationStrategy) {
        ShortestPathTree spt = null;
        long abortTime = DateUtils.absoluteTimeout(relTimeoutSeconds);

        startSearch (options, terminationStrategy, abortTime);

        if (runState != null) {
View Full Code Here

    public ShortestPathTree getShortestPathTree(State initialState) {
        Vertex target = null;
        if (options.rctx != null) {
            target = initialState.getOptions().rctx.target;
        }
        ShortestPathTree spt = new BasicShortestPathTree(options);
        BinHeap<State> queue = new BinHeap<State>(1000);

        spt.add(initialState);
        queue.insert(initialState, initialState.getWeight());

        while (!queue.empty()) { // Until the priority queue is empty:
            State u = queue.extract_min();
            Vertex u_vertex = u.getVertex();

            if (traverseVisitor != null) {
                traverseVisitor.visitVertex(u);
            }

            if (!spt.getStates(u_vertex).contains(u)) {
                continue;
            }

            if (verbose) {
                System.out.println("min," + u.getWeight());
                System.out.println(u_vertex);
            }

            if (searchTerminationStrategy != null &&
                searchTerminationStrategy.shouldSearchTerminate(initialState.getVertex(), null, u, spt, options)) {
                break;
            }

            for (Edge edge : options.arriveBy ? u_vertex.getIncoming() : u_vertex.getOutgoing()) {
                if (skipEdgeStrategy != null &&
                    skipEdgeStrategy.shouldSkipEdge(initialState.getVertex(), null, u, edge, spt, options)) {
                    continue;
                }
                // Iterate over traversal results. When an edge leads nowhere (as indicated by
                // returning NULL), the iteration is over.
                for (State v = edge.traverse(u); v != null; v = v.getNextResult()) {
                    if (skipTraverseResultStrategy != null &&
                        skipTraverseResultStrategy.shouldSkipTraversalResult(initialState.getVertex(), null, u, v, spt, options)) {
                        continue;
                    }
                    if (traverseVisitor != null) {
                        traverseVisitor.visitEdge(edge, v);
                    }
                    if (verbose) {
                        System.out.printf("  w = %f + %f = %f %s", u.getWeight(), v.getWeightDelta(), v.getWeight(), v.getVertex());
                    }
                    if (v.exceedsWeightLimit(options.maxWeight)) continue;
                    if (spt.add(v)) {
                        double estimate = heuristic.computeForwardWeight(v, target);
                        queue.insert(v, v.getWeight() + estimate);
                        if (traverseVisitor != null) traverseVisitor.visitEnqueue(v);
                    }
                }
            }
            spt.postVisit(u);
        }
        return spt;
    }
View Full Code Here

    private List<State> streetSearch (RoutingRequest rr, boolean fromTarget, long abortTime) {
        rr = rr.clone();
        if (fromTarget)
            rr.setArriveBy( ! rr.arriveBy);
        List<State> stopStates = Lists.newArrayList();
        ShortestPathTree spt = new BasicShortestPathTree(rr);
        BinHeap<State> pq = new BinHeap<State>();
        Vertex initVertex = fromTarget ? rr.rctx.target : rr.rctx.origin;
        State initState = new State(initVertex, rr);
        pq.insert(initState, 0);
        while ( ! pq.empty()) {
            /**
             * Terminate the search prematurely if we've hit our computation wall.
             */
            if (abortTime < Long.MAX_VALUE  && System.currentTimeMillis() > abortTime) {
                return null;
            }

            State s = pq.extract_min();
            Double w = s.getWeight();
            Vertex v = s.getVertex();
            if (v instanceof TransitStationStop) {
                stopStates.add(s);
                // Prune street search upon reaching TransitStationStops.
                // Do not save weights at transit stops. Since they may be reached by
                // SimpleTransfer their weights will be recorded during the main heuristic search.
                continue;
            }
            // at this point the vertex is closed (pulled off heap).
            // on reverse search save measured weights.
            // on forward search set heuristic to 0 -- we have no idea how far to the destination,
            // the optimal path may use transit etc.
            if (!fromTarget) weights.put(v, 0.0);
            else {
                Double old_weight = weights.get(v);
                if (old_weight == null || old_weight > w) {
                    weights.put(v, w);
                }
            }

            for (Edge e : rr.arriveBy ? v.getIncoming() : v.getOutgoing()) {
                // arriveBy has been set to match actual directional behavior in this subsearch
                State s1 = e.traverse(s);
                if (s1 == null)
                    continue;
                if (spt.add(s1)) {
                    pq.insert(s1,  s1.getWeight());
                }
            }
        }
        // return a list of all stops hit
View Full Code Here

        final long maxt = maxDuration + options.clampInitialWait;
        options.worstTime = options.dateTime + (options.arriveBy ? -maxt : maxt);
           
        // SPT cache does not look at routing request in SPT to perform lookup,
        // so it's OK to construct with the local cloned one
        ShortestPathTree spt = new EarliestArrivalShortestPathTree(options);
        State initialState = new State(options);
        spt.add(initialState);

        BinHeap<State> pq = new BinHeap<State>();
        pq.insert(initialState, 0);

        while (!pq.empty()) {
            State u = pq.extract_min();
            Vertex u_vertex = u.getVertex();
            if (!spt.visit(u))
                continue;
            Collection<Edge> edges = options.arriveBy ? u_vertex.getIncoming() : u_vertex.getOutgoing();
            for (Edge edge : edges) {
                for (State v = edge.traverse(u); v != null; v = v.getNextResult()) {
                    if (isWorstTimeExceeded(v, options)) {
                        continue;
                    }
                    if (spt.add(v)) {
                        pq.insert(v, v.getActiveTime()); // activeTime?
                    }
                }
            }
        }
View Full Code Here

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

                    new NoThruTrafficPathParser() };
        }

        long searchBeginTime = System.currentTimeMillis();
       
        ShortestPathTree spt = sptService.getShortestPathTree(options, timeout);
       
        if(sptVisitor!=null){
          System.out.println( "setting spt" );
          sptVisitor.spt = spt;
        } else {
          System.out.println( "no spt visitor" );
        }
       
        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);
            return null;
        }
        for( GraphPath gp : spt.getPaths() ) {
          paths.add(gp);
        }
        LOG.debug("SPT provides {} paths to target.", paths.size());

        LOG.debug("{} / {} itineraries", paths.size(), options.numItineraries);
View Full Code Here

        if (options.maxWalkDistance == Double.MAX_VALUE) options.maxWalkDistance = DEFAULT_MAX_WALK;
        if (options.maxWalkDistance > CLAMP_MAX_WALK) options.maxWalkDistance = CLAMP_MAX_WALK;

        long searchBeginTime = System.currentTimeMillis();
        LOG.debug("BEGIN SEARCH");
        ShortestPathTree spt = sptService.getShortestPathTree(options, timeout);
        LOG.debug("END SEARCH ({} msec)", System.currentTimeMillis() - searchBeginTime);
       
        if (spt == null) { // timeout or other fail
            LOG.warn("SPT was null.");
            return null;
        }
       
        if( this.sptVisitor!=null ){
          this.sptVisitor.spt = spt;
        }
       
        //spt.getPaths().get(0).dump();
        List<GraphPath> paths = spt.getPaths();
        Collections.sort(paths, new PathWeightComparator());
        return paths;
    }
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.spt.ShortestPathTree

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.