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());
}
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.");
}
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;
}
Aggregations