Search in sources :

Example 1 with BikeParkVertex

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

the class TestParkAndRide method testBike.

public void testBike() throws Exception {
    AStar aStar = new AStar();
    // Impossible to get from B to D in BIKE+WALK (no bike P+R).
    RoutingRequest options = new RoutingRequest("BICYCLE_PARK,TRANSIT");
    options.freezeTraverseMode();
    options.setRoutingContext(graph, B, D);
    ShortestPathTree tree = aStar.getShortestPathTree(options);
    GraphPath path = tree.getPath(D, false);
    assertNull(path);
    // So we add a bike P+R at C.
    BikePark bpc = new BikePark();
    bpc.id = "bpc";
    bpc.name = "Bike Park C";
    bpc.x = 0.002;
    bpc.y = 45.00001;
    bpc.spacesAvailable = 1;
    BikeParkVertex BPRC = new BikeParkVertex(graph, bpc);
    new BikeParkEdge(BPRC);
    new StreetBikeParkLink(BPRC, C);
    new StreetBikeParkLink(C, BPRC);
    // Still impossible from B to D by bike only (CD is WALK only).
    options = new RoutingRequest("BICYCLE");
    options.setRoutingContext(graph, B, D);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(D, false);
    assertNotNull(path);
    State s = tree.getState(D);
    assertFalse(s.isBikeParked());
    // TODO backWalkingBike flag is broken
    // assertTrue(s.isBackWalkingBike());
    assertTrue(s.getBackMode() == TraverseMode.WALK);
    // But we can go from B to D using bike P+R.
    options = new RoutingRequest("BICYCLE_PARK,WALK,TRANSIT");
    options.setRoutingContext(graph, B, D);
    tree = aStar.getShortestPathTree(options);
    path = tree.getPath(D, false);
    assertNotNull(path);
    s = tree.getState(D);
    assertTrue(s.isBikeParked());
    assertFalse(s.isBackWalkingBike());
}
Also used : BikeParkVertex(org.opentripplanner.routing.vertextype.BikeParkVertex) ShortestPathTree(org.opentripplanner.routing.spt.ShortestPathTree) State(org.opentripplanner.routing.core.State) GraphPath(org.opentripplanner.routing.spt.GraphPath) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) BikePark(org.opentripplanner.routing.bike_park.BikePark)

Example 2 with BikeParkVertex

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

the class BikeParkModule method buildGraph.

@Override
public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
    LOG.info("Building bike parks from static source...");
    BikeRentalStationService service = graph.getService(BikeRentalStationService.class, true);
    if (!dataSource.update()) {
        LOG.warn("No bike parks found from the data source.");
        return;
    }
    Collection<BikePark> bikeParks = dataSource.getBikeParks();
    for (BikePark bikePark : bikeParks) {
        service.addBikePark(bikePark);
        BikeParkVertex bikeParkVertex = new BikeParkVertex(graph, bikePark);
        new BikeParkEdge(bikeParkVertex);
    }
    LOG.info("Created " + bikeParks.size() + " bike parks.");
}
Also used : BikeParkVertex(org.opentripplanner.routing.vertextype.BikeParkVertex) BikeParkEdge(org.opentripplanner.routing.edgetype.BikeParkEdge) BikeRentalStationService(org.opentripplanner.routing.bike_rental.BikeRentalStationService) BikePark(org.opentripplanner.routing.bike_park.BikePark)

Example 3 with BikeParkVertex

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

the class BikeParkEdge method traversePark.

protected State traversePark(State s0) {
    RoutingRequest options = s0.getOptions();
    /*
         * To park a bike, we need to be riding one, (not rented) and be allowed to walk and to park
         * it.
         */
    if (s0.getNonTransitMode() != TraverseMode.BICYCLE || !options.modes.getWalk() || s0.isBikeRenting() || s0.isBikeParked())
        return null;
    BikeParkVertex bikeParkVertex = (BikeParkVertex) tov;
    if (bikeParkVertex.getSpacesAvailable() == 0) {
        return null;
    }
    StateEditor s0e = s0.edit(this);
    s0e.incrementWeight(options.bikeParkCost);
    s0e.incrementTimeInSeconds(options.bikeParkTime);
    s0e.setBackMode(TraverseMode.LEG_SWITCH);
    s0e.setBikeParked(true);
    State s1 = s0e.makeState();
    return s1;
}
Also used : BikeParkVertex(org.opentripplanner.routing.vertextype.BikeParkVertex) StateEditor(org.opentripplanner.routing.core.StateEditor) State(org.opentripplanner.routing.core.State) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest)

Aggregations

BikeParkVertex (org.opentripplanner.routing.vertextype.BikeParkVertex)3 BikePark (org.opentripplanner.routing.bike_park.BikePark)2 RoutingRequest (org.opentripplanner.routing.core.RoutingRequest)2 State (org.opentripplanner.routing.core.State)2 BikeRentalStationService (org.opentripplanner.routing.bike_rental.BikeRentalStationService)1 StateEditor (org.opentripplanner.routing.core.StateEditor)1 BikeParkEdge (org.opentripplanner.routing.edgetype.BikeParkEdge)1 GraphPath (org.opentripplanner.routing.spt.GraphPath)1 ShortestPathTree (org.opentripplanner.routing.spt.ShortestPathTree)1