Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
options = get_options()
print("generating trips...")
net = sumolib.net.readNet(options.netfile)
stopsLanes = {}
for stop in sumolib.output.parse_fast(options.ptstops, 'busStop', ['id', 'lane']):
stopsLanes[stop.id] = stop.lane
trpIDLineMap = {}
with open(options.trips, 'w') as fouttrips:
sumolib.writeXMLHeader(
fouttrips, "$Id$", "routes")
trp_nr = 0
for line in sumolib.output.parse(options.ptlines, 'ptLine'):
stops = line._child_dict['busStop']
fr = ''
stop_ids = []
for stop in stops:
laneId = stopsLanes[stop.id]
edge_id, lane_index = laneId.rsplit("_", 1)
if fr == '':
fr = edge_id
dep_lane = laneId
to = edge_id
edge = net.getEdge(edge_id)
def main():
options = get_options()
with open(options.output, 'w') as f:
sumolib.writeXMLHeader(
fouttrips, "$Id$", "routes")
index = options.index
for depart in range(options.begin, options.end):
if random.random() < options.prob:
write_ped(
f, index, options, depart, ' '.join(options.route.split(',')))
index += 1
f.write('')
def createTrips(options):
print("generating trips...")
stopsLanes = {}
stopNames = {}
for stop in sumolib.output.parse(options.ptstops, 'busStop'):
stopsLanes[stop.id] = stop.lane
if stop.name:
stopNames[stop.id] = stop.attr_name
trpMap = {}
with codecs.open(options.trips, 'w', encoding="UTF8") as fouttrips:
sumolib.writeXMLHeader(
fouttrips, "$Id: ptlines2flows.py v1_3_1+0313-ccb31df3eb jakob.erdmann@dlr.de 2019-09-02 13:26:32 +0200 $",
"routes")
writeTypes(fouttrips, options.vtypeprefix)
departTimes = [options.begin for line in sumolib.output.parse_fast(options.ptlines, 'ptLine', ['id'])]
if options.randomBegin:
departTimes = sorted([options.begin
+ int(random.random() * options.period) for t in departTimes])
lineCount = collections.defaultdict(int)
typeCount = collections.defaultdict(int)
numLines = 0
numStops = 0
numSkipped = 0
for trp_nr, line in enumerate(sumolib.output.parse(options.ptlines, 'ptLine', heterogeneous=True)):
stop_ids = []
def main(options):
net = sumolib.net.readNet(options.netfile, withConnections=False, withFoes=False)
l2 = options.length / 2
with open(options.outfile + ".edg.xml", 'w') as out_e:
with open(options.outfile + ".nod.xml", 'w') as out_n:
sumolib.writeXMLHeader(out_e, "$Id$") # noqa
sumolib.writeXMLHeader(out_n, "$Id$") # noqa
out_e.write('\n')
out_n.write('\n')
for stop in sumolib.xml.parse(options.stopfile, 'busStop', heterogeneous=True):
edge_id = stop.id + "_access"
x, y = sumolib.geomhelper.positionAtShapeOffset(
net.getLane(stop.lane).getShape(),
(float(stop.startPos) + float(stop.endPos)) / 2)
from_id = edge_id + '_from'
to_id = edge_id + '_to'
out_n.write(' \n' % (from_id, x - l2, y))
out_n.write(' \n' % (to_id, x + l2, y))
out_e.write(' \n' % (
edge_id, from_id, to_id, options.width))
out_e.write('\n')
out_n.write('\n')
def main():
options = get_options()
with open(options.output, 'w') as f:
sumolib.writeXMLHeader(f, "$Id$", "routes") # noqa
index = options.index
for depart in range(options.begin, options.end):
if random.random() < options.prob:
write_ped(
f, index, options, depart)
index += 1
f.write('')
def main(options):
net = sumolib.net.readNet(options.netfile)
incomingRoutes = defaultdict(set) # edge : set(route0, route1, ...)
if options.longRoutes:
# build dictionary of routes leading from an intersection to each edge
for junction in net.getNodes():
isEntry = len(junction.getIncoming()) == 0
if len(junction.getOutgoing()) > 1 or isEntry:
for edge in junction.getOutgoing():
if isEntry or getNumSiblings(edge) > 1:
edges = getEdgesToIntersection(edge)
edgeIDs = tuple([e.getID() for e in edges])
incomingRoutes[edges[-1]].add(edgeIDs)
with open(options.outfile, 'w') as outf:
sumolib.writeXMLHeader(outf, "$Id$", "additional") # noqa
for junction in net.getNodes():
if len(junction.getOutgoing()) > 1:
routes = []
for edge in junction.getOutgoing():
routes.append(getEdgesToIntersection(edge))
for edge in junction.getIncoming():
if options.longRoutes:
# overlapping routes: start behind an intersection and
# route across the next intersection to the entry of the
# 2nd intersetion (more rerouters and overlapping routes)
if getNumAlterantives(edge, routes) > 1:
for incomingRoute in incomingRoutes[edge]:
assert(incomingRoute[-1] == edge.getID())
firstEdgeID = incomingRoute[0]
routeIDs = []
'from="%s"%s%s%s/>\n') % (
label, j, options.begin, options.end, 1.0 / options.period / options.binomial,
source_edge.getID(), to, via, combined_attrs))
else:
fouttrips.write((' \n') % (
label, options.begin, options.end, options.period * options.flows, source_edge.getID(),
to, via, combined_attrs))
else:
fouttrips.write(' \n' % (
label, depart, source_edge.getID(), sink_edge.getID(), via, combined_attrs))
except Exception as exc:
print(exc, file=sys.stderr)
return idx + 1
with open(options.tripfile, 'w') as fouttrips:
sumolib.writeXMLHeader(fouttrips, "$Id$", "routes") # noqa
if options.vehicle_class:
fouttrips.write(' \n' %
(options.vtypeID, options.vehicle_class, vtypeattrs))
options.tripattrs += ' type="%s"' % options.vtypeID
personattrs += ' type="%s"' % options.vtypeID
depart = options.begin
if trip_generator:
if options.flows == 0:
while depart < options.end:
if options.binomial is None:
# generate with constant spacing
idx = generate_one(idx)
depart += options.period
else:
# draw n times from a Bernoulli distribution
# for an average arrival rate of 1 / period
if options.binomial:
for j in range(options.binomial):
fouttrips.write(' \n' % (
label, j, options.begin, options.end, 1.0 / options.period / options.binomial, source_edge.getID(), sink_edge.getID(), via, options.tripattrs))
else:
fouttrips.write(' \n' % (
label, options.begin, options.end, options.period * options.flows, source_edge.getID(), sink_edge.getID(), via, options.tripattrs))
else:
fouttrips.write(' \n' % (
label, depart, source_edge.getID(), sink_edge.getID(), via, options.tripattrs))
except Exception as exc:
print(exc, file=sys.stderr)
return idx + 1
with open(options.tripfile, 'w') as fouttrips:
sumolib.writeXMLHeader(
fouttrips, "$Id$", "routes")
if options.vehicle_class:
fouttrips.write(' \n' %
(options.vehicle_class, options.vehicle_class, vtypeattrs))
options.tripattrs += ' type="%s"' % options.vehicle_class
depart = options.begin
if trip_generator:
if options.flows == 0:
while depart < options.end:
if options.binomial is None:
# generate with constant spacing
idx = generate_one(idx)
depart += options.period
else:
# draw n times from a Bernoulli distribution
# for an average arrival rate of 1 / period
def main(options):
# get traffic flows for each edge pair
edgePairFlowsMap = getFlows(options.routefiles, options.verbose)
with open(options.outfile, 'w') as outf:
sumolib.writeXMLHeader(outf, "$Id$", "turns") # noqa
outf.write(' \n')
for from_edge in edgePairFlowsMap:
outf.write(' \n' % from_edge)
if options.prob:
sum = 0.
for to_edge in edgePairFlowsMap[from_edge]:
sum += edgePairFlowsMap[from_edge][to_edge]
for to_edge in edgePairFlowsMap[from_edge]:
outf.write(' \n' %
(to_edge, edgePairFlowsMap[from_edge][to_edge]/sum))
else:
for to_edge in edgePairFlowsMap[from_edge]:
outf.write(' \n' %
(to_edge, edgePairFlowsMap[from_edge][to_edge]))
outf.write(' \n')