Search in sources :

Example 21 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class BikeParkEdge method traverseUnpark.

protected State traverseUnpark(State s0) {
    RoutingRequest options = s0.getOptions();
    /*
         * To unpark a bike, we need to be walking, and be allowed to bike.
         */
    if (s0.getNonTransitMode() != TraverseMode.WALK || !options.modes.getBicycle())
        return null;
    StateEditor s0e = s0.edit(this);
    s0e.incrementWeight(options.bikeParkCost);
    s0e.incrementTimeInSeconds(options.bikeParkTime);
    s0e.setBackMode(TraverseMode.LEG_SWITCH);
    s0e.setBikeParked(false);
    State s1 = s0e.makeState();
    return s1;
}
Also used : StateEditor(org.opentripplanner.routing.core.StateEditor) State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Example 22 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class SimpleIsochrone method makePoints.

/**
 * @return a map from each vertex to minimum travel time over the course of the day.
 */
private Map<Vertex, Double> makePoints() throws Exception {
    rangeCheckParameters();
    request = buildRequest();
    Router router = otpServer.getRouter(routerId);
    Graph graph = router.graph;
    // double speed = request.getWalkSpeed();
    Coordinate originCoord = request.from.getCoordinate();
    if (originCoord == null)
        return null;
    List<TransitStop> stops = graph.streetIndex.getNearbyTransitStops(originCoord, radiusMeters);
    if (stops.isEmpty()) {
        LOG.error("No stops found within {} meters.", radiusMeters);
        return null;
    }
    if (shpName == null)
        shpName = stops.get(0).getName().split(" ")[0];
    StreetVertex origin = new IntersectionVertex(graph, "iso_temp", originCoord.x, originCoord.y);
    for (TransitStop stop : stops) {
        new StreetTransitLink(origin, stop, false);
        LOG.debug("linked to stop {}", stop.getName());
    }
    request.setRoutingContext(graph, origin, null);
    /* Make one request every M minutes over H hours */
    int nRequests = (requestTimespanHours * 60) / requestSpacingMinutes;
    request.clampInitialWait = (requestSpacingMinutes * 60);
    Date date = request.getDateTime();
    MinMap<Vertex, Double> points = new MinMap<Vertex, Double>();
    for (int r = 0; r < nRequests; r++) {
        request.dateTime = date.getTime() / 1000 + r * requestSpacingMinutes * 60;
        LOG.debug("date: {} {}", new Date(request.dateTime), request.dateTime);
        ShortestPathTree spt = sptService.getShortestPathTree(request, 10);
        /* This could even be a good use for a generic SPT merging function */
        for (State s : spt.getAllStates()) {
            if (stopsOnly && !(s.getVertex() instanceof TransitStop))
                continue;
            points.putMin(s.getVertex(), (double) (s.getActiveTime()));
        }
    }
    graph.removeVertexAndEdges(origin);
    return points;
}
Also used : StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex) Vertex(org.opentripplanner.routing.graph.Vertex) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Router(org.opentripplanner.standalone.Router) StreetTransitLink(org.opentripplanner.routing.edgetype.StreetTransitLink) Point(com.vividsolutions.jts.geom.Point) Date(java.util.Date) Graph(org.opentripplanner.routing.graph.Graph) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) IntersectionVertex(org.opentripplanner.routing.vertextype.IntersectionVertex) StreetVertex(org.opentripplanner.routing.vertextype.StreetVertex)

Example 23 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class TestHalfEdges method testHalfEdges.

