Package org.opentripplanner.routing.graph

Examples of org.opentripplanner.routing.graph.Graph


        Vertex b = g.getVertex("A");
        assertEquals(a, b);
    }

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


        FreeEdge ee = new FreeEdge(a, b);
        assertNotNull(ee);
    }

    public void testGetEdgesOneEdge() {
        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);

        List<Edge> edges = new ArrayList<Edge>(g.getEdges());
        assertEquals(1, edges.size());
        assertEquals(ee, edges.get(0));
    }
View Full Code Here

        assertEquals(1, edges.size());
        assertEquals(ee, edges.get(0));
    }

    public void testGetEdgesMultiple() {
        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> expectedEdges = new HashSet<Edge>(4);
        expectedEdges.add(new FreeEdge(a, b));
        expectedEdges.add(new FreeEdge(b, c));
        expectedEdges.add(new FreeEdge(c, b));
        expectedEdges.add(new FreeEdge(c, a));

        Set<Edge> edges = new HashSet<Edge>(g.getEdges());
        assertEquals(4, edges.size());
        assertEquals(expectedEdges, edges);
    }
View Full Code Here

        assertEquals(4, edges.size());
        assertEquals(expectedEdges, edges);
    }

    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());
    }
View Full Code Here

        Set<StreetEdge> edges = new HashSet<StreetEdge>(g.getStreetEdges());
        assertEquals(0, edges.size());
    }

    public void testGetStreetEdgesSeveral() {
        Graph g = new Graph();
        StreetVertex a = new IntersectionVertex(g, "A", 5, 5);
        StreetVertex b = new IntersectionVertex(g, "B", 6, 6);
        StreetVertex c = new IntersectionVertex(g, "C", 3, 2);

        Set<Edge> allStreetEdges = new HashSet<Edge>(4);
        allStreetEdges.add(edge(a, b, 1.0));
        allStreetEdges.add(edge(b, c, 1.0));
        allStreetEdges.add(edge(c, b, 1.0));
        allStreetEdges.add(edge(c, a, 1.0));

        Set<StreetEdge> edges = new HashSet<StreetEdge>(g.getStreetEdges());
        assertEquals(4, edges.size());
        assertEquals(allStreetEdges, edges);
    }
View Full Code Here

        assertEquals(4, edges.size());
        assertEquals(allStreetEdges, edges);
    }

    public void testGetEdgesAndVerticesById() {
        Graph g = new Graph();
        StreetVertex a = new IntersectionVertex(g, "A", 5, 5);
        StreetVertex b = new IntersectionVertex(g, "B", 6, 6);
        StreetVertex c = new IntersectionVertex(g, "C", 3, 2);

        Set<Edge> allEdges = new HashSet<Edge>(4);
        allEdges.add(edge(a, b, 1.0));
        allEdges.add(edge(b, c, 1.0));
        allEdges.add(edge(c, b, 1.0));
        allEdges.add(edge(c, a, 1.0));

        // Before rebuilding the indices, they are empty.
        for (Edge e : allEdges) {
            assertNull(g.getEdgeById(e.getId()));
        }

        for (Vertex v : g.getVertices()) {
            assertNull(g.getVertexById(v.getIndex()));
        }

        g.rebuildVertexAndEdgeIndices();
        for (Edge e : allEdges) {
            assertEquals(e, g.getEdgeById(e.getId()));
        }

        for (Vertex v : g.getVertices()) {
            assertEquals(v, g.getVertexById(v.getIndex()));
        }
    }
