Package org.opentripplanner.routing.spt

Examples of org.opentripplanner.routing.spt.BasicShortestPathTree


    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

  @Override
  public BasicShortestPathTree getTransitShed(Vertex origin, State originState,
      TraverseOptions options) {

    BasicShortestPathTree spt = new BasicShortestPathTree();

    Graph graph = _graphService.getGraph();

    FibHeap<State> queue = new FibHeap<State>(graph.getVertices().size());

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

    HashSet<Vertex> closed = new HashSet<Vertex>();

    ExtraEdgesStrategy extraEdgesStrategy = options.extraEdgesStrategy;

    Map<Vertex, List<Edge>> extraEdges = new HashMap<Vertex, List<Edge>>();
    extraEdgesStrategy.addOutgoingEdgesForOrigin(extraEdges, origin);
    if (extraEdges.isEmpty())
      extraEdges = Collections.emptyMap();

    while (!queue.empty()) {

      State state = queue.extract_min();

      Vertex fromVertex = state.getVertex();

      closed.add(fromVertex);

      if (_vertexSkipStrategy.isVertexSkippedInFowardSearch(origin,
          originState, state, options))
        continue;

      Iterable<Edge> outgoing = GraphLibrary.getOutgoingEdges(graph,
          fromVertex, extraEdges);

      for (Edge edge : outgoing) {

        for (State wr = edge.traverse(state); wr != null; wr = wr.getNextResult()) {

          EdgeNarrative er = wr.getBackEdgeNarrative();
          Vertex toVertex = er.getToVertex();

          if (!closed.contains(toVertex)) {

            if (spt.add(wr))
              queue.insert(wr, wr.getWeight());
          }
        }
      }
    }
View Full Code Here

    Coordinate c = new Coordinate(location.getLon(), location.getLat());
    Vertex origin = _streetVertexIndexService.getClosestVertex(c, options);

    State originState = new OBAState(time, origin, options);
    BasicShortestPathTree tree = _transitShedPathService.getTransitShed(origin,
        originState, options);

    Map<StopEntry, Long> results = new HashMap<StopEntry, Long>();

    for (State state : tree.getAllStates()) {

      OBAState obaState = (OBAState) state;
      Vertex v = state.getVertex();

      if (v instanceof AbstractStopVertex) {
View Full Code Here

TOP

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

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.