@Test
public void testHalfEdges() {
    // the shortest half-edge from the start vertex takes you down, but the shortest total path
    // is up and over
    int nVertices = graph.getVertices().size();
    int nEdges = graph.getEdges().size();
    RoutingRequest options = new RoutingRequest();
    HashSet<Edge> turns = new HashSet<Edge>();
    turns.add(left);
    turns.add(leftBack);
    TemporaryStreetLocation start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start", new NonLocalizedString("start"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.4).getCoordinate(left.getGeometry()), false);
    HashSet<Edge> endTurns = new HashSet<Edge>();
    endTurns.add(right);
    endTurns.add(rightBack);
    TemporaryStreetLocation end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end", new NonLocalizedString("end"), filter(endTurns, StreetEdge.class), new LinearLocation(0, 0.8).getCoordinate(right.getGeometry()), true);
    assertTrue(start.getX() < end.getX());
    assertTrue(start.getY() < end.getY());
    Collection<Edge> edges = end.getIncoming();
    assertEquals(2, edges.size());
    long startTime = TestUtils.dateInSeconds("America/New_York", 2009, 11, 1, 12, 34, 25);
    options.dateTime = startTime;
    options.setRoutingContext(graph, br, end);
    options.setMaxWalkDistance(Double.MAX_VALUE);
    ShortestPathTree spt1 = aStar.getShortestPathTree(options);
    GraphPath pathBr = spt1.getPath(end, false);
    assertNotNull("There must be a path from br to end", pathBr);
    options.setRoutingContext(graph, tr, end);
    ShortestPathTree spt2 = aStar.getShortestPathTree(options);
    GraphPath pathTr = spt2.getPath(end, false);
    assertNotNull("There must be a path from tr to end", pathTr);
    assertTrue("path from bottom to end must be longer than path from top to end", pathBr.getWeight() > pathTr.getWeight());
    options.setRoutingContext(graph, start, end);
    ShortestPathTree spt = aStar.getShortestPathTree(options);
    GraphPath path = spt.getPath(end, false);
    assertNotNull("There must be a path from start to end", path);
    // the bottom is not part of the shortest path
    for (State s : path.states) {
        assertNotSame(s.getVertex(), graph.getVertex("bottom"));
        assertNotSame(s.getVertex(), graph.getVertex("bottomBack"));
    }
    options.setArriveBy(true);
    options.setRoutingContext(graph, start, end);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(start, false);
    assertNotNull("There must be a path from start to end (looking back)", path);
    // the bottom edge is not part of the shortest path
    for (State s : path.states) {
        assertNotSame(s.getVertex(), graph.getVertex("bottom"));
        assertNotSame(s.getVertex(), graph.getVertex("bottomBack"));
    }
    // Number of vertices and edges should be the same as before after a cleanup.
    options.cleanup();
    assertEquals(nVertices, graph.getVertices().size());
    assertEquals(nEdges, graph.getEdges().size());
    /*
         * Now, the right edge is not bikeable. But the user can walk their bike. So here are some tests that prove (a) that walking bikes works, but
         * that (b) it is not preferred to riding a tiny bit longer.
         */
    options = new RoutingRequest(new TraverseModeSet(TraverseMode.BICYCLE));
    start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start1", new NonLocalizedString("start1"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.95).getCoordinate(top.getGeometry()), false);
    end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end1", new NonLocalizedString("end1"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.95).getCoordinate(bottom.getGeometry()), true);
    options.setRoutingContext(graph, start, end);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(start, false);
    assertNotNull("There must be a path from top to bottom along the right", path);
    // the left edge is not part of the shortest path (even though the bike must be walked along the right)
    for (State s : path.states) {
        assertNotSame(s.getVertex(), graph.getVertex("left"));
        assertNotSame(s.getVertex(), graph.getVertex("leftBack"));
    }
    // Number of vertices and edges should be the same as before after a cleanup.
    options.cleanup();
    assertEquals(nVertices, graph.getVertices().size());
    assertEquals(nEdges, graph.getEdges().size());
    start = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "start2", new NonLocalizedString("start2"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.55).getCoordinate(top.getGeometry()), false);
    end = StreetVertexIndexServiceImpl.createTemporaryStreetLocation(graph, "end2", new NonLocalizedString("end2"), filter(turns, StreetEdge.class), new LinearLocation(0, 0.55).getCoordinate(bottom.getGeometry()), true);
    options.setRoutingContext(graph, start, end);
    spt = aStar.getShortestPathTree(options);
    path = spt.getPath(start, false);
    assertNotNull("There must be a path from top to bottom", path);
    // the right edge is not part of the shortest path, e
    for (State s : path.states) {
        assertNotSame(s.getVertex(), graph.getVertex("right"));
        assertNotSame(s.getVertex(), graph.getVertex("rightBack"));
    }
    // Number of vertices and edges should be the same as before after a cleanup.
    options.cleanup();
    assertEquals(nVertices, graph.getVertices().size());
    assertEquals(nEdges, graph.getEdges().size());
}
Also used : LinearLocation(com.vividsolutions.jts.linearref.LinearLocation) GraphPath(org.opentripplanner.routing.spt.GraphPath) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) TemporaryFreeEdge(org.opentripplanner.routing.edgetype.TemporaryFreeEdge) StreetEdge(org.opentripplanner.routing.edgetype.StreetEdge) Edge(org.opentripplanner.routing.graph.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 24 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class AStarTest method testBackExtraEdges.

@Test
public void testBackExtraEdges() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    options.setArriveBy(true);
    TemporaryStreetLocation from = new TemporaryStreetLocation("near_shilshole_22nd", new Coordinate(-122.385050, 47.666620), new NonLocalizedString("near_shilshole_22nd"), false);
    new TemporaryConcreteEdge(from, _graph.getVertex("shilshole_22nd"));
    TemporaryStreetLocation to = new TemporaryStreetLocation("near_56th_20th", new Coordinate(-122.382347, 47.669518), new NonLocalizedString("near_56th_20th"), true);
    new TemporaryConcreteEdge(_graph.getVertex("56th_20th"), to);
    options.setRoutingContext(_graph, from, to);
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    options.cleanup();
    GraphPath path = tree.getPath(from, false);
    List<State> states = path.states;
    assertEquals(9, states.size());
    assertEquals("near_shilshole_22nd", states.get(0).getVertex().getLabel());
    assertEquals("shilshole_22nd", states.get(1).getVertex().getLabel());
    assertEquals("ballard_22nd", states.get(2).getVertex().getLabel());
    assertEquals("market_22nd", states.get(3).getVertex().getLabel());
    assertEquals("market_leary", states.get(4).getVertex().getLabel());
    assertEquals("market_russell", states.get(5).getVertex().getLabel());
    assertEquals("market_20th", states.get(6).getVertex().getLabel());
    assertEquals("56th_20th", states.get(7).getVertex().getLabel());
    assertEquals("near_56th_20th", states.get(8).getVertex().getLabel());
}
Also used : TemporaryStreetLocation(org.opentripplanner.routing.location.TemporaryStreetLocation) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) Coordinate(com.vividsolutions.jts.geom.Coordinate) State(org.opentripplanner.routing.core.State) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) TemporaryConcreteEdge(org.opentripplanner.routing.graph.TemporaryConcreteEdge) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Example 25 with State

