use of org.opentripplanner.routing.core.TraverseModeSet 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.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.
the class InitialStopsTest method testInitialStopWalkSpeedIncrease.
/**
* Test that increasing the walk speed on a walk-to-transit search
* a) decreases or leaves unchanged all access times.
* b) allows access to a superset of the originally accessible stops.
* c) decreases at least some access times.
*
* There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
*/
@Test
public void testInitialStopWalkSpeedIncrease() throws Exception {
Graph g = buildGraphNoTransit();
addRegularStopGrid(g);
addTransitMultipleLines(g);
link(g);
g.index(new DefaultStreetVertexIndexFactory());
ProfileRequest req = new ProfileRequest();
req.fromLon = req.toLon = -83.0118;
req.fromLat = req.toLat = 39.9908;
req.date = new LocalDate(2015, 9, 17);
req.bikeSpeed = 4.1f;
req.walkSpeed = 1.3f;
req.fromTime = 7 * 3600;
req.toTime = 9 * 3600;
req.maxBikeTime = 20;
req.maxWalkTime = 20;
req.transitModes = new TraverseModeSet("TRANSIT");
req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("WALK");
RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
assertFalse(initialStops1.isEmpty());
// let's get crazy, set walk speed really high.
req.walkSpeed = 25f;
data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
// we should find decreases to at least some stops
boolean foundDecreases = false;
for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
it.advance();
// the reached stops from the faster search should be a superset of the reached stops from the slower search
assertTrue(initialStops2.containsKey(it.key()));
assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
}
assertTrue("No decreases were found due to increased walk speed", foundDecreases);
}
use of org.opentripplanner.routing.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.
the class InitialStopsTest method testInitialStopBikeSpeedIncrease.
/**
* Test that increasing the bike speed on a bike-to-transit search
* a) decreases or leaves unchanged all access times.
* b) allows access to a superset of the originally accessible stops.
*
* There was once a bug where bike speed was not correctly applied because we used the distance not the speed.
*/
@Test
public void testInitialStopBikeSpeedIncrease() throws Exception {
Graph g = buildGraphNoTransit();
addRegularStopGrid(g);
addTransitMultipleLines(g);
link(g);
g.index(new DefaultStreetVertexIndexFactory());
ProfileRequest req = new ProfileRequest();
req.fromLon = req.toLon = -83.0118;
req.fromLat = req.toLat = 39.9908;
req.date = new LocalDate(2015, 9, 17);
req.bikeSpeed = 4.1f;
req.walkSpeed = 1.3f;
req.fromTime = 7 * 3600;
req.toTime = 9 * 3600;
req.maxBikeTime = 20;
req.transitModes = new TraverseModeSet("TRANSIT");
req.accessModes = req.egressModes = req.directModes = new QualifiedModeSet("BICYCLE");
RaptorWorkerData data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
RepeatedRaptorProfileRouter rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops1 = rrpr.findInitialStops(false, data);
assertFalse(initialStops1.isEmpty());
// let's get crazy, set bike speed really high.
req.bikeSpeed = 25f;
data = RepeatedRaptorProfileRouter.getRaptorWorkerData(req, g, null, new TaskStatistics());
assertNotNull(data);
rrpr = new RepeatedRaptorProfileRouter(g, req);
TIntIntMap initialStops2 = rrpr.findInitialStops(false, data);
// we should find decreases to at least some stops
boolean foundDecreases = false;
for (TIntIntIterator it = initialStops1.iterator(); it.hasNext(); ) {
it.advance();
// the reached stops from the faster search should be a superset of the reached stops from the slower search
assertTrue(initialStops2.containsKey(it.key()));
assertTrue("Found increase in travel time to stop", initialStops2.get(it.key()) <= it.value());
foundDecreases = foundDecreases || initialStops2.get(it.key()) < it.value() - EPSILON;
}
assertTrue(foundDecreases);
}
use of org.opentripplanner.routing.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.
the class RepeatedRaptorTestResource method oneOrigin.
private void oneOrigin(double lat, double lon, String banAgency) {
ProfileRequest req = new ProfileRequest();
req.fromLat = lat;
req.fromLon = lon;
req.fromTime = 60 * 60 * 8;
req.toTime = 60 * 60 * 9;
req.walkSpeed = 2;
req.bikeSpeed = 4;
req.carSpeed = 8;
req.date = new LocalDate(2015, 04, 20);
// minutes
req.maxWalkTime = 20;
req.accessModes = new QualifiedModeSet("WALK");
req.egressModes = new QualifiedModeSet("WALK");
req.transitModes = new TraverseModeSet("TRANSIT");
req.analyst = true;
if (surfaceCache == null) {
LOG.error("You must run OTP with the --analyst option to enable spatial analysis features.");
}
final RepeatedRaptorProfileRouter router_a = new RepeatedRaptorProfileRouter(graph, req);
final RepeatedRaptorProfileRouter router_b = new RepeatedRaptorProfileRouter(graph, req);
router_b.banAgency = banAgency;
try {
router_a.route();
router_b.route();
} catch (VertexNotFoundException ex) {
LOG.error("vertex not found");
return;
}
System.out.printf("stop, min_a, min_b, min_diff, max_a, max_b, max_diff\n");
boolean decreased = false;
// Compare the propagated results
decreased = false;
TimeSurface.RangeSet timeSurfaces_a = router_a.timeSurfaceRangeSet;
TimeSurface.RangeSet timeSurfaces_b = router_b.timeSurfaceRangeSet;
for (Vertex destVertex : timeSurfaces_a.min.times.keySet()) {
int min_a = timeSurfaces_a.min.getTime(destVertex);
int max_a = timeSurfaces_a.max.getTime(destVertex);
int avg_a = timeSurfaces_a.avg.getTime(destVertex);
int min_b = timeSurfaces_b.min.getTime(destVertex);
int max_b = timeSurfaces_b.max.getTime(destVertex);
int avg_b = timeSurfaces_b.avg.getTime(destVertex);
long min_diff = (long) min_b - min_a;
long max_diff = (long) max_b - max_a;
long avg_diff = (long) avg_b - avg_a;
if (min_b == TimeSurface.UNREACHABLE) {
min_diff = Integer.MAX_VALUE;
max_diff = Integer.MAX_VALUE;
avg_diff = Integer.MAX_VALUE;
}
n_total += 1;
if (min_diff < 0 || max_diff < 0 || avg_diff < 0) {
n_decrease += 1;
sum_decrease += max_diff;
// Time decreased due to banning a route. This is bad, print it out.
System.out.printf("\"%s\",%d,%d,%d,%d,%d,%d\n", destVertex.getName(), min_a, min_b, min_diff, max_a, max_b, max_diff);
decreased = true;
} else if (avg_diff > 0) {
n_increase += 1;
}
}
if (decreased) {
LOG.error("Decreases happened at propagated street vertices for this origin!");
}
LOG.info("Street Vertices: {} increased, {} decreased out of {} destinations total", n_increase, n_decrease, n_total);
}
use of org.opentripplanner.routing.core.TraverseModeSet in project OpenTripPlanner by opentripplanner.
the class StreetUtils method pruneFloatingIslands.
public static void pruneFloatingIslands(Graph graph, int maxIslandSize, int islandWithStopMaxSize, String islandLogName) {
LOG.debug("pruning");
PrintWriter islandLog = null;
if (islandLogName != null && !islandLogName.isEmpty()) {
try {
islandLog = new PrintWriter(new File(islandLogName));
} catch (Exception e) {
LOG.error("Failed to write islands log file", e);
}
}
if (islandLog != null) {
islandLog.printf("%s\t%s\t%s\t%s\t%s\n", "id", "stopCount", "streetCount", "wkt", "hadRemoved");
}
Map<Vertex, Subgraph> subgraphs = new HashMap<Vertex, Subgraph>();
Map<Vertex, ArrayList<Vertex>> neighborsForVertex = new HashMap<Vertex, ArrayList<Vertex>>();
// RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK, TraverseMode.TRANSIT));
RoutingRequest options = new RoutingRequest(new TraverseModeSet(TraverseMode.WALK));
for (Vertex gv : graph.getVertices()) {
if (!(gv instanceof StreetVertex)) {
continue;
}
State s0 = new State(gv, options);
for (Edge e : gv.getOutgoing()) {
Vertex in = gv;
if (!(e instanceof StreetEdge || e instanceof StreetTransitLink || e instanceof ElevatorEdge || e instanceof FreeEdge)) {
continue;
}
State s1 = e.traverse(s0);
if (s1 == null) {
continue;
}
Vertex out = s1.getVertex();
ArrayList<Vertex> vertexList = neighborsForVertex.get(in);
if (vertexList == null) {
vertexList = new ArrayList<Vertex>();
neighborsForVertex.put(in, vertexList);
}
vertexList.add(out);
vertexList = neighborsForVertex.get(out);
if (vertexList == null) {
vertexList = new ArrayList<Vertex>();
neighborsForVertex.put(out, vertexList);
}
vertexList.add(in);
}
}
ArrayList<Subgraph> islands = new ArrayList<Subgraph>();
/* associate each node with a subgraph */
for (Vertex gv : graph.getVertices()) {
if (!(gv instanceof StreetVertex)) {
continue;
}
Vertex vertex = gv;
if (subgraphs.containsKey(vertex)) {
continue;
}
if (!neighborsForVertex.containsKey(vertex)) {
continue;
}
Subgraph subgraph = computeConnectedSubgraph(neighborsForVertex, vertex);
if (subgraph != null) {
for (Iterator<Vertex> vIter = subgraph.streetIterator(); vIter.hasNext(); ) {
Vertex subnode = vIter.next();
subgraphs.put(subnode, subgraph);
}
islands.add(subgraph);
}
}
LOG.info(islands.size() + " sub graphs found");
/* remove all tiny subgraphs and large subgraphs without stops */
for (Subgraph island : islands) {
boolean hadRemoved = false;
if (island.stopSize() > 0) {
// for islands with stops
if (island.streetSize() < islandWithStopMaxSize) {
depedestrianizeOrRemove(graph, island);
hadRemoved = true;
}
} else {
// for islands without stops
if (island.streetSize() < maxIslandSize) {
depedestrianizeOrRemove(graph, island);
hadRemoved = true;
}
}
if (islandLog != null) {
WriteNodesInSubGraph(island, islandLog, hadRemoved);
}
}
if (graph.removeEdgelessVertices() > 0) {
LOG.warn("Removed edgeless vertices after pruning islands");
}
}
Aggregations