Package org.opentripplanner.routing.graph

Examples of org.opentripplanner.routing.graph.Vertex


        Stop stop1 = new Stop();
        stop1.setId(new AgencyAndId("agency", "stop1"));
        Stop stop2 = new Stop();
        stop2.setId(new AgencyAndId("agency", "stop2"));
       
        Vertex from = new TransitStop(graph, stop1);
        Vertex to = new TransitStop(graph, stop2);
       
        // Create dummy TimetableResolver
        TimetableResolver resolver = new TimetableResolver();
       
        // Mock TimetableSnapshotSource to return dummy TimetableResolver
View Full Code Here


        loader.setSchema(schema);

        loader.buildGraph(gg, new HashMap<Class<?>, Object>());

        //find start and end vertices
        Vertex start = null;
        Vertex end = null;
        Vertex carlton = null;
       
        Coordinate vanderbiltAtPark = new Coordinate(-73.969178, 40.676785);
        Coordinate grandAtLafayette = new Coordinate(-73.999095, 40.720005);
        Coordinate carltonAtPark = new Coordinate(-73.972347, 40.677447);
View Full Code Here

        int n = 0;
        while (true) {

            /* Compute a normal path between two random stops... */
            Vertex origin, destination;
            do {
                /* See FAKE_GTFS for available locations */
                origin = graph.getVertex("agency:" + (char) (65 + rand.nextInt(20)));
                destination = graph.getVertex("agency:" + (char) (65 + rand.nextInt(20)));
            } while (origin.equals(destination));

            /* ...at a random date/time */
            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;
            int numBoardings2 = 0;
            Vertex arrivalVertex2 = null;
            for (State s : path2.states) {
                if (verbose)
                    System.out.println(s + " [" + s.getVertex().getClass().getName() + "]");
                arrivalTime2 = s.getTimeSeconds();
                arrivalVertex2 = s.getVertex();
View Full Code Here

        snp1.setAlert(note1);
        snp1.setId("id1");
        snp1.setStop(new AgencyAndId("agency", "A"));
        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);
View Full Code Here

        snp1.setAlert(note1);
        snp1.setId("id1");
        snp1.setStop(new AgencyAndId("agency", "A"));
        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);
View Full Code Here

        rnp1.setAlert(note1);
        rnp1.setId("id1");
        rnp1.setRoute(new AgencyAndId("agency", "1"));
        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);
View Full Code Here

                    onboardVertices.add(onboardVertex);
                }

                // -1 because we loop over onboardVertices two at a time
                for (Integer i = 0, vSize = onboardVertices.size() - 1; i < vSize; i++) {
                    Vertex from = onboardVertices.get(i);
                    Vertex to = onboardVertices.get(i + 1);

                    // default permissions: pedestrian, wheelchair, and bicycle
                    boolean wheelchairAccessible = true;
                    StreetTraversalPermission permission = StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE;
                    // check for bicycle=no, otherwise assume it's OK to take a bike
View Full Code Here

        /* Stage the point features in memory */
        DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(null, pointSchema);
        SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(pointSchema);
        GeometryFactory gf = new GeometryFactory();
        for (Map.Entry<Vertex, Double> entry : points.entrySet()) {
            Vertex vertex = entry.getKey();
            Double travelTime = entry.getValue();
            fbuilder.add(gf.createPoint(vertex.getCoordinate()));
            fbuilder.add(travelTime);
            featureCollection.add(fbuilder.buildFeature(null));
        }
        return featureCollection;
    }
View Full Code Here

        graph.putService(CalendarServiceData.class, GtfsLibrary.createCalendarServiceData(context.getDao()));
    }

    public void testGraphPathOptimize() throws Exception {

        Vertex stop_a = graph.getVertex("agency:A");
        Vertex stop_c = graph.getVertex("agency:C");
        Vertex stop_e = graph.getVertex("agency:E");

        ShortestPathTree spt;
        GraphPath path;

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

        path = spt.getPath(stop_e, false); /* do not optimize yet, since we are testing optimization */
        assertNotNull(path);

View Full Code Here

        coordinates[2] = new Coordinate(5.0, 5.0);

        coordinateSequence = coordinateSequenceFactory.create(coordinates);
        geometry = new LineString(coordinateSequence, geometryFactory);

        Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
        Edge edge = vertex.getOutgoing().toArray(new Edge[1])[0];

        assertEquals(vertex, edge.getFromVertex());
        assertEquals(dwell, edge.getToVertex());
        assertEquals("The right", edge.getDirection());
        assertEquals(geometry, edge.getGeometry());

        assertEquals(coordinates[0].x, vertex.getX(), 0.0);
        assertEquals(coordinates[0].y, vertex.getY(), 0.0);
    }
View Full Code Here

TOP

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

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.