Search in sources :

Example 56 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class TestGraph method testAddEdge.

public void testAddEdge() throws Exception {
    Graph g = new Graph();
    Vertex a = new IntersectionVertex(g, "A", 5, 5);
    Vertex b = new IntersectionVertex(g, "B", 6, 6);
    FreeEdge ee = new FreeEdge(a, b);
    assertNotNull(ee);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge)

Example 57 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class TestGraph method testGetStreetEdgesNone.

public void testGetStreetEdgesNone() {
    Graph g = new Graph();
    Vertex a = new IntersectionVertex(g, "A", 5, 5);
    Vertex b = new IntersectionVertex(g, "B", 6, 6);
    Vertex c = new IntersectionVertex(g, "C", 3, 2);
    Set<Edge> allEdges = new HashSet<Edge>(4);
    allEdges.add(new FreeEdge(a, b));
    allEdges.add(new FreeEdge(b, c));
    allEdges.add(new FreeEdge(c, b));
    allEdges.add(new FreeEdge(c, a));
    Set<StreetEdge> edges = new HashSet<StreetEdge>(g.getStreetEdges());
    assertEquals(0, edges.size());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Graph(org.opentripplanner.routing.graph.Graph) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) FreeEdge(org.opentripplanner.routing.edgetype.FreeEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet)

Example 58 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class TestOnBoardRouting method testOnBoardRouting.

/**
 * Compute a set of path between two random stop locations in a test GTFS.
 *
 * For each departure/arrival location, compute a normal path (depart alighted). Then re-run the
 * same itinerary but with departure while on-board at a randomly-picked up trip alongside the
 * path.
 *
 * We assert that the two itineraries will arrive at the same time, at the same place, with at
 * least one less boarding, and take a less or equals amount of time.
 */
@SuppressWarnings("deprecation")
public void testOnBoardRouting() throws Exception {
    String feedId = graph.getFeedIds().iterator().next();
    // Seed the random generator to make consistent set of tests
    Random rand = new Random(42);
    // Number of tests to run
    final int NTESTS = 100;
    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(feedId + ":" + (char) (65 + rand.nextInt(20)));
            destination = graph.getVertex(feedId + ":" + (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();
        // Mock location, not really important here.
        double lon = end.getLon();
        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();
            elapsedTime2 = s.getElapsedTimeSeconds();
            numBoardings2 = s.getNumBoardings();
        }
        /* Arrival time and vertex *must* match */
        assertEquals(arrivalTime1, arrivalTime2);
        assertEquals(arrivalVertex1, destination);
        assertEquals(arrivalVertex2, destination);
        /* On-board *must* be shorter in time */
        assertTrue(elapsedTime2 <= elapsedTime1);
        /* On-board *must* have less boardings */
        assertTrue(numBoardings2 < numBoardings1);
        /* Cleanup edges */
        for (Edge edge : onboardOrigin.getOutgoing()) {
            graph.removeEdge(edge);
        }
        n++;
        if (n > NTESTS)
            break;
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) OnboardDepartVertex(org.opentripplanner.routing.vertextype.OnboardDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) PatternStopVertex(org.opentripplanner.routing.vertextype.PatternStopVertex) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath) OnboardDepartVertex(org.opentripplanner.routing.vertextype.OnboardDepartVertex) Date(java.util.Date) Random(java.util.Random) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) OnBoardDepartPatternHop(org.opentripplanner.routing.edgetype.OnBoardDepartPatternHop) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) PatternStopVertex(org.opentripplanner.routing.vertextype.PatternStopVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) OnBoardDepartPatternHop(org.opentripplanner.routing.edgetype.OnBoardDepartPatternHop) Edge(org.opentripplanner.routing.graph.Edge)

Example 59 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class SimpleStreetSplitterTest method testFindEndVertexForParkAndRide.

/**
 * Tests that traverse mode WALK is used when getting closest end vertex for park and ride.
 */
