Package org.opentripplanner.routing.graph

Examples of org.opentripplanner.routing.graph.Vertex$ValidEdgeTypes


     * Generates a TripPlan from a set of paths
     */
    TripPlan generatePlan(List<GraphPath> paths, RoutingRequest request) {

        GraphPath exemplar = paths.get(0);
        Vertex tripStartVertex = exemplar.getStartVertex();
        Vertex tripEndVertex = exemplar.getEndVertex();
        String startName = tripStartVertex.getName();
        String endName = tripEndVertex.getName();

        // Use vertex labels if they don't have names
        if (startName == null) {
            startName = tripStartVertex.getLabel();
        }
        if (endName == null) {
            endName = tripEndVertex.getLabel();
        }
        Place from = new Place(tripStartVertex.getX(), tripStartVertex.getY(), startName);
        Place to = new Place(tripEndVertex.getX(), tripEndVertex.getY(), endName);

        from.orig = request.from.name;
        to.orig = request.to.name;

        TripPlan plan = new TripPlan(from, to, request.getDateTime());
View Full Code Here


     * @param states The states that go with the leg
     * @param edges The edges that go with the leg
     * @param showIntermediateStops Whether to include intermediate stops in the leg or not
     */
    private void addPlaces(Leg leg, State[] states, Edge[] edges, boolean showIntermediateStops) {
        Vertex firstVertex = states[0].getVertex();
        Vertex lastVertex = states[states.length - 1].getVertex();

        Stop firstStop = firstVertex instanceof TransitVertex ?
                ((TransitVertex) firstVertex).getStop(): null;
        Stop lastStop = lastVertex instanceof TransitVertex ?
                ((TransitVertex) lastVertex).getStop(): null;
        TripTimes tripTimes = states[states.length - 1].getTripTimes();

        leg.from = makePlace(states[0], firstVertex, edges[0], firstStop, tripTimes);
        leg.from.arrival = null;
        leg.to = makePlace(states[states.length - 1], lastVertex, null, lastStop, tripTimes);
        leg.to.departure = null;

        if (showIntermediateStops) {
            leg.stop = new ArrayList<Place>();

            Stop previousStop = null;
            Stop currentStop;

            for (int i = 1; i < edges.length; i++) {
                Vertex vertex = states[i].getVertex();

                if (!(vertex instanceof TransitVertex)) continue;

                currentStop = ((TransitVertex) vertex).getStop();
                if (currentStop == firstStop) continue;
View Full Code Here

                        }
                    } else {
                        double angleDiff = getAbsoluteAngleDiff(lastAngle, thisAngle);
                        // FIXME: this code might be wrong with the removal of the edge-based graph
                        State twoStatesBack = backState.getBackState();
                        Vertex backVertex = twoStatesBack.getVertex();
                        for (Edge alternative : backVertex.getOutgoingStreetEdges()) {
                            List<Edge> alternatives = alternative.getToVertex()
                                    .getOutgoingStreetEdges();
                            if (alternatives.size() == 0) {
                                continue; // this is not an alternative
                            }
View Full Code Here

     * @return
     */
    private List<Coordinate> computeInitialPoints(ShortestPathTree spt) {
        List<Coordinate> retval = new ArrayList<Coordinate>(spt.getVertexCount());
        for (State s : spt.getAllStates()) {
            Vertex v = s.getVertex();
            // Take only street
            if (v instanceof StreetVertex) {
                retval.add(v.getCoordinate());
            }
        }
        LOG.debug("Created {} initial points from {} vertexes.", retval.size(),
                spt.getVertexCount());
        return retval;
View Full Code Here

    public static GraphPath findShortestPath(Vertex toVertex, Vertex fromVertex,
            Map<Vertex, HashMap<Vertex, GraphPath>> paths, HashSet<Vertex> vertices, long time, RoutingRequest options) {

        TSPPath shortestPath = findShortestPathInternal(toVertex, fromVertex, paths, vertices, 0);
       
        Vertex firstIntermediate = shortestPath.vertices.get(0);
       
        HashMap<Vertex, GraphPath> pathsFromFV = paths.get(fromVertex);
        //get the path from the end of the first subpath
        GraphPath newPath = new GraphPath(pathsFromFV.get(firstIntermediate).states.getLast(), false);
        Vertex lastVertex = firstIntermediate;
        for (Vertex v : shortestPath.vertices.subList(1, shortestPath.vertices.size())) {
               State lastState = newPath.states.getLast();
               GraphPath subPath = paths.get(lastVertex).get(v);
               //add a leg-switching state
               LegSwitchingEdge legSwitchingEdge = new LegSwitchingEdge(lastVertex, lastVertex);
View Full Code Here

                            nSkippedDupEdge++;
                            continue;
                        }
                        processedEdges.add(e);
                    }
                    Vertex vx0 = s0.getVertex();
                    Vertex vx1 = s1.getVertex();
                    LineString lineString = e.getGeometry();
                    if (lineString == null) {
                        nSkippedNoGeometry++;
                        continue;
                    }

                    // Length of linestring
                    double lineStringLen = distanceLibrary.fastLength(lineString);
                    visitor.visit(vx0.getCoordinate(), s0, s1, 0.0, lineStringLen);
                    visitor.visit(vx1.getCoordinate(), s0, s1, lineStringLen, 0.0);
                    nTotal += 2;
                    Coordinate[] pList = lineString.getCoordinates();
                    boolean reverse = vx1.getCoordinate().equals(pList[0]);
                    // Split the linestring in nSteps
                    if (lineStringLen > d0) {
                        int nSteps = (int) Math.floor(lineStringLen / d0) + 1; // Number of steps
                        double stepLen = lineStringLen / nSteps; // Length of step
                        double startLen = 0; // Distance at start of current seg
View Full Code Here

    public void setSkipTraverseResultStrategy(SkipTraverseResultStrategy skipTraverseResultStrategy) {
        this.skipTraverseResultStrategy = skipTraverseResultStrategy;
    }

    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
View Full Code Here

                LOG.debug("Emptied SSSP queue.");
                finished = true;
                break;
            }
            double uw = q.peek_min_key();
            Vertex u = q.extract_min();
            //LOG.info("dequeued weight {} at {}", uw, u);
//            // Ignore vertices that could be rekeyed (but are not rekeyed in this implementation).
//            if (uw > weights.get(u)) continue;
            // The weight of the queue head is uniformly increasing. This is the highest ever seen.
            maxFound = uw;
           
//            System.out.printf("H, %3.5f, %3.5f, %2.1f\n", u.getY(), u.getX(),
//                    Double.isInfinite(uw) ? -1.0 : uw);

            // OUTgoing for heuristic search when main search is arriveBy
            for (Edge e : options.arriveBy ? u.getOutgoing() : u.getIncoming()) {
                // Do not enter streets in this phase.
                if (e instanceof StreetTransitLink) continue;
                Vertex v = options.arriveBy ? e.getToVertex() : e.getFromVertex();
                double ew = e.weightLowerBound(options);
                // INF heuristic value indicates unreachable (e.g. non-running transit service)
                // this saves time by not reverse-exploring those routes and avoids maxFound of INF.
                if (Double.isInfinite(ew)) {
                    continue
View Full Code Here

     * All on-street vertices must be explored by the heuristic before the main search starts.
     * This allows us to completely skip walking outside a certain radius of the origin/destination.
     */
    @Override
    public double computeReverseWeight(State s, Vertex target) {
        final Vertex v = s.getVertex();
        // Temporary vertices (StreetLocations) might not be found in walk search.
        if (v instanceof StreetLocation) return 0;
        Double weight = weights.get(v);
        // All valid street vertices should be explored before the main search starts,
        // but many transit vertices may not yet be explored when the search starts.
        // TODO: verify that StreetVertex includes all vertices of interest.
        if (v instanceof StreetVertex) return weight == null ? Double.POSITIVE_INFINITY : weight;
        else if (weight == null) {
            double dist = distanceLibrary.fastDistance(v.getY(), v.getX(), target.getY(), target.getX());
            double time = dist / MAX_TRANSIT_SPEED;
            return Math.max(maxFound, time);
        }
        else return weight;
    }
View Full Code Here

        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)) {
View Full Code Here

TOP

Related Classes of org.opentripplanner.routing.graph.Vertex$ValidEdgeTypes

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.