use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class WalkableAreaBuilder method pruneAreaEdges.
/**
* Do an all-pairs shortest path search from a list of vertices over a specified set of edges,
* and retain only those edges which are actually used in some shortest path.
*
* @param startingVertices
* @param edges
*/
private void pruneAreaEdges(Collection<Vertex> startingVertices, Set<Edge> edges) {
if (edges.size() == 0)
return;
TraverseMode mode;
StreetEdge firstEdge = (StreetEdge) edges.iterator().next();
if (firstEdge.getPermission().allows(StreetTraversalPermission.PEDESTRIAN)) {
mode = TraverseMode.WALK;
} else if (firstEdge.getPermission().allows(StreetTraversalPermission.BICYCLE)) {
mode = TraverseMode.BICYCLE;
} else {
mode = TraverseMode.CAR;
}
RoutingRequest options = new RoutingRequest(mode);
options.setDummyRoutingContext(graph);
options.dominanceFunction = new DominanceFunction.EarliestArrival();
GenericDijkstra search = new GenericDijkstra(options);
search.setSkipEdgeStrategy(new ListedEdgesOnly(edges));
Set<Edge> usedEdges = new HashSet<Edge>();
for (Vertex vertex : startingVertices) {
State state = new State(vertex, options);
ShortestPathTree spt = search.getShortestPathTree(state);
for (Vertex endVertex : startingVertices) {
GraphPath path = spt.getPath(endVertex, false);
if (path != null) {
for (Edge edge : path.edges) {
usedEdges.add(edge);
}
}
}
}
for (Edge edge : edges) {
if (!usedEdges.contains(edge)) {
graph.removeEdge(edge);
}
}
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class WheelchairEdgeRenderer method renderEdge.
@Override
public boolean renderEdge(Edge e, EdgeVertexTileRenderer.EdgeVisualAttributes attrs) {
if (e instanceof StreetEdge) {
StreetEdge pse = (StreetEdge) e;
if (!pse.isWheelchairAccessible()) {
attrs.color = NO_WHEELCHAIR_COLOR;
attrs.label = "wheelchair=no";
} else {
attrs.color = slopePalette.getColor(pse.getMaxSlope());
attrs.label = String.format("%.02f", pse.getMaxSlope());
}
} else {
return false;
}
return true;
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class RoutingContext method overlappingStreetEdges.
/**
* Returns the StreetEdges that overlap between two vertices edge sets.
*/
private Set<StreetEdge> overlappingStreetEdges(Vertex u, Vertex v) {
Set<Integer> vIds = new HashSet<Integer>();
Set<Integer> uIds = new HashSet<Integer>();
for (Edge e : Iterables.concat(v.getIncoming(), v.getOutgoing())) {
vIds.add(e.getId());
}
for (Edge e : Iterables.concat(u.getIncoming(), u.getOutgoing())) {
uIds.add(e.getId());
}
// Intesection of edge IDs between u and v.
uIds.retainAll(vIds);
Set<Integer> overlappingIds = uIds;
// Fetch the edges by ID - important so we aren't stuck with temporary edges.
Set<StreetEdge> overlap = new HashSet<>();
for (Integer id : overlappingIds) {
Edge e = graph.getEdgeById(id);
if (e == null || !(e instanceof StreetEdge)) {
continue;
}
overlap.add((StreetEdge) e);
}
return overlap;
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class ShowGraph method buildSpatialIndex.
/*
* Iterate through all vertices and their (outgoing) edges. If they are of 'interesting' types,
* add them to the corresponding spatial index.
*/
public synchronized void buildSpatialIndex() {
vertexIndex = new STRtree();
edgeIndex = new STRtree();
Envelope env;
// int xminx, xmax, ymin, ymax;
for (Vertex v : graph.getVertices()) {
Coordinate c = v.getCoordinate();
env = new Envelope(c);
vertexIndex.insert(env, v);
for (Edge e : v.getOutgoing()) {
if (e.getGeometry() == null)
continue;
if (e instanceof PatternEdge || e instanceof StreetTransitLink || e instanceof StreetEdge || e instanceof PathwayEdge || e instanceof SimpleTransfer) {
env = e.getGeometry().getEnvelopeInternal();
edgeIndex.insert(env, e);
}
}
}
vertexIndex.build();
edgeIndex.build();
}
use of org.opentripplanner.routing.edgetype.StreetEdge in project OpenTripPlanner by opentripplanner.
the class ShowGraph method drawGraphPath.
private void drawGraphPath(GraphPath gp) {
// draw edges in different colors according to mode
for (State s : gp.states) {
TraverseMode mode = s.getBackMode();
Edge e = s.getBackEdge();
if (e == null)
continue;
if (mode != null && mode.isTransit()) {
stroke(200, 050, 000);
strokeWeight(6);
drawEdge(e);
}
if (e instanceof StreetEdge) {
StreetTraversalPermission stp = ((StreetEdge) e).getPermission();
if (stp == StreetTraversalPermission.PEDESTRIAN) {
stroke(000, 200, 000);
strokeWeight(6);
drawEdge(e);
} else if (stp == StreetTraversalPermission.BICYCLE) {
stroke(000, 000, 200);
strokeWeight(6);
drawEdge(e);
} else if (stp == StreetTraversalPermission.PEDESTRIAN_AND_BICYCLE) {
stroke(000, 200, 200);
strokeWeight(6);
drawEdge(e);
} else if (stp == StreetTraversalPermission.ALL) {
stroke(200, 200, 200);
strokeWeight(6);
drawEdge(e);
} else {
stroke(64, 64, 64);
strokeWeight(6);
drawEdge(e);
}
}
}
// mark key vertices
lastLabelY = -999;
labelState(gp.states.getFirst(), "begin");
for (State s : gp.states) {
Edge e = s.getBackEdge();
if (e instanceof TransitBoardAlight) {
if (((TransitBoardAlight) e).boarding) {
labelState(s, "board");
} else {
labelState(s, "alight");
}
}
}
labelState(gp.states.getLast(), "end");
if (VIDEO) {
// freeze on final path for a few frames
for (int i = 0; i < 10; i++) saveVideoFrame();
resetVideoFrameNumber();
}
}
Aggregations