use of org.opentripplanner.routing.core.State in project OpenTripPlanner by opentripplanner.

the class AStarTest method testForward.

@Test
public void testForward() {
    RoutingRequest options = new RoutingRequest();
    options.walkSpeed = 1.0;
    options.setRoutingContext(_graph, _graph.getVertex("56th_24th"), _graph.getVertex("leary_20th"));
    ShortestPathTree tree = new AStar().getShortestPathTree(options);
    GraphPath path = tree.getPath(_graph.getVertex("leary_20th"), false);
    List<State> states = path.states;
    assertEquals(7, states.size());
    assertEquals("56th_24th", states.get(0).getVertex().getLabel());
    assertEquals("market_24th", states.get(1).getVertex().getLabel());
    assertEquals("market_ballard", states.get(2).getVertex().getLabel());
    assertEquals("market_22nd", states.get(3).getVertex().getLabel());
    assertEquals("market_leary", states.get(4).getVertex().getLabel());
    assertEquals("leary_vernon", states.get(5).getVertex().getLabel());
    assertEquals("leary_20th", states.get(6).getVertex().getLabel());
}
Also used : ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Test(org.junit.Test)

Aggregations

State (org.opentripplanner.routing.core.State)78 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)42 GraphPath (org.opentripplanner.routing.spt.GraphPath)25 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)24 Test (org.junit.Test)23 Edge (org.opentripplanner.routing.graph.Edge)22 Vertex (org.opentripplanner.routing.graph.Vertex)20 StreetEdge (org.opentripplanner.routing.edgetype.StreetEdge)13 Coordinate (com.vividsolutions.jts.geom.Coordinate)11 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)8 Graph (org.opentripplanner.routing.graph.Graph)7 DominanceFunction (org.opentripplanner.routing.spt.DominanceFunction)7 NonLocalizedString (org.opentripplanner.util.NonLocalizedString)6 LineString (com.vividsolutions.jts.geom.LineString)5 HashSet (java.util.HashSet)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 Trip (org.onebusaway.gtfs.model.Trip)5 StateEditor (org.opentripplanner.routing.core.StateEditor)5 TemporaryStreetLocation (org.opentripplanner.routing.location.TemporaryStreetLocation)5 IntersectionVertex (org.opentripplanner.routing.vertextype.IntersectionVertex)5