Search in sources :

Example 76 with Vertex

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

the class ShowGraph method drawVertices.

private void drawVertices() {
    /* turn off vertex display when zoomed out */
    final double METERS_PER_DEGREE_LAT = 111111.111111;
    boolean closeEnough = (modelBounds.getHeight() * METERS_PER_DEGREE_LAT / this.width < 5);
    /* Draw selected visible vertices */
    for (Vertex v : visibleVertices) {
        if (drawTransitStopVertices && closeEnough && v instanceof TransitStationStop) {
            // Make transit stops blue dots
            fill(60, 60, 200);
            drawVertex(v, 7);
        }
        if (drawStreetVertices && v instanceof IntersectionVertex) {
            IntersectionVertex iv = (IntersectionVertex) v;
            if (iv.trafficLight) {
                // Make traffic lights red dots
                fill(120, 60, 60);
                drawVertex(v, 5);
            }
        }
        if (drawMultistateVertices && spt != null) {
            List<? extends State> states = spt.getStates(v);
            if (states != null) {
                fill(100, 60, 100);
                drawVertex(v, states.size() * 2);
            }
        }
    }
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) TransitStationStop(org.opentripplanner.routing.vertextype.TransitStationStop)

Example 77 with Vertex

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

the class ShowGraph method drawAnotation.

public void drawAnotation(GraphBuilderAnnotation anno) {
    Envelope env = new Envelope();
    Edge e = anno.getReferencedEdge();
    if (e != null) {
        this.enqueueHighlightedEdge(e);
        env.expandToInclude(e.getFromVertex().getCoordinate());
        env.expandToInclude(e.getToVertex().getCoordinate());
    }
    ArrayList<Vertex> vertices = new ArrayList<Vertex>();
    Vertex v = anno.getReferencedVertex();
    if (v != null) {
        env.expandToInclude(v.getCoordinate());
        vertices.add(v);
    }
    if (e == null && v == null)
        return;
    // make it a little bigger, especially needed for STOP_UNLINKED
    env.expandBy(0.02);
    // highlight relevant things
    this.clearHighlights();
    this.setHighlightedVertices(vertices);
    // zoom the graph display
    this.zoomToEnvelope(env);
    // and draw
    this.draw();
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) Envelope(com.vividsolutions.jts.geom.Envelope) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) PathwayEdge(org.opentripplanner.routing.edgetype.PathwayEdge) PatternEdge(org.opentripplanner.routing.edgetype.PatternEdge) Edge(org.opentripplanner.routing.graph.Edge)

Example 78 with Vertex

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

the class AddTripPatternTest method integrationTest.

/**
 * Test the full routing
 */
@Test
public void integrationTest() throws Exception {
    Graph g = buildGraphNoTransit();
    addTransit(g);
    link(g);
    ProfileRequest pr1 = new ProfileRequest();
    pr1.date = new LocalDate(2015, 6, 10);
    pr1.fromTime = 7 * 3600;
    pr1.toTime = 9 * 3600;
    pr1.fromLat = pr1.toLat = 39.9621;
    pr1.fromLon = pr1.toLon = -83.0007;
    RepeatedRaptorProfileRouter rrpr1 = new RepeatedRaptorProfileRouter(g, pr1);
    rrpr1.route();
    ProfileRequest pr2 = new ProfileRequest();
    pr2.date = new LocalDate(2015, 6, 10);
    pr2.fromTime = 7 * 3600;
    pr2.toTime = 9 * 3600;
    pr2.fromLat = pr2.toLat = 39.9621;
    pr2.fromLon = pr2.toLon = -83.0007;
    AddTripPattern atp = getAddTripPattern(RouteSelector.BROAD_HIGH);
    atp.timetables.add(getTimetable(true));
    pr2.scenario = new Scenario(0);
    pr2.scenario.modifications = Arrays.asList(atp);
    RepeatedRaptorProfileRouter rrpr2 = new RepeatedRaptorProfileRouter(g, pr2);
    rrpr2.route();
    boolean foundDecrease = false;
    // make sure that travel time did not increase
    for (TObjectIntIterator<Vertex> vit = rrpr1.timeSurfaceRangeSet.min.times.iterator(); vit.hasNext(); ) {
        vit.advance();
        int time2 = rrpr2.timeSurfaceRangeSet.min.getTime(vit.key());
        assertTrue(time2 <= vit.value());
        if (time2 < vit.value())
            foundDecrease = true;
    }
    assertTrue("found decreases in travel time due to adding route", foundDecrease);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) FakeGraph(org.opentripplanner.graph_builder.module.FakeGraph) Graph(org.opentripplanner.routing.graph.Graph) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test)

Example 79 with Vertex

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

the class RepeatedRaptorTestResource method oneOrigin.

