Search in sources :

Example 26 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method setUp.

@Before
public void setUp() {
    graph = new Graph();
    // a 0.1 degree x 0.1 degree square
    tl = new IntersectionVertex(graph, "tl", -74.01, 40.01);
    tr = new IntersectionVertex(graph, "tr", -74.0, 40.01);
    bl = new IntersectionVertex(graph, "bl", -74.01, 40.0);
    br = new IntersectionVertex(graph, "br", -74.00, 40.0);
    top = new StreetEdge(tl, tr, GeometryUtils.makeLineString(-74.01, 40.01, -74.0, 40.01), "top", 1500, StreetTraversalPermission.ALL, false);
    bottom = new StreetEdge(br, bl, GeometryUtils.makeLineString(-74.01, 40.0, -74.0, 40.0), "bottom", 1500, StreetTraversalPermission.ALL, false);
    left = new StreetEdge(bl, tl, GeometryUtils.makeLineString(-74.01, 40.0, -74.01, 40.01), "left", 1500, StreetTraversalPermission.ALL, false);
    right = new StreetEdge(br, tr, GeometryUtils.makeLineString(-74.0, 40.0, -74.0, 40.01), "right", 1500, StreetTraversalPermission.PEDESTRIAN, false);
    @SuppressWarnings("unused") StreetEdge topBack = new StreetEdge(tr, tl, (LineString) top.getGeometry().reverse(), "topBack", 1500, StreetTraversalPermission.ALL, true);
    @SuppressWarnings("unused") StreetEdge bottomBack = new StreetEdge(br, bl, (LineString) bottom.getGeometry().reverse(), "bottomBack", 1500, StreetTraversalPermission.ALL, true);
    leftBack = new StreetEdge(tl, bl, (LineString) left.getGeometry().reverse(), "leftBack", 1500, StreetTraversalPermission.ALL, true);
    rightBack = new StreetEdge(tr, br, (LineString) right.getGeometry().reverse(), "rightBack", 1500, StreetTraversalPermission.ALL, true);
    Stop s1 = new Stop();
    s1.setName("transitVertex 1");
    s1.setLon(-74.005);
    s1.setLat(40.0099999);
    s1.setId(new AgencyAndId("A", "fleem station"));
    Stop s2 = new Stop();
    s2.setName("transitVertex 2");
    s2.setLon(-74.002);
    s2.setLat(40.0099999);
    s2.setId(new AgencyAndId("A", "morx station"));
    station1 = new TransitStop(graph, s1);
    station2 = new TransitStop(graph, s2);
    station1.addMode(TraverseMode.RAIL);
    station2.addMode(TraverseMode.RAIL);
    graph.rebuildVertexAndEdgeIndices();
    // Linkers aren't run otherwise in testNetworkLinker
    graph.hasStreets = true;
    graph.hasTransit = true;
}
Also used : Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) LineString(com.vividsolutions.jts.geom.LineString) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Before(org.junit.Before)

Example 27 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class TestGraphPath method testGraphPathOptimize.

