use of org.opentripplanner.routing.graph.Edge 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();
}
}
use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.
the class StreetUtils method depedestrianizeOrRemove.
private static void depedestrianizeOrRemove(Graph graph, Subgraph island) {
// iterate over the street vertex of the subgraph
for (Iterator<Vertex> vIter = island.streetIterator(); vIter.hasNext(); ) {
Vertex v = vIter.next();
Collection<Edge> outgoing = new ArrayList<Edge>(v.getOutgoing());
for (Edge e : outgoing) {
if (e instanceof StreetEdge) {
StreetEdge pse = (StreetEdge) e;
StreetTraversalPermission permission = pse.getPermission();
permission = permission.remove(StreetTraversalPermission.PEDESTRIAN);
permission = permission.remove(StreetTraversalPermission.BICYCLE);
if (permission == StreetTraversalPermission.NONE) {
graph.removeEdge(pse);
} else {
pse.setPermission(permission);
}
}
}
}
for (Iterator<Vertex> vIter = island.streetIterator(); vIter.hasNext(); ) {
Vertex v = vIter.next();
if (v.getDegreeOut() + v.getDegreeIn() == 0) {
graph.remove(v);
}
}
// remove street conncetion form
for (Iterator<Vertex> vIter = island.stopIterator(); vIter.hasNext(); ) {
Vertex v = vIter.next();
Collection<Edge> edges = new ArrayList<Edge>(v.getOutgoing());
edges.addAll(v.getIncoming());
for (Edge e : edges) {
if (e instanceof StreetTransitLink) {
graph.removeEdge(e);
}
}
}
LOG.debug(graph.addBuilderAnnotation(new GraphConnectivity(island.getRepresentativeVertex(), island.streetSize())));
}
use of org.opentripplanner.routing.graph.Edge 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");
}
}
use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.
the class WalkableAreaBuilder method buildWithoutVisibility.
/**
* For all areas just use outermost rings as edges so that areas can be routable without visibility calculations
* @param group
*/
public void buildWithoutVisibility(AreaGroup group) {
Set<Edge> edges = new HashSet<Edge>();
// create polygon and accumulate nodes for area
for (Ring ring : group.outermostRings) {
AreaEdgeList edgeList = new AreaEdgeList();
// the points corresponding to concave or hole vertices
// or those linked to ways
HashSet<P2<OSMNode>> alreadyAddedEdges = new HashSet<P2<OSMNode>>();
// and to avoid the numerical problems that they tend to cause
for (Area area : group.areas) {
if (!ring.toJtsPolygon().contains(area.toJTSMultiPolygon())) {
continue;
}
for (Ring outerRing : area.outermostRings) {
for (int i = 0; i < outerRing.nodes.size(); ++i) {
createEdgesForRingSegment(edges, edgeList, area, outerRing, i, alreadyAddedEdges);
}
// TODO: is this actually needed?
for (Ring innerRing : outerRing.holes) {
for (int j = 0; j < innerRing.nodes.size(); ++j) {
createEdgesForRingSegment(edges, edgeList, area, innerRing, j, alreadyAddedEdges);
}
}
}
}
}
}
use of org.opentripplanner.routing.graph.Edge in project OpenTripPlanner by opentripplanner.
the class WalkableAreaBuilder method buildWithVisibility.
public void buildWithVisibility(AreaGroup group, boolean platformEntriesLinking) {
Set<OSMNode> startingNodes = new HashSet<OSMNode>();
Set<Vertex> startingVertices = new HashSet<Vertex>();
Set<Edge> edges = new HashSet<Edge>();
// create polygon and accumulate nodes for area
for (Ring ring : group.outermostRings) {
AreaEdgeList edgeList = new AreaEdgeList();
// the points corresponding to concave or hole vertices
// or those linked to ways
ArrayList<VLPoint> visibilityPoints = new ArrayList<VLPoint>();
ArrayList<OSMNode> visibilityNodes = new ArrayList<OSMNode>();
HashSet<P2<OSMNode>> alreadyAddedEdges = new HashSet<P2<OSMNode>>();
// and to avoid the numerical problems that they tend to cause
for (Area area : group.areas) {
// parameter is true
if (platformEntriesLinking && "platform".equals(area.parent.getTag("public_transport"))) {
continue;
}
if (!ring.toJtsPolygon().contains(area.toJTSMultiPolygon())) {
continue;
}
// Add stops from public transit relations into the area
Collection<OSMNode> nodes = osmdb.getStopsInArea(area.parent);
if (nodes != null) {
for (OSMNode node : nodes) {
addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
}
}
for (Ring outerRing : area.outermostRings) {
for (int i = 0; i < outerRing.nodes.size(); ++i) {
OSMNode node = outerRing.nodes.get(i);
createEdgesForRingSegment(edges, edgeList, area, outerRing, i, alreadyAddedEdges);
addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
}
for (Ring innerRing : outerRing.holes) {
for (int j = 0; j < innerRing.nodes.size(); ++j) {
OSMNode node = innerRing.nodes.get(j);
createEdgesForRingSegment(edges, edgeList, area, innerRing, j, alreadyAddedEdges);
addtoVisibilityAndStartSets(startingNodes, visibilityPoints, visibilityNodes, node);
}
}
}
}
List<OSMNode> nodes = new ArrayList<OSMNode>();
List<VLPoint> vertices = new ArrayList<VLPoint>();
accumulateRingNodes(ring, nodes, vertices);
VLPolygon polygon = makeStandardizedVLPolygon(vertices, nodes, false);
accumulateVisibilityPoints(ring.nodes, polygon, visibilityPoints, visibilityNodes, false);
ArrayList<VLPolygon> polygons = new ArrayList<VLPolygon>();
polygons.add(polygon);
// holes
for (Ring innerRing : ring.holes) {
ArrayList<OSMNode> holeNodes = new ArrayList<OSMNode>();
vertices = new ArrayList<VLPoint>();
accumulateRingNodes(innerRing, holeNodes, vertices);
VLPolygon hole = makeStandardizedVLPolygon(vertices, holeNodes, true);
accumulateVisibilityPoints(innerRing.nodes, hole, visibilityPoints, visibilityNodes, true);
nodes.addAll(holeNodes);
polygons.add(hole);
}
Environment areaEnv = new Environment(polygons);
// areas to prevent way explosion
if (visibilityPoints.size() > MAX_AREA_NODES) {
LOG.warn("Area " + group.getSomeOSMObject() + " is too complicated (" + visibilityPoints.size() + " > " + MAX_AREA_NODES);
continue;
}
if (!areaEnv.is_valid(VISIBILITY_EPSILON)) {
LOG.warn("Area " + group.getSomeOSMObject() + " is not epsilon-valid (epsilon = " + VISIBILITY_EPSILON + ")");
continue;
}
edgeList.setOriginalEdges(ring.toJtsPolygon());
createNamedAreas(edgeList, ring, group.areas);
OSMWithTags areaEntity = group.getSomeOSMObject();
for (int i = 0; i < visibilityNodes.size(); ++i) {
OSMNode nodeI = visibilityNodes.get(i);
VisibilityPolygon visibilityPolygon = new VisibilityPolygon(visibilityPoints.get(i), areaEnv, VISIBILITY_EPSILON);
Polygon poly = toJTSPolygon(visibilityPolygon);
for (int j = 0; j < visibilityNodes.size(); ++j) {
OSMNode nodeJ = visibilityNodes.get(j);
P2<OSMNode> nodePair = new P2<OSMNode>(nodeI, nodeJ);
if (alreadyAddedEdges.contains(nodePair))
continue;
IntersectionVertex startEndpoint = __handler.getVertexForOsmNode(nodeI, areaEntity);
IntersectionVertex endEndpoint = __handler.getVertexForOsmNode(nodeJ, areaEntity);
Coordinate[] coordinates = new Coordinate[] { startEndpoint.getCoordinate(), endEndpoint.getCoordinate() };
GeometryFactory geometryFactory = GeometryUtils.getGeometryFactory();
LineString line = geometryFactory.createLineString(coordinates);
if (poly != null && poly.contains(line)) {
createSegments(nodeI, nodeJ, startEndpoint, endEndpoint, group.areas, edgeList, edges);
if (startingNodes.contains(nodeI)) {
startingVertices.add(startEndpoint);
}
if (startingNodes.contains(nodeJ)) {
startingVertices.add(endEndpoint);
}
}
}
}
}
pruneAreaEdges(startingVertices, edges);
}
Aggregations