Package org.opentripplanner.routing.spt

Examples of org.opentripplanner.routing.spt.ShortestPathTree


    @Override /** completes the abstract CacheLoader superclass */
    public ShortestPathTree load(RoutingRequest req) throws Exception {
        LOG.debug("spt cache miss : {}", req);
        req.setRoutingContext(graphService.getGraph());
        long t0 = System.currentTimeMillis();
        ShortestPathTree spt = sptServiceFactory.instantiate().getShortestPathTree(req);
        long t1 = System.currentTimeMillis();
        LOG.debug("calculated spt in {}msec", (int) (t1 - t0));
        req.cleanup();
        return spt;
    }
View Full Code Here


        long tOvershot = (long) (2 * D0 / V0);
        sptRequest.worstTime = (sptRequest.dateTime
                + (sptRequest.arriveBy ? -spgRequest.maxTimeSec - tOvershot : spgRequest.maxTimeSec + tOvershot));
        sptRequest.batch = (true);
        sptRequest.setRoutingContext(graphService.getGraph(sptRequest.routerId));
        final ShortestPathTree spt = sptServiceFactory.instantiate().getShortestPathTree(sptRequest);

        // 3. Create a sample grid based on the SPT.
        long t1 = System.currentTimeMillis();
        Coordinate coordinateOrigin = spgRequest.coordinateOrigin;
        if (coordinateOrigin == null)
            coordinateOrigin = sptRequest.from.getCoordinate();
        final double gridSizeMeters = spgRequest.precisionMeters;
        final double cosLat = FastMath.cos(toRadians(coordinateOrigin.y));
        double dY = Math.toDegrees(gridSizeMeters / SphericalDistanceLibrary.RADIUS_OF_EARTH_IN_M);
        double dX = dY / cosLat;

        SparseMatrixZSampleGrid<WTWD> sampleGrid = new SparseMatrixZSampleGrid<WTWD>(16,
                spt.getVertexCount(), dX, dY, coordinateOrigin);
        sampleSPT(spt, sampleGrid, gridSizeMeters * 0.7, gridSizeMeters, V0,
                sptRequest.getMaxWalkDistance(), cosLat);
        sptRequest.cleanup();

        long t2 = System.currentTimeMillis();
View Full Code Here

     * @param optimize is true when optimization should be used
     * @return ordered list of states and edges in the journey
     */
    private GraphPath planJourney(RoutingRequest options, boolean optimize) {
        // Calculate route and convert to path
        ShortestPathTree spt = aStar.getShortestPathTree(options);
        GraphPath path = spt.getPath(options.rctx.target, optimize);

        // Return list of states and edges in the journey
        return path;
    }
View Full Code Here

        assertEquals(3, start.getDegreeIn());

        GenericAStar aStar = new GenericAStar();
        RoutingRequest opt = new RoutingRequest();
        opt.setRoutingContext(gg, start, end);
        ShortestPathTree spt = aStar.getShortestPathTree(opt);
        assertNotNull(spt);

        //test that the option to walk bikes on the first or last segment works
       
        opt = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
View Full Code Here

            RoutingRequest options = new RoutingRequest();
            options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009,
                    5 + rand.nextInt(4), 1 + rand.nextInt(20), 4 + rand.nextInt(10),
                    rand.nextInt(60), 0);

            ShortestPathTree spt;
            GraphPath path;

            options.setRoutingContext(graph, origin, destination);
            spt = aStar.getShortestPathTree(options);

            path = spt.getPath(destination, false);
            if (path == null)
                continue;

            System.out.println("Testing path between " + origin.getLabel() + " and "
                    + destination.getLabel() + " at " + new Date(options.dateTime * 1000));

            long arrivalTime1 = 0L;
            long elapsedTime1 = 0L;
            int numBoardings1 = 0;
            Vertex arrivalVertex1 = null;
            if (verbose)
                System.out.println("PATH 1 ---------------------");
            for (State s : path.states) {
                if (verbose)
                    System.out.println(s + " [" + s.getVertex().getClass().getName() + "]");
                arrivalTime1 = s.getTimeSeconds();
                arrivalVertex1 = s.getVertex();
                elapsedTime1 = s.getElapsedTimeSeconds();
                numBoardings1 = s.getNumBoardings();
            }

            /* Get a random transit hop from the computed path */
            Stop end = null;
            PatternStopVertex nextV = null;
            TripTimes tripTimes = null;
            int stopIndex = 0;
            long newStart = 0L;
            int nhop = 0;
            for (State s : path.states) {
                if (s.getVertex() instanceof PatternArriveVertex
                        && s.getBackEdge() instanceof PatternHop)
                    nhop++;
            }
            int hop = rand.nextInt(nhop);
            nhop = 0;
            float k = rand.nextFloat();
            for (State s : path.states) {
                Vertex v = s.getVertex();
                if (v instanceof PatternArriveVertex && s.getBackEdge() instanceof PatternHop) {
                    if (hop == nhop) {
                        PatternArriveVertex pav = (PatternArriveVertex) v;
                        end = pav.getStop();
                        nextV = pav;
                        PatternHop phe = (PatternHop) s.getBackEdge();
                        stopIndex = phe.getStopIndex();
                        tripTimes = s.getTripTimes();
                        int hopDuration = tripTimes.getRunningTime(stopIndex);
                        /*
                         * New start time at k% of hop. Note: do not try to make: round(time +
                         * k.hop) as it will be off few seconds due to floating-point rounding
                         * errors.
                         */
                        newStart = s.getBackState().getTimeSeconds() + Math.round(hopDuration * k);
                        break;
                    }
                    nhop++;
                }
            }
            System.out.println("Boarded depart: trip=" + tripTimes.trip + ", nextStop="
                    + nextV.getStop() + " stopIndex=" + stopIndex + " startTime="
                    + new Date(newStart * 1000L));

            /* And use it for onboard departure */
            double lat = end.getLat();
            double lon = end.getLon(); // Mock location, not really important here.
            OnboardDepartVertex onboardOrigin = new OnboardDepartVertex("OnBoard_Origin", lat, lon);
            @SuppressWarnings("unused")
            OnBoardDepartPatternHop currentHop = new OnBoardDepartPatternHop(onboardOrigin, nextV,
                    tripTimes, options.rctx.serviceDays.get(1), stopIndex, k);

            options.dateTime = newStart;
            options.setRoutingContext(graph, onboardOrigin, destination);
            spt = aStar.getShortestPathTree(options);

            /* Re-compute a new path starting boarded */
            GraphPath path2 = spt.getPath(destination, false);
            assertNotNull(path2);
            if (verbose)
                System.out.println("PATH 2 ---------------------");
            long arrivalTime2 = 0L;
            long elapsedTime2 = 0L;