private void oneOrigin(double lat, double lon, String banAgency) {
    ProfileRequest req = new ProfileRequest();
    req.fromLat = lat;
    req.fromLon = lon;
    req.fromTime = 60 * 60 * 8;
    req.toTime = 60 * 60 * 9;
    req.walkSpeed = 2;
    req.bikeSpeed = 4;
    req.carSpeed = 8;
    req.date = new LocalDate(2015, 04, 20);
    // minutes
    req.maxWalkTime = 20;
    req.accessModes = new QualifiedModeSet("WALK");
    req.egressModes = new QualifiedModeSet("WALK");
    req.transitModes = new TraverseModeSet("TRANSIT");
    req.analyst = true;
    if (surfaceCache == null) {
        LOG.error("You must run OTP with the --analyst option to enable spatial analysis features.");
    }
    final RepeatedRaptorProfileRouter router_a = new RepeatedRaptorProfileRouter(graph, req);
    final RepeatedRaptorProfileRouter router_b = new RepeatedRaptorProfileRouter(graph, req);
    router_b.banAgency = banAgency;
    try {
        router_a.route();
        router_b.route();
    } catch (VertexNotFoundException ex) {
        LOG.error("vertex not found");
        return;
    }
    System.out.printf("stop, min_a, min_b, min_diff, max_a, max_b, max_diff\n");
    boolean decreased = false;
    // Compare the propagated results
    decreased = false;
    TimeSurface.RangeSet timeSurfaces_a = router_a.timeSurfaceRangeSet;
    TimeSurface.RangeSet timeSurfaces_b = router_b.timeSurfaceRangeSet;
    for (Vertex destVertex : timeSurfaces_a.min.times.keySet()) {
        int min_a = timeSurfaces_a.min.getTime(destVertex);
        int max_a = timeSurfaces_a.max.getTime(destVertex);
        int avg_a = timeSurfaces_a.avg.getTime(destVertex);
        int min_b = timeSurfaces_b.min.getTime(destVertex);
        int max_b = timeSurfaces_b.max.getTime(destVertex);
        int avg_b = timeSurfaces_b.avg.getTime(destVertex);
        long min_diff = (long) min_b - min_a;
        long max_diff = (long) max_b - max_a;
        long avg_diff = (long) avg_b - avg_a;
        if (min_b == TimeSurface.UNREACHABLE) {
            min_diff = Integer.MAX_VALUE;
            max_diff = Integer.MAX_VALUE;
            avg_diff = Integer.MAX_VALUE;
        }
        n_total += 1;
        if (min_diff < 0 || max_diff < 0 || avg_diff < 0) {
            n_decrease += 1;
            sum_decrease += max_diff;
            // Time decreased due to banning a route. This is bad, print it out.
            System.out.printf("\"%s\",%d,%d,%d,%d,%d,%d\n", destVertex.getName(), min_a, min_b, min_diff, max_a, max_b, max_diff);
            decreased = true;
        } else if (avg_diff > 0) {
            n_increase += 1;
        }
    }
    if (decreased) {
        LOG.error("Decreases happened at propagated street vertices for this origin!");
    }
    LOG.info("Street Vertices: {} increased, {} decreased out of {} destinations total", n_increase, n_decrease, n_total);
}
Also used : RepeatedRaptorProfileRouter(org.opentripplanner.profile.RepeatedRaptorProfileRouter) Vertex(org.opentripplanner.routing.graph.Vertex) TimeSurface(org.opentripplanner.analyst.TimeSurface) QualifiedModeSet(org.opentripplanner.api.parameter.QualifiedModeSet) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) ProfileRequest(org.opentripplanner.profile.ProfileRequest) LocalDate(org.joda.time.LocalDate) VertexNotFoundException(org.opentripplanner.routing.error.VertexNotFoundException)

Example 80 with Vertex

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

the class StreetUtils method depedestrianizeOrRemove.

private static void depedestrianizeOrRemove(Graph graph, Subgraph island) {
    // iterate over the street vertex of the subgraph
    for (Iterator<Vertex> vIter = island.streetIterator(); vIter.hasNext(); ) {
        Vertex v = vIter.next();
        Collection<Edge> outgoing = new ArrayList<Edge>(v.getOutgoing());
        for (Edge e : outgoing) {
            if (e instanceof StreetEdge) {
                StreetEdge pse = (StreetEdge) e;
                StreetTraversalPermission permission = pse.getPermission();
                permission = permission.remove(StreetTraversalPermission.PEDESTRIAN);
                permission = permission.remove(StreetTraversalPermission.BICYCLE);
                if (permission == StreetTraversalPermission.NONE) {
                    graph.removeEdge(pse);
                } else {
                    pse.setPermission(permission);
                }
            }
        }
    }
    for (Iterator<Vertex> vIter = island.streetIterator(); vIter.hasNext(); ) {
        Vertex v = vIter.next();
        if (v.getDegreeOut() + v.getDegreeIn() == 0) {
            graph.remove(v);
        }
    }
    // remove street conncetion form
    for (Iterator<Vertex> vIter = island.stopIterator(); vIter.hasNext(); ) {
        Vertex v = vIter.next();
        Collection<Edge> edges = new ArrayList<Edge>(v.getOutgoing());
        edges.addAll(v.getIncoming());
        for (Edge e : edges) {
            if (e instanceof StreetTransitLink) {
                graph.removeEdge(e);
            }
        }
    }
    LOG.debug(graph.addBuilderAnnotation(new GraphConnectivity(island.getRepresentativeVertex(), island.streetSize())));
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) GraphConnectivity(org.opentripplanner.graph_builder.annotation.GraphConnectivity) Edge(org.opentripplanner.routing.graph.Edge)

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