use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class TestBikeRental method testBasic.
public void testBasic() throws Exception {
// generate a very simple graph
Graph graph = new Graph();
StreetVertex v1 = new IntersectionVertex(graph, "v1", -77.0492, 38.856, "v1");
StreetVertex v2 = new IntersectionVertex(graph, "v2", -77.0492, 38.857, "v2");
StreetVertex v3 = new IntersectionVertex(graph, "v3", -77.0492, 38.858, "v3");
@SuppressWarnings("unused") Edge walk = new StreetEdge(v1, v2, GeometryUtils.makeLineString(-77.0492, 38.856, -77.0492, 38.857), "S. Crystal Dr", 87, StreetTraversalPermission.PEDESTRIAN, false);
@SuppressWarnings("unused") Edge mustBike = new StreetEdge(v2, v3, GeometryUtils.makeLineString(-77.0492, 38.857, -77.0492, 38.858), "S. Crystal Dr", 87, StreetTraversalPermission.BICYCLE, false);
AStar aStar = new AStar();
// it is impossible to get from v1 to v3 by walking
RoutingRequest options = new RoutingRequest(new TraverseModeSet("WALK,TRANSIT"));
options.setRoutingContext(graph, v1, v3);
ShortestPathTree tree = aStar.getShortestPathTree(options);
GraphPath path = tree.getPath(v3, false);
assertNull(path);
// or biking + walking (assuming walking bikes is disallowed)
options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
options.freezeTraverseMode();
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
assertNull(path);
// so we add a bike share
BikeRentalStation station = new BikeRentalStation();
station.id = "id";
station.name = new NonLocalizedString("station");
station.x = -77.049;
station.y = 36.856;
station.bikesAvailable = 5;
station.spacesAvailable = 5;
BikeRentalStationVertex stationVertex = new BikeRentalStationVertex(graph, station);
new StreetBikeRentalLink(stationVertex, v2);
new StreetBikeRentalLink(v2, stationVertex);
Set<String> networks = new HashSet<String>(Arrays.asList("default"));
new RentABikeOnEdge(stationVertex, stationVertex, networks);
new RentABikeOffEdge(stationVertex, stationVertex, networks);
// but we can't get off the bike at v3, so we still fail
options = new RoutingRequest(new TraverseModeSet("WALK,BICYCLE,TRANSIT"));
options.freezeTraverseMode();
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
// null is returned because the only state at the target is not final
assertNull(path);
BikeRentalStation station2 = new BikeRentalStation();
station2.id = "id2";
station2.name = new NonLocalizedString("station2");
station2.x = -77.049;
station2.y = 36.857;
station2.bikesAvailable = 5;
station2.spacesAvailable = 5;
BikeRentalStationVertex stationVertex2 = new BikeRentalStationVertex(graph, station2);
new StreetBikeRentalLink(stationVertex2, v3);
new StreetBikeRentalLink(v3, stationVertex2);
new RentABikeOnEdge(stationVertex2, stationVertex2, networks);
new RentABikeOffEdge(stationVertex2, stationVertex2, networks);
// now we succeed!
options = new RoutingRequest();
new QualifiedModeSet("BICYCLE_RENT,TRANSIT").applyToRoutingRequest(options);
options.setRoutingContext(graph, v1, v3);
tree = aStar.getShortestPathTree(options);
path = tree.getPath(v3, false);
assertNotNull(path);
}
use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class CitiBikeNycBikeRentalDataSource method makeStation.
public BikeRentalStation makeStation(JsonNode stationNode) {
if (!stationNode.path("statusValue").asText().equals("In Service")) {
return null;
}
if (stationNode.path("testStation").asText().equals("true")) {
return null;
}
BikeRentalStation brstation = new BikeRentalStation();
brstation.networks = new HashSet<String>();
brstation.networks.add(this.networkName);
brstation.id = stationNode.path("id").toString();
brstation.x = stationNode.path("longitude").asDouble();
brstation.y = stationNode.path("latitude").asDouble();
brstation.name = new NonLocalizedString(stationNode.path("stationName").asText());
brstation.bikesAvailable = stationNode.path("availableBikes").asInt();
brstation.spacesAvailable = stationNode.path("availableDocks").asInt();
return brstation;
}
use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class GenericKmlBikeRentalDataSource method makeStation.
public BikeRentalStation makeStation(Map<String, String> attributes) {
if (!attributes.containsKey("name")) {
LOG.warn("Missing name in KML Placemark, cannot create bike rental.");
return null;
}
if (!attributes.containsKey("Point")) {
LOG.warn("Missing Point geometry in KML Placemark, cannot create bike rental.");
return null;
}
BikeRentalStation brStation = new BikeRentalStation();
brStation.name = new NonLocalizedString(attributes.get("name").trim());
if (namePrefix != null)
brStation.name = new NonLocalizedString(namePrefix + brStation.name);
String[] coords = attributes.get("Point").trim().split(",");
brStation.x = Double.parseDouble(coords[0]);
brStation.y = Double.parseDouble(coords[1]);
// There is no ID in KML, assume unique names and location
brStation.id = String.format(Locale.US, "%s[%.3f-%.3f]", brStation.name.toString().replace(" ", "_"), brStation.x, brStation.y);
brStation.realTimeData = false;
// Unknown, always 1
brStation.bikesAvailable = 1;
// Unknown, always 1
brStation.spacesAvailable = 1;
brStation.networks = networks;
brStation.allowDropoff = allowDropoff;
return brStation;
}
use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class JCDecauxBikeRentalDataSource method makeStation.
/**
* JSON JCDecaux API v1 format:
*
* <pre>
* [ {
* "number" : 94,
* "name" : "00094-PETIT PORT",
* "address" : "PETIT PORT - BD DU PETIT PORT",
* "position" : {
* "lat" : 47.243263914975486,
* "lng" : -1.556344610167984 },
* "banking" : true,
* "bonus" : false,
* "status" : "OPEN",
* "bike_stands" : 20,
* "available_bike_stands" : 1,
* "available_bikes" : 19,
* "last_update" : 1368611914000
* },
* ...
* ]
* </pre>
*/
public BikeRentalStation makeStation(JsonNode node) {
if (!node.path("status").asText().equals("OPEN")) {
return null;
}
BikeRentalStation station = new BikeRentalStation();
station.id = String.format("%d", node.path("number").asInt());
station.x = node.path("position").path("lng").asDouble();
station.y = node.path("position").path("lat").asDouble();
station.name = new NonLocalizedString(node.path("name").asText());
station.bikesAvailable = node.path("available_bikes").asInt();
station.spacesAvailable = node.path("available_bike_stands").asInt();
return station;
}
use of org.opentripplanner.routing.bike_rental.BikeRentalStation in project OpenTripPlanner by opentripplanner.
the class NextBikeRentalDataSource method makeStation.
public BikeRentalStation makeStation(Map<String, String> attributes) {
// some place entries appear to actually be checked-out bikes, not stations
if (attributes.get("bike") != null) {
return null;
}
BikeRentalStation brstation = new BikeRentalStation();
brstation.networks = new HashSet<String>();
brstation.networks.add(this.networkName);
brstation.id = attributes.get("number");
brstation.x = Double.parseDouble(attributes.get("lng"));
brstation.y = Double.parseDouble(attributes.get("lat"));
brstation.name = new NonLocalizedString(attributes.get("name"));
brstation.spacesAvailable = Integer.parseInt(attributes.get("bike_racks"));
// number of bikes available is reported as "5+" if >= 5
String numBikes = attributes.get("bikes");
if (numBikes.equals("5+")) {
brstation.bikesAvailable = 5;
} else {
brstation.bikesAvailable = Integer.parseInt(numBikes);
}
return brstation;
}
Aggregations