View Full Code Here

        snp1.apply(graph);

        Vertex stop_a = graph.getVertex("agency:A");
        Vertex stop_e = graph.getVertex("agency:E_arrive");

        ShortestPathTree spt;
        GraphPath optimizedPath, unoptimizedPath;

        options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
        options.setRoutingContext(graph, stop_a, stop_e);
        spt = aStar.getShortestPathTree(options);

        optimizedPath = spt.getPath(stop_e, true);
        unoptimizedPath = spt.getPath(stop_e, false);
        assertNotNull(optimizedPath);
        HashSet<Alert> expectedAlerts = new HashSet<Alert>();
        expectedAlerts.add(note1);

        Edge optimizedEdge = optimizedPath.states.get(1).getBackEdge();
View Full Code Here

        snp1.apply(graph);

        Vertex stop_a = graph.getVertex("agency:A");
        Vertex stop_e = graph.getVertex("agency:E_arrive");

        ShortestPathTree spt;
        GraphPath path;

        options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 0, 0);
        options.setRoutingContext(graph, stop_a, stop_e);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(stop_e, true);
        assertNotNull(path);
        // expect no notes because we are during the break
        State noAlertPatchesState = path.states.get(1);
        Edge noAlertPatchesEdge = noAlertPatchesState.getBackEdge();
        HashSet<Alert> noAlertPatchesAlerts = new HashSet<Alert>();
        for (AlertPatch alertPatch : graph.getAlertPatches(noAlertPatchesEdge)) {
            if (alertPatch.displayDuring(noAlertPatchesState)) {
                noAlertPatchesAlerts.add(alertPatch.getAlert());
            }
        }
        assertEquals(new HashSet<Alert>(), noAlertPatchesAlerts);

        // now a trip during the second period
        options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 8, 0, 0);
        options.setRoutingContext(graph, stop_a, stop_e);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(stop_e, false); // do not optimize because we want the first trip
        assertNotNull(path);
        HashSet<Alert> expectedNotes = new HashSet<Alert>();
        expectedNotes.add(note1);
        State oneAlertPatchState = path.states.get(1);
        Edge oneAlertPatchEdge = oneAlertPatchState.getBackEdge();
View Full Code Here

        rnp1.apply(graph);

        Vertex stop_a = graph.getVertex("agency:A");
        Vertex stop_e = graph.getVertex("agency:E_arrive");

        ShortestPathTree spt;
        GraphPath path;

        options.setRoutingContext(graph, stop_a, stop_e);
        spt = aStar.getShortestPathTree(options);

        path = spt.getPath(stop_e, false);
        assertNotNull(path);
        HashSet<Alert> expectedAlerts = new HashSet<Alert>();
        expectedAlerts.add(note1);
        Edge actualEdge = path.states.get(2).getBackEdge();
        HashSet<Alert> actualAlerts = new HashSet<Alert>();
View Full Code Here

        Date date = request.getDateTime();
        MinMap<Vertex, Double> points = new MinMap<Vertex, Double>();
        for (int r = 0; r < nRequests; r++) {
            request.dateTime = date.getTime() / 1000 + r * requestSpacingMinutes * 60;
            LOG.debug("date: {} {}", new Date(request.dateTime), request.dateTime);
            ShortestPathTree spt = sptService.getShortestPathTree(request, 10);
            /* This could even be a good use for a generic SPT merging function */
            for (State s : spt.getAllStates()) {
                if ( stopsOnly && ! (s.getVertex() instanceof TransitStop)) continue;
                points.putMin(s.getVertex(), (double)(s.getActiveTime()));
            }
        }
        graph.removeVertexAndEdges(origin);
View Full Code Here

        RoutingRequest options = new RoutingRequest();
        options.carSpeed = 1.0;
        options.walkSpeed = 1.0;

        options.setRoutingContext(_graph, topRight, bottomLeft);
        ShortestPathTree tree = new GenericAStar().getShortestPathTree(options);

        GraphPath path = tree.getPath(bottomLeft, false);
        assertNotNull(path);

        // Since there are no turn restrictions applied to the default modes (walking + transit)
        // the shortest path is 1st to Main, Main to 2nd, 2nd to Broad and Broad until the
        // corner of Broad and 3rd.
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.