View Full Code Here

    @Test
    public void testSetServiceDays() throws Exception {

        String agencyId = "AGENCY";
        Graph graph = mock(Graph.class);
        RoutingRequest routingRequest = mock(RoutingRequest.class);
        CalendarService calendarService = mock(CalendarService.class);

        when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("Europe/Budapest"));
        when(graph.getCalendarService()).thenReturn(calendarService);
        when(graph.getAgencyIds()).thenReturn(Collections.<String>singletonList(agencyId));
        when(calendarService.getTimeZoneForAgencyId(agencyId)).thenReturn(TimeZone.getTimeZone("Europe/Budapest"));

        when(routingRequest.getSecondsSinceEpoch())
            .thenReturn(
                1393750800L /* 2014-03-02T10:00:00+01:00 */,
 
View Full Code Here

import org.opentripplanner.routing.vertextype.IntersectionVertex;

public class TestOverlayGraph extends TestCase {
   
    public void testBasic() throws Exception {
        Graph g = new Graph();
        Vertex a = new IntersectionVertex(g, "a", 5, 5);
        Vertex b = new IntersectionVertex(g, "b", 6, 5);
        Vertex c = new IntersectionVertex(g, "c", 7, 5);
        Vertex d = new IntersectionVertex(g, "d", 8, 5);
        // vary weights so edges are not considered equal
        Edge ab = new SimpleEdge(a, b, 1, 1);
        Edge bc1 = new SimpleEdge(b, c, 1, 1);
        Edge bc2 = new SimpleEdge(b, c, 2, 2);
        Edge bc3 = new SimpleEdge(b, c, 3, 3);
        Edge cd1 = new SimpleEdge(c, d, 1, 1);
        Edge cd2 = new SimpleEdge(c, d, 2, 2);
        Edge cd3 = new SimpleEdge(c, d, 3, 3);
        OverlayGraph og = new OverlayGraph(g);
        assertEquals(g.countVertices(), og.countVertices());
        assertEquals(g.countEdges(), og.countEdges());
        for (Vertex v : g.getVertices()) {
            for (Edge e : v.getOutgoing()) {
                assertTrue(og.getOutgoing(v).contains(e));
                assertTrue(og.getIncoming(e.getToVertex()).contains(e));
            }
            for (Edge e : v.getIncoming()) {
                assertTrue(og.getIncoming(v).contains(e));
                assertTrue(og.getOutgoing(e.getFromVertex()).contains(e));
            }
        }
        assertTrue(og.getIncoming(a).size() == 0);
        assertTrue(og.getOutgoing(d).size() == 0);
       
        // add an edge that is not in the overlay
        Edge ad = new FreeEdge(a, d);
        assertTrue(d.getIncoming().size() == 4);
        assertTrue(og.getIncoming(d).size() == 3);
        assertTrue(a.getOutgoing().size() == 2);
        assertTrue(og.getOutgoing(a).size() == 1);
       
        // remove edges from overlaygraph
        og.removeEdge(bc1);
        og.removeEdge(bc2);

        assertEquals(og.countEdges(), g.countEdges() - 3);
        assertTrue(og.getOutgoing(b).size() == 1);
        assertTrue(og.getIncoming(c).size() == 1);
    }
View Full Code Here

public class TestShapefileStreetGraphBuilderImpl extends TestCase {

    @Test
    public void testBasic() throws Exception {
        Graph gg = new Graph();

        URL resource = getClass().getResource("nyc_streets/streets.shp");
        File file = null;
        if (resource != null) {
            file = new File(resource.getFile());
        }
        if (file == null || !file.exists()) {
            System.out.println("No New York City basemap; skipping; see comment here for details");
            /*
             * This test requires the New York City base map. Place it among the source
             * resources and Eclipse should automatically copy it over to the target directory.
             * Once you have prepared these files, you may need to 'refresh' in Eclipse's package
             * explorer to force Eclipse to notice the new resources.
             *
             * Recent versions of this map are available only in Arcview Geodatabase format.
             * For conversion to a Shapefile, you will need the archived MapInfo version at:
             * http://www.nyc.gov/html/dcp/html/bytes/bytesarchive.shtml#lion
             * Download the MapInfo file of Lion version 10B.
             *
             * This must then be converted to a ShapeFile as follows:
             * cd opentripplanner-graph-builder/src/test/resources/org/opentripplanner/graph_builder/impl/shapefile
             * mkdir nyc_streets       (this is where we will store the shapefile)
             * unzip nyc_lion10ami.zip (this should place zipfile contents in a ./lion directory)
             * ogr2ogr -f 'ESRI Shapefile' nyc_streets/streets.shp lion/MNLION1.tab
             * ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/SILION1.tab -nln streets
             * ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/QNLION1.tab -nln streets
             * ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/BKLION1.tab -nln streets
             * ogr2ogr -update -append -f 'ESRI Shapefile' nyc_streets lion/BXLION1.tab -nln streets
             *
             * Testing also requires NYC Subway data in GTFS in the same location:
             * wget http://data.topplabs.org/data/mta_nyct_subway/subway.zip
             */
            return;
        }

        ShapefileFeatureSourceFactoryImpl factory = new ShapefileFeatureSourceFactoryImpl(file);

        ShapefileStreetSchema schema = new ShapefileStreetSchema();
        schema.setIdAttribute("SegmentID");
        schema.setNameAttribute("Street");

        /* only featuretyp=0 are streets */
        CaseBasedBooleanConverter selector = new CaseBasedBooleanConverter("FeatureTyp", false);

        HashMap<String, Boolean> streets = new HashMap<String, Boolean>();
        streets.put("0", true);
        selector.setValues(streets);
        schema.setFeatureSelector(selector);
       
        /* street directions */
        CaseBasedTraversalPermissionConverter perms = new CaseBasedTraversalPermissionConverter(
                "TrafDir", StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE);

        perms.addPermission("W", StreetTraversalPermission.ALL,
                StreetTraversalPermission.PEDESTRIAN);
        perms.addPermission("A", StreetTraversalPermission.PEDESTRIAN,
                StreetTraversalPermission.ALL);
        perms.addPermission("T", StreetTraversalPermission.ALL, StreetTraversalPermission.ALL);

        schema.setPermissionConverter(perms);

        ShapefileStreetGraphBuilderImpl loader = new ShapefileStreetGraphBuilderImpl();
        loader.setFeatureSourceFactory(factory);
        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);

        for (Vertex v : gg.getVertices()) {
            if (v.getCoordinate().distance(vanderbiltAtPark) < 0.00005) {
                /* we need the correct vanderbilt at park.  In this case,
                 * that's the one facing west on vanderbilt.
                 */
                int numParks = 0;
View Full Code Here

       
        // Check that realtime updates are not ignored
        assertFalse(options.ignoreRealtimeUpdates);
       
        // Create (very simple) new graph
        Graph graph = new Graph();
       
        Stop stop1 = new Stop();
        stop1.setId(new AgencyAndId("agency", "stop1"));
        Stop stop2 = new Stop();
        stop2.setId(new AgencyAndId("agency", "stop2"));
View Full Code Here

TOP

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

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.