def getReachable(net, source_id, options, useIncoming=False): if not net.hasEdge(source_id): sys.exit("'{}' is not a valid edge id".format(source_id)) source = net.getEdge(source_id) if options.vclass is not None and not source.allows(options.vclass): sys.exit("'{}' does not allow {}".format(source_id, options.vclass)) fringe = [source] found = set() found.add(source) while len(fringe) > 0: new_fringe = [] for edge in fringe: cands = edge.getIncoming() if useIncoming else edge.getOutgoing() for reachable in cands: if options.vclass is None or reachable.allows(options.vclass): if not reachable in found: found.add(reachable) new_fringe.append(reachable) fringe = new_fringe if useIncoming: print("{} of {} edges can reach edge '{}':".format(len(found), len(net.getEdges()), source_id)) else: print("{} of {} edges are reachable from edge '{}':".format(len(found), len(net.getEdges()), source_id)) ids = sorted([e.getID() for e in found]) if options.selection_output: with open(options.selection_output, 'w') as f: for e in ids: f.write("edge:{}\n".format(e)) else: print(ids)
def getReachable(net, source_id, options, useIncoming=False): if not net.hasEdge(source_id): sys.exit("'{}' is not a valid edge id".format(source_id)) source = net.getEdge(source_id) if options.vclass is not None and not source.allows(options.vclass): sys.exit("'{}' does not allow {}".format(source_id, options.vclass)) fringe = [source] found = set() found.add(source) while len(fringe) > 0: new_fringe = [] for edge in fringe: cands = edge.getIncoming() if useIncoming else edge.getOutgoing() for reachable in cands: if options.vclass is None or reachable.allows(options.vclass): if reachable not in found: found.add(reachable) new_fringe.append(reachable) fringe = new_fringe if useIncoming: print("{} of {} edges can reach edge '{}':".format( len(found), len(net.getEdges()), source_id)) else: print("{} of {} edges are reachable from edge '{}':".format( len(found), len(net.getEdges()), source_id)) ids = sorted([e.getID() for e in found]) if options.selection_output: with open(options.selection_output, 'w') as f: for e in ids: f.write("edge:{}\n".format(e)) else: print(ids)
def getReachable(net, source_id, options, useIncoming=False): if not net.hasEdge(source_id): sys.exit("'%s' is not a valid edge id" % source_id) source = net.getEdge(source_id) if options.vclass is not None and not source.allows(options.vclass): sys.exit("'%s' does not allow %s" % (source_id, options.vclass)) fringe = [source] found = set() found.add(source) while len(fringe) > 0: new_fringe = [] for edge in fringe: cands = edge.getIncoming() if useIncoming else edge.getOutgoing() for reachable in cands.iterkeys(): if options.vclass is None or reachable.allows(options.vclass): if not reachable in found: found.add(reachable) new_fringe.append(reachable) fringe = new_fringe if useIncoming: print "%s of %s edges can reach edge '%s':" % ( len(found), len(net.getEdges()), source_id) else: print "%s of %s edges are reachable from edge '%s':" % ( len(found), len(net.getEdges()), source_id) if options.selection_output: with open(options.selection_output, 'w') as f: for e in sorted(found): f.write("edge:%s\n" % e.getID()) else: print[e.getID() for e in found]
def getReachable(net, source_id, options): if not net.hasEdge(source_id): sys.exit("'%s' is not a valid edge id" % source_id) source = net.getEdge(source_id) fringe = [source] found = set() found.add(source) while len(fringe) > 0: new_fringe = [] for edge in fringe: for reachable in edge.getOutgoing().iterkeys(): if not reachable in found: found.add(reachable) new_fringe.append(reachable) fringe = new_fringe print "%s of %s edges are reachable from edge '%s':" % ( len(found), len(net.getEdges()), source_id) if options.selection_output: with open(options.selection_output, 'w') as f: for e in found: f.write("edge:%s\n" % e.getID()) else: print [e.getID() for e in found]
def getReachable(net, source_id, options): if not net.hasEdge(source_id): sys.exit("'%s' is not a valid edge id" % source_id) source = net.getEdge(source_id) fringe = [source] found = set() found.add(source) while len(fringe) > 0: new_fringe = [] for edge in fringe: for reachable in edge.getOutgoing().iterkeys(): if not reachable in found: found.add(reachable) new_fringe.append(reachable) fringe = new_fringe print "%s of %s edges are reachable from edge '%s':" % ( len(found), len(net.getEdges()), source_id) if options.selection_output: with open(options.selection_output, 'w') as f: for e in found: f.write("edge:%s\n" % e.getID()) else: print[e.getID() for e in found]
def getReachable(net, source_id, options, useIncoming=False): if not net.hasEdge(source_id): sys.exit("'{}' is not a valid edge id".format(source_id)) source = net.getEdge(source_id) if options.vclass is not None and not source.allows(options.vclass): sys.exit("'{}' does not allow {}".format(source_id, options.vclass)) fringe = [source] found = set() found.add(source) while len(fringe) > 0: new_fringe = [] for edge in fringe: if options.vclass == "pedestrian": cands = chain(chain(*edge.getIncoming().values()), chain(*edge.getOutgoing().values())) else: cands = chain(*(edge.getIncoming().values( ) if useIncoming else edge.getOutgoing().values())) #print("\n".join(map(str, list(cands)))) for conn in cands: if options.vclass is None or ( conn.getFromLane().allows(options.vclass) and conn.getToLane().allows(options.vclass)): for reachable in [conn.getTo(), conn.getFrom()]: if reachable not in found: #print("added %s via %s" % (reachable, conn)) found.add(reachable) new_fringe.append(reachable) fringe = new_fringe if useIncoming: print("{} of {} edges can reach edge '{}':".format( len(found), len(net.getEdges()), source_id)) else: print("{} of {} edges are reachable from edge '{}':".format( len(found), len(net.getEdges()), source_id)) ids = sorted([e.getID() for e in found]) if options.selection_output: with open(options.selection_output, 'w') as f: for e in ids: f.write("edge:{}\n".format(e)) else: print(ids)
def getReachable(net, source_id, options, useIncoming=False): if not net.hasEdge(source_id): sys.exit("'{}' is not a valid edge id".format(source_id)) source = net.getEdge(source_id) if options.vclass is not None and not source.allows(options.vclass): sys.exit("'{}' does not allow {}".format(source_id, options.vclass)) fringe = [source] found = set() found.add(source) while len(fringe) > 0: new_fringe = [] for edge in fringe: if options.vclass == "pedestrian": cands = chain(chain(*edge.getIncoming().values()), chain(*edge.getOutgoing().values())) else: cands = chain(*(edge.getIncoming().values() if useIncoming else edge.getOutgoing().values())) # print("\n".join(map(str, list(cands)))) for conn in cands: if options.vclass is None or ( conn.getFromLane().allows(options.vclass) and conn.getToLane().allows(options.vclass)): for reachable in [conn.getTo(), conn.getFrom()]: if reachable not in found: # print("added %s via %s" % (reachable, conn)) found.add(reachable) new_fringe.append(reachable) fringe = new_fringe if useIncoming: print("{} of {} edges can reach edge '{}':".format( len(found), len(net.getEdges()), source_id)) else: print("{} of {} edges are reachable from edge '{}':".format( len(found), len(net.getEdges()), source_id)) ids = sorted([e.getID() for e in found]) if options.selection_output: with open(options.selection_output, 'w') as f: for e in ids: f.write("edge:{}\n".format(e)) else: print(ids)