@Test
public void testFindEndVertexForParkAndRide() {
    GenericLocation genericLocation = new GenericLocation(10, 23);
    RoutingRequest routingRequest = new RoutingRequest();
    routingRequest.setMode(TraverseMode.CAR);
    routingRequest.parkAndRide = true;
    spySimpleStreetSplitter.getClosestVertex(genericLocation, routingRequest, true);
    verify(spySimpleStreetSplitter).link(any(Vertex.class), eq(TraverseMode.WALK), eq(routingRequest));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 60 with Vertex

use of org.opentripplanner.routing.graph.Vertex in project OpenTripPlanner by opentripplanner.

the class PlatformLinkerTest method testLinkEntriesToPlatforms.

/**
 * Test linking from stairs endpoint to to nodes in the ring defining the platform area.
 * OSM test data is from Skøyen station, Norway
 */
@Test
public void testLinkEntriesToPlatforms() throws Exception {
    String stairsEndpointLabel = "osm:node:1028861028";
    List<String> platformRingVertexLabels = Arrays.asList("osm:node:304045332", "osm:node:3238357455", "osm:node:1475363433", "osm:node:3238357491", "osm:node:1475363427", "osm:node:304045336", "osm:node:304045337", "osm:node:1475363437", "osm:node:3238357483", "osm:node:1475363443", "osm:node:1028860941", "osm:node:304045341", "osm:node:304045332");
    Graph gg = new Graph();
    OpenStreetMapModule loader = new OpenStreetMapModule();
    loader.platformEntriesLinking = true;
    loader.skipVisibility = true;
    loader.setDefaultWayPropertySetSource(new DefaultWayPropertySetSource());
    AnyFileBasedOpenStreetMapProviderImpl provider = new AnyFileBasedOpenStreetMapProviderImpl();
    File file = new File(URLDecoder.decode(FakeGraph.class.getResource("osm/skoyen.osm.pbf").getFile(), "UTF-8"));
    provider.setPath(file);
    loader.setProvider(provider);
    loader.buildGraph(gg, new HashMap<>());
    Vertex stairsEndpoint = gg.getVertex(stairsEndpointLabel);
    // verify outgoing links
    List<String> linkedRingVertecies = stairsEndpoint.getOutgoing().stream().map(edge -> edge.getToVertex().getLabel()).collect(Collectors.toList());
    // the endpoint has links to two nodes in OSM
    assertEquals(linkedRingVertecies.size() - 2, platformRingVertexLabels.size());
    for (String label : platformRingVertexLabels) {
        assert (linkedRingVertecies.contains(label));
    }
    // verify incoming links
    List<String> linkedRingVerteciesInn = stairsEndpoint.getIncoming().stream().map(edge -> edge.getFromVertex().getLabel()).collect(Collectors.toList());
    // the endpoint has links to two nodes in OSM
    assertEquals(linkedRingVerteciesInn.size() - 2, platformRingVertexLabels.size());
    for (String label : platformRingVertexLabels) {
        assert (linkedRingVerteciesInn.contains(label));
    }
}
Also used : Arrays(java.util.Arrays) List(java.util.List) URLDecoder(java.net.URLDecoder) Graph(org.opentripplanner.routing.graph.Graph) Vertex(org.opentripplanner.routing.graph.Vertex) Test(org.junit.Test) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) HashMap(java.util.HashMap) Collectors(java.util.stream.Collectors) File(java.io.File) Assert.assertEquals(org.junit.Assert.assertEquals) AnyFileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.AnyFileBasedOpenStreetMapProviderImpl) Vertex(org.opentripplanner.routing.graph.Vertex) Graph(org.opentripplanner.routing.graph.Graph) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) AnyFileBasedOpenStreetMapProviderImpl(org.opentripplanner.openstreetmap.impl.AnyFileBasedOpenStreetMapProviderImpl) File(java.io.File) Test(org.junit.Test)

Aggregations

Vertex (org.opentripplanner.routing.graph.Vertex)143 Edge (org.opentripplanner.routing.graph.Edge)63 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)45 GraphPath (org.opentripplanner.routing.spt.GraphPath)39 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)35 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)34 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)32 Graph (org.opentripplanner.routing.graph.Graph)29 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)28 Coordinate (com.vividsolutions.jts.geom.Coordinate)24 StreetVertex (org.opentripplanner.routing.vertextype.StreetVertex)24 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 State (org.opentripplanner.routing.core.State)20 Stop (org.onebusaway.gtfs.model.Stop)18 LineString (com.vividsolutions.jts.geom.LineString)16 ArrayList (java.util.ArrayList)16 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 Trip (org.onebusaway.gtfs.model.Trip)12 Envelope (com.vividsolutions.jts.geom.Envelope)11