Search in sources :

Example 11 with Vertex

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

the class PortlandCustomNamer method nameAccordingToOrigin.

private String nameAccordingToOrigin(Graph graph, StreetEdge e, int maxDepth) {
    if (maxDepth == 0) {
        return null;
    }
    Vertex fromVertex = e.getFromVertex();
    for (StreetEdge in : Iterables.filter(fromVertex.getIncoming(), StreetEdge.class)) {
        if (in.hasBogusName()) {
            String name = nameAccordingToOrigin(graph, in, maxDepth - 1);
            if (name == null) {
                continue;
            }
            e.setName(new NonLocalizedString(name));
            return name;
        } else {
            String name = in.getName();
            e.setName(new NonLocalizedString(name));
            return name;
        }
    }
    return null;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) NonLocalizedString(org.opentripplanner.util.NonLocalizedString)

Example 12 with Vertex

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

the class AnalysisUtils method getComponentPolygons.

/**
 * Get polygons covering the components of the graph. The largest component (in terms of number
 * of nodes) will not overlap any other components (it will have holes); the others may overlap
 * each other.
 *
 * @param dateTime
 */
public static List<Geometry> getComponentPolygons(Graph graph, RoutingRequest options, long time) {
    DisjointSet<Vertex> components = getConnectedComponents(graph);
    LinkedListMultimap<Integer, Coordinate> componentCoordinates = LinkedListMultimap.create();
    options.setDummyRoutingContext(graph);
    for (Vertex v : graph.getVertices()) {
        for (Edge e : v.getOutgoing()) {
            State s0 = new State(v, time, options);
            State s1 = e.traverse(s0);
            if (s1 != null) {
                Integer component = components.find(e.getFromVertex());
                Geometry geometry = s1.getBackEdge().getGeometry();
                if (geometry != null) {
                    List<Coordinate> coordinates = new ArrayList<Coordinate>(Arrays.asList(geometry.getCoordinates()));
                    for (int i = 0; i < coordinates.size(); ++i) {
                        Coordinate coordinate = new Coordinate(coordinates.get(i));
                        coordinate.x = Math.round(coordinate.x * PRECISION) / PRECISION;
                        coordinate.y = Math.round(coordinate.y * PRECISION) / PRECISION;
                        coordinates.set(i, coordinate);
                    }
                    componentCoordinates.putAll(component, coordinates);
                }
            }
        }
    }
    // generate convex hull of each component
    List<Geometry> geoms = new ArrayList<Geometry>();
    int mainComponentSize = 0;
    int mainComponentIndex = -1;
    int component = 0;
    for (Integer key : componentCoordinates.keySet()) {
        List<Coordinate> coords = componentCoordinates.get(key);
        Coordinate[] coordArray = new Coordinate[coords.size()];
        ConvexHull hull = new ConvexHull(coords.toArray(coordArray), GeometryUtils.getGeometryFactory());
        Geometry geom = hull.getConvexHull();
        // buffer components which are mere lines so that they do not disappear.
        if (geom instanceof LineString) {
            // ~10 meters
            geom = geom.buffer(0.01);
        } else if (geom instanceof Point) {
            // ~50 meters, so that it shows up
            geom = geom.buffer(0.05);
        }
        geoms.add(geom);
        if (mainComponentSize < coordArray.length) {
            mainComponentIndex = component;
            mainComponentSize = coordArray.length;
        }
        ++component;
    }
    // subtract small components out of main component
    // (small components are permitted to overlap each other)
    Geometry mainComponent = geoms.get(mainComponentIndex);
    for (int i = 0; i < geoms.size(); ++i) {
        Geometry geom = geoms.get(i);
        if (i == mainComponentIndex) {
            continue;
        }
        mainComponent = mainComponent.difference(geom);
    }
    geoms.set(mainComponentIndex, mainComponent);
    return geoms;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ArrayList(java.util.ArrayList) ConvexHull(com.vividsolutions.jts.algorithm.ConvexHull) Point(com.vividsolutions.jts.geom.Point) Point(com.vividsolutions.jts.geom.Point) Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) State(org.opentripplanner.routing.core.State) Edge(org.opentripplanner.routing.graph.Edge)