public void testGraphPathOptimize() throws Exception {
    String feedId = graph.getFeedIds().iterator().next();
    Vertex stop_a = graph.getVertex(feedId + ":A");
    Vertex stop_c = graph.getVertex(feedId + ":C");
    Vertex stop_e = graph.getVertex(feedId + ":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);
    // Check that the resulting path visits the stops in the right order.
    List<Vertex> stopvs = Lists.newArrayList();
    for (State state : path.states) {
        if (state.getVertex() instanceof TransitStop) {
            stopvs.add(state.getVertex());
        }
    }
    assertTrue(stopvs.get(0) == stop_a);
    assertTrue(stopvs.get(1) == stop_c);
    assertTrue(stopvs.get(2) == stop_e);
    long bestStart = TestUtils.dateInSeconds("America/New_York", 2009, 8, 7, 0, 20, 0);
    assertNotSame(bestStart, path.getStartTime());
    path = spt.getPath(stop_e, true);
    /* optimize */
    assertEquals(bestStart, path.getStartTime());
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 28 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class TestIgnoreRealtimeUpdates method testIgnoreRealtimeUpdates.

public void testIgnoreRealtimeUpdates() throws Exception {
    // Create routing request
    RoutingRequest options = new RoutingRequest();
    // 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"));
    Vertex from = new TransitStop(graph, stop1);
    Vertex to = new TransitStop(graph, stop2);
    // Create dummy TimetableSnapshot
    TimetableSnapshot snapshot = new TimetableSnapshot();
    // Mock TimetableSnapshotSource to return dummy TimetableSnapshot
    TimetableSnapshotSource source = mock(TimetableSnapshotSource.class);
    when(source.getTimetableSnapshot()).thenReturn(snapshot);
    graph.timetableSnapshotSource = (source);
    // Create routing context
    RoutingContext rctx = new RoutingContext(options, graph, from, to);
    // Check that the resolver is set as timetable snapshot
    assertNotNull(rctx.timetableSnapshot);
    // Now set routing request to ignore realtime updates
    options.ignoreRealtimeUpdates = (true);
    // Check that realtime updates are ignored
    assertTrue(options.ignoreRealtimeUpdates);
    // Create new routing context
    rctx = new RoutingContext(options, graph, from, to);
    // Check that the timetable snapshot is null in the new routing context
    assertNull(rctx.timetableSnapshot);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TimetableSnapshot(org.opentripplanner.routing.edgetype.TimetableSnapshot) TimetableSnapshotSource(org.opentripplanner.updater.stoptime.TimetableSnapshotSource)

Example 29 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class InterleavedBidirectionalHeuristic method streetSearch.

/**
 * Explore the streets around the origin or target, recording the minimum weight of a path to each street vertex.
 * When searching around the target, also retain the states that reach transit stops since we'll want to
 * explore the transit network backward, in order to guide the main forward search.
 *
 * The main search always proceeds from the "origin" to the "target" (names remain unchanged in arriveBy mode).
 * The reverse heuristic search always proceeds outward from the target (name remains unchanged in arriveBy).
 *
 * When the main search is departAfter:
 * it gets outgoing edges and traverses them with arriveBy=false,
 * the heuristic search gets incoming edges and traverses them with arriveBy=true,
 * the heuristic destination street search also gets incoming edges and traverses them with arriveBy=true,
 * the heuristic origin street search gets outgoing edges and traverses them with arriveBy=false.
 *
 * When main search is arriveBy:
 * it gets incoming edges and traverses them with arriveBy=true,
 * the heuristic search gets outgoing edges and traverses them with arriveBy=false,
 * the heuristic destination street search also gets outgoing edges and traverses them with arriveBy=false,
 * the heuristic origin street search gets incoming edges and traverses them with arriveBy=true.
 * The streetSearch method traverses using the real traverse method rather than the lower bound traverse method
 * because this allows us to keep track of the distance walked.
 * Perhaps rather than tracking walk distance, we should just check the straight-line radius and
 * only walk within that distance. This would avoid needing to call the main traversal functions.
 *
 * TODO what if the egress segment is by bicycle or car mode? This is no longer admissible.
 */
private TObjectDoubleMap<Vertex> streetSearch(RoutingRequest rr, boolean fromTarget, long abortTime) {
    LOG.debug("Heuristic street search around the {}.", fromTarget ? "target" : "origin");
    rr = rr.clone();
    if (fromTarget) {
        rr.setArriveBy(!rr.arriveBy);
    }
    // Create a map that returns Infinity when it does not contain a vertex.
    TObjectDoubleMap<Vertex> vertices = new TObjectDoubleHashMap<>(100, 0.5f, Double.POSITIVE_INFINITY);
    ShortestPathTree spt = new DominanceFunction.MinimumWeight().getNewShortestPathTree(rr);
    // TODO use normal OTP search for this.
    BinHeap<State> pq = new BinHeap<State>();
    Vertex initVertex = fromTarget ? rr.rctx.target : rr.rctx.origin;
    State initState = new State(initVertex, rr);
    pq.insert(initState, 0);
    while (!pq.empty()) {
        if (abortTime < Long.MAX_VALUE && System.currentTimeMillis() > abortTime) {
            return null;
        }
        State s = pq.extract_min();
        Vertex v = s.getVertex();
        // This is the lowest cost we will ever see for this vertex. We can record the cost to reach it.
        if (v instanceof TransitStop) {
            // place vertices on the transit queue so we can explore the transit network backward later.
            if (fromTarget) {
                double weight = s.getWeight();
                transitQueue.insert(v, weight);
                if (weight > maxWeightSeen) {
                    maxWeightSeen = weight;
                }
            }
            continue;
        }
        // Record the cost to reach this vertex.
        if (!vertices.containsKey(v)) {
            // FIXME time or weight? is RR using right mode?
            vertices.put(v, (int) s.getWeight());
        }
        for (Edge e : rr.arriveBy ? v.getIncoming() : v.getOutgoing()) {
            // arriveBy has been set to match actual directional behavior in this subsearch.
            // Walk cutoff will happen in the street edge traversal method.
            State s1 = e.traverse(s);
            if (s1 == null) {
                continue;
            }
            if (spt.add(s1)) {
                pq.insert(s1, s1.getWeight());
            }
        }
    }
    LOG.debug("Heuristric street search hit {} vertices.", vertices.size());
    LOG.debug("Heuristric street search hit {} transit stops.", transitQueue.size());
    return vertices;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) TObjectDoubleHashMap(gnu.trove.map.hash.TObjectDoubleHashMap) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) State(org.opentripplanner.routing.core.State) BinHeap(org.opentripplanner.common.pqueue.BinHeap) DominanceFunction(org.opentripplanner.routing.spt.DominanceFunction) Edge(org.opentripplanner.routing.graph.Edge)

Example 30 with TransitStop

use of org.opentripplanner.routing.vertextype.TransitStop in project OpenTripPlanner by opentripplanner.

the class GraphGeographicFilter method findHull.

public void findHull() {
    LOG.info("finding hull of graph...");
    LOG.debug("using only stops? {}", useOnlyStops);
    if (bufferMeters < prototypeRoutingRequest.maxWalkDistance)
        LOG.warn("geographic filter buffer is smaller than max walk distance, this will probably yield incorrect results.");
    Graph graph = graphService.getRouter(prototypeRoutingRequest.routerId).graph;
    List<Geometry> geometries = new ArrayList<Geometry>();
    for (Vertex v : graph.getVertices()) {
        if (useOnlyStops && !(v instanceof TransitStop))
            continue;
        Point pt = gf.createPoint(v.getCoordinate());
        Geometry geom = crudeProjectedBuffer(pt, bufferMeters);
        geometries.add(geom);
    }
    Geometry multiGeom = gf.buildGeometry(geometries);
    LOG.info("unioning hull...");
    hull = multiGeom.union();
    LOG.trace("hull is {}", hull.toText());
// may lead to false rejections
// DouglasPeuckerSimplifier simplifier = new DouglasPeuckerSimplifier();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Vertex(org.opentripplanner.routing.graph.Vertex) Graph(org.opentripplanner.routing.graph.Graph) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) ArrayList(java.util.ArrayList) Point(com.vividsolutions.jts.geom.Point)

Aggregations

TransitStop (org.opentripplanner.routing.vertextype.TransitStop)49 Stop (org.onebusaway.gtfs.model.Stop)20 Vertex (org.opentripplanner.routing.graph.Vertex)18 Edge (org.opentripplanner.routing.graph.Edge)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)13 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)12 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)11 Graph (org.opentripplanner.routing.graph.Graph)10 Envelope (com.vividsolutions.jts.geom.Envelope)8 LineString (com.vividsolutions.jts.geom.LineString)8 ArrayList (java.util.ArrayList)8 State (org.opentripplanner.routing.core.State)8 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)8 Agency (org.onebusaway.gtfs.model.Agency)7 Trip (org.onebusaway.gtfs.model.Trip)7 SimpleTransfer (org.opentripplanner.routing.edgetype.SimpleTransfer)7 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)7 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)7 Route (org.onebusaway.gtfs.model.Route)6