Example 13 with Vertex

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

the class GraphIndexTest method testIdLookup.

public void testIdLookup() {
    /* Graph vertices */
    for (Vertex vertex : graph.index.vertexForId.values()) {
        if (vertex instanceof TransitStop) {
            Stop stop = ((TransitStop) vertex).getStop();
            Vertex index_vertex = graph.index.stopVertexForStop.get(stop);
            assertEquals(index_vertex, vertex);
        }
    }
    /* Agencies */
    String feedId = graph.getFeedIds().iterator().next();
    Agency agency;
    agency = graph.index.agenciesForFeedId.get(feedId).get("azerty");
    assertNull(agency);
    agency = graph.index.agenciesForFeedId.get(feedId).get("agency");
    assertEquals(agency.getId(), "agency");
    assertEquals(agency.getName(), "Fake Agency");
    /* Stops */
    graph.index.stopForId.get(new AgencyAndId("X", "Y"));
/* Trips */
// graph.index.tripForId;
// graph.index.routeForId;
// graph.index.serviceForId;
// graph.index.patternForId;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Agency(org.onebusaway.gtfs.model.Agency) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop)

Example 14 with Vertex

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

the class TripTimesTest method testBikesAllowed.

@Test
public void testBikesAllowed() {
    Graph graph = new Graph();
    Trip trip = new Trip();
    Route route = new Route();
    trip.setRoute(route);
    List<StopTime> stopTimes = Arrays.asList(new StopTime(), new StopTime());
    TripTimes s = new TripTimes(trip, stopTimes, new Deduplicator());
    RoutingRequest request = new RoutingRequest(TraverseMode.BICYCLE);
    Vertex v = new SimpleConcreteVertex(graph, "", 0.0, 0.0);
    request.setRoutingContext(graph, v, v);
    State s0 = new State(request);
    assertFalse(s.tripAcceptable(s0, 0));
    BikeAccess.setForTrip(trip, BikeAccess.ALLOWED);
    assertTrue(s.tripAcceptable(s0, 0));
    BikeAccess.setForTrip(trip, BikeAccess.NOT_ALLOWED);
    assertFalse(s.tripAcceptable(s0, 0));
}
Also used : SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) Graph(org.opentripplanner.routing.graph.Graph) State(org.opentripplanner.routing.core.State) SimpleConcreteVertex(org.opentripplanner.routing.graph.SimpleConcreteVertex) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 15 with Vertex

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

the class TestTransfers method testStopToStopTransfer.

public void testStopToStopTransfer() throws Exception {
    // Replace the transfer table with an empty table
    TransferTable table = new TransferTable();
    when(graph.getTransferTable()).thenReturn(table);
    // Compute a normal path between two stops
    Vertex origin = graph.getVertex(feedId + ":N");
    Vertex destination = graph.getVertex(feedId + ":H");
    // Set options like time and routing context
    RoutingRequest options = new RoutingRequest();
    options.dateTime = TestUtils.dateInSeconds("America/New_York", 2009, 7, 11, 11, 11, 0);
    options.setRoutingContext(graph, origin, destination);
    // Plan journey
    GraphPath path;
    List<Trip> trips;
    path = planJourney(options);
    trips = extractTrips(path);
    // Validate result
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.2", trips.get(1).getId().getId());
    // Add transfer to table, transfer time was 27600 seconds
    Stop stopK = new Stop();
    stopK.setId(new AgencyAndId(feedId, "K"));
    Stop stopF = new Stop();
    stopF.setId(new AgencyAndId(feedId, "F"));
    table.addTransferTime(stopK, stopF, null, null, null, null, 27601);
    // Plan journey
    path = planJourney(options);
    trips = extractTrips(path);
    // Check whether a later second trip was taken
    assertEquals("8.1", trips.get(0).getId().getId());
    assertEquals("4.3", trips.get(1).getId().getId());
    // Revert the graph, thus using the original transfer table again
    reset(graph);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) GraphPath(org.opentripplanner.routing.spt.GraphPath)

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