本文整理汇总了Python中sumolib.output.parse函数的典型用法代码示例。如果您正苦于以下问题:Python parse函数的具体用法?Python parse怎么用?Python parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: write_diff
def write_diff(options):
attrs = ["depart", "arrival", "timeLoss", "duration", "routeLength"]
# parseTime works just fine for floats
attr_conversions = dict([(a, parseTime) for a in attrs])
vehicles_orig = OrderedDict([(v.id, v) for v in parse(options.orig, 'tripinfo',
attr_conversions=attr_conversions)])
origDurations = Statistics('original durations', histogram=options.useHist, scale=options.histScale)
durations = Statistics('new durations', histogram=options.useHist, scale=options.histScale)
durationDiffs = Statistics('duration differences', histogram=options.useHist, scale=options.histScale)
with open(options.output, 'w') as f:
f.write("<tripDiffs>\n")
for v in parse(options.new, 'tripinfo', attr_conversions=attr_conversions):
if v.id in vehicles_orig:
vOrig = vehicles_orig[v.id]
diffs = [v.getAttribute(a) - vOrig.getAttribute(a) for a in attrs]
durations.add(v.duration, v.id)
origDurations.add(vOrig.duration, v.id)
durationDiffs.add(v.duration - vOrig.duration, v.id)
diffAttrs = ''.join([' %sDiff="%s"' % (a, x) for a, x in zip(attrs, diffs)])
f.write(' <vehicle id="%s"%s/>\n' % (v.id, diffAttrs))
del vehicles_orig[v.id]
else:
f.write(' <vehicle id="%s" comment="new"/>\n' % v.id)
for id in vehicles_orig.keys():
f.write(' <vehicle id="%s" comment="missing"/>\n' % id)
f.write("</tripDiffs>\n")
print(origDurations)
print(durations)
print(durationDiffs)
开发者ID:behrisch,项目名称:sumo,代码行数:30,代码来源:tripinfoDiff.py
示例2: main
def main(args):
options = parse_args(args)
net = readNet(options.net)
known_ids = set()
def unique_id(cand, index=0):
cand2 = cand
if index > 0:
cand2 = "%s#%s" % (cand, index)
if cand2 in known_ids:
return unique_id(cand, index + 1)
else:
known_ids.add(cand2)
return cand2
with open(options.outfile, 'w') as outf:
outf.write('<polygons>\n')
for routefile in options.routefiles:
print("parsing %s" % routefile)
if options.standalone:
for route in parse(routefile, 'route'):
# print("found veh", vehicle.id)
generate_poly(net, unique_id(route.id), options.colorgen(),
options.layer, options.geo,
route.edges.split(), options.blur, outf)
else:
for vehicle in parse(routefile, 'vehicle'):
# print("found veh", vehicle.id)
generate_poly(net, unique_id(vehicle.id), options.colorgen(),
options.layer, options.geo,
vehicle.route[0].edges.split(), options.blur, outf)
outf.write('</polygons>\n')
开发者ID:fieryzig,项目名称:sumo,代码行数:32,代码来源:route2poly.py
示例3: main
def main():
options = get_options()
net = readNet(options.network)
edges = set([e.getID() for e in net.getEdges()])
lengths1 = {}
lengths2 = {}
lengthDiffStats = Statistics(
"route length difference", histogram=True, scale=options.binwidth)
for vehicle in parse(options.routeFile1, 'vehicle'):
lengths1[vehicle.id] = getRouteLength(net, vehicle)
for vehicle in parse(options.routeFile2, 'vehicle'):
lengths2[vehicle.id] = getRouteLength(net, vehicle)
lengthDiffStats.add(
lengths2[vehicle.id] - lengths1[vehicle.id], vehicle.id)
print lengthDiffStats
if options.hist_output is not None:
with open(options.hist_output, 'w') as f:
for bin, count in lengthDiffStats.histogram():
f.write("%s %s\n" % (bin, count))
if options.full_output is not None:
with open(options.full_output, 'w') as f:
differences = sorted(
[(lengths2[id] - lengths1[id], id) for id in lengths1.keys()])
for diff, id in differences:
f.write("%s %s\n" % (diff, id))
开发者ID:sequielo,项目名称:sumo,代码行数:29,代码来源:routeDiffStats.py
示例4: write_diff
def write_diff(orig, new, out):
diffStats = defaultdict(Statistics)
with open(out, 'w') as f:
f.write("<meandata>\n")
for interval_old, interval_new in zip(parse(orig, 'interval'), parse(new, 'interval')):
f.write(' <interval begin="%s" end="%s">\n' %
(interval_old.begin, interval_old.end))
for edge_old, edge_new in zip(interval_old.edge, interval_new.edge):
assert(edge_old.id == edge_new.id)
f.write(' <edge id="%s"' % edge_old.id)
for attr in edge_old._fields:
if attr == 'id':
continue
try:
delta = float(getattr(edge_new, attr)) - \
float(getattr(edge_old, attr))
diffStats[attr].add(delta, edge_old.id)
f.write(' %s="%s"' % (attr, delta))
except:
pass
f.write("/>\n")
f.write("</interval>\n")
f.write("</meandata>\n")
for attr, stats in diffStats.items():
stats.label = attr
print(stats)
开发者ID:702nADOS,项目名称:sumo,代码行数:29,代码来源:edgeDataDiff.py
示例5: write_persondiff
def write_persondiff(options):
attrs = ["depart", "arrival", "timeLoss", "duration", "routeLength", "waitingTime"]
attr_conversions = dict([(a, parseTime) for a in attrs])
persons_orig = OrderedDict([(p.id, p) for p in parse(options.orig, 'personinfo',
attr_conversions=attr_conversions)])
origDurations = Statistics('original durations')
durations = Statistics('new durations')
durationDiffs = Statistics('duration differences')
statAttrs = ["duration", "walkTimeLoss", "rideWait", "walks", "accesses", "rides", "stops"]
with open(options.output, 'w') as f:
f.write("<tripDiffs>\n")
for p in parse(options.new, 'personinfo', attr_conversions=attr_conversions):
if p.id in persons_orig:
pOrig = persons_orig[p.id]
stats = plan_stats(p)
statsOrig = plan_stats(pOrig)
diffs = [a - b for a, b in zip(stats, statsOrig)]
durations.add(stats[0], p.id)
origDurations.add(statsOrig[0], p.id)
durationDiffs.add(stats[0] - statsOrig[0], p.id)
diffAttrs = ''.join([' %sDiff="%s"' % (a, x) for a, x in zip(statAttrs, diffs)])
f.write(' <personinfo id="%s"%s/>\n' % (p.id, diffAttrs))
del persons_orig[p.id]
else:
f.write(' <personinfo id="%s" comment="new"/>\n' % p.id)
for id in persons_orig.keys():
f.write(' <personinfo id="%s" comment="missing"/>\n' % id)
f.write("</tripDiffs>\n")
print(origDurations)
print(durations)
print(durationDiffs)
开发者ID:behrisch,项目名称:sumo,代码行数:32,代码来源:tripinfoDiff.py
示例6: main
def main():
options = get_options()
net = None
attribute_retriever = None
if options.attribute == "length":
net = readNet(options.network)
def attribute_retriever(vehicle):
return sum([net.getEdge(e).getLength() for e in vehicle.route[0].edges.split()])
elif options.attribute == "depart":
def attribute_retriever(vehicle):
return float(vehicle.depart)
elif options.attribute == "numEdges":
def attribute_retriever(vehicle):
return len(vehicle.route[0].edges.split())
else:
sys.exit("Invalid value '%s' for option --attribute" % options.attribute)
lengths = {}
lengths2 = {}
if options.routeFile2 is None:
# write statistics on a single route file
stats = Statistics(
"route %ss" % options.attribute, histogram=True, scale=options.binwidth)
for vehicle in parse(options.routeFile, 'vehicle'):
length = attribute_retriever(vehicle)
if options.routeFile2 is None:
stats.add(length, vehicle.id)
lengths[vehicle.id] = length
if options.routeFile2 is not None:
# compare route lengths between two files
stats = Statistics(
"route %s difference" % options.attribute, histogram=True, scale=options.binwidth)
for vehicle in parse(options.routeFile2, 'vehicle'):
lengths2[vehicle.id] = attribute_retriever(vehicle)
stats.add(lengths2[vehicle.id] - lengths[vehicle.id], vehicle.id)
print(stats)
if options.hist_output is not None:
with open(options.hist_output, 'w') as f:
for bin, count in stats.histogram():
f.write("%s %s\n" % (bin, count))
if options.full_output is not None:
with open(options.full_output, 'w') as f:
if options.routeFile2 is None:
data = [(v, k) for k, v in lengths.items()]
else:
data = [(lengths2[id] - lengths[id], id)
for id in lengths.keys()]
for val, id in sorted(data):
f.write("%s %s\n" % (val, id))
开发者ID:behrisch,项目名称:sumo,代码行数:55,代码来源:routeStats.py
示例7: write_diff
def write_diff(orig, new, out, earliest_out=None):
attr_conversions = {"depart": parseTime, "arrival": parseTime}
earliest_diffs = defaultdict(lambda: (uMax, None)) # diff -> (time, veh)
vehicles_orig = dict([(v.id, v) for v in parse(orig, 'vehicle',
attr_conversions=attr_conversions)])
origDurations = Statistics('original durations')
durations = Statistics('new durations')
durationDiffs = Statistics('duration differences')
with open(out, 'w') as f:
f.write("<routeDiff>\n")
for v in parse(new, 'vehicle', attr_conversions=attr_conversions):
if v.id in vehicles_orig:
vOrig = vehicles_orig[v.id]
departDiff = v.depart - vOrig.depart
arrivalDiff = v.arrival - vOrig.arrival
if v.route[0].exitTimes is None:
sys.exit("Error: Need route input with 'exitTimes'\n")
exitTimes = map(parseTime, v.route[0].exitTimes.split())
origExitTimes = map(parseTime, vOrig.route[0].exitTimes.split())
exitTimesDiff = [
e - eOrig for e, eOrig in zip(exitTimes, origExitTimes)]
durations.add(v.arrival - v.depart, v.id)
origDurations.add(vOrig.arrival - vOrig.depart, v.id)
durationDiffs.add(arrivalDiff - departDiff, v.id)
update_earliest(
earliest_diffs, departDiff, vOrig.depart, v.id + ' (depart)')
for diff, timestamp in zip(exitTimesDiff, origExitTimes):
update_earliest(earliest_diffs, diff, timestamp, v.id)
f.write(''' <vehicle id="%s" departDiff="%s" arrivalDiff="%s" exitTimesDiff="%s"/>\n''' % (
v.id, departDiff, arrivalDiff, ' '.join(map(str, exitTimesDiff))))
del vehicles_orig[v.id]
else:
f.write(' <vehicle id="%s" comment="new"/>\n' % v.id)
for id in vehicles_orig.keys():
f.write(' <vehicle id="%s" comment="missing"/>\n' % id)
f.write("</routeDiff>\n")
if earliest_out is not None:
with open(earliest_out, 'w') as f:
for diff in reversed(sorted(earliest_diffs.keys())):
f.write("%s, %s\n" % (diff, earliest_diffs[diff]))
print(origDurations)
print(durations)
print(durationDiffs)
开发者ID:behrisch,项目名称:sumo,代码行数:48,代码来源:vehrouteDiff.py
示例8: main
def main(tripinfos, lengthThreshold=0.1):
lengthThreshold = float(lengthThreshold)
stats = Statistics('walkfactor')
statsZeroDuration = Statistics('length of zero-duration walks')
statsShort = Statistics('duration of short walks (length <= %s)' % lengthThreshold)
numUnfinished = 0
for personinfo in parse(tripinfos, 'personinfo'):
if personinfo.hasChild('walk'):
for i, walk in enumerate(personinfo.walk):
if walk.arrival[0] == '-':
numUnfinished += 1
continue
walkID = "%s.%s" % (personinfo.id, i)
duration = float(walk.duration)
routeLength = float(walk.routeLength)
if duration > 0:
if routeLength <= lengthThreshold:
statsShort.add(duration, walkID)
else:
avgSpeed = routeLength / duration
walkFactor = avgSpeed / float(walk.maxSpeed)
stats.add(walkFactor, walkID)
else:
statsZeroDuration.add(routeLength, walkID)
print(stats)
if statsZeroDuration.count() > 0:
print(statsZeroDuration)
if statsShort.count() > 0:
print(statsShort)
if numUnfinished > 0:
print("unfinished walks: %s" % numUnfinished)
开发者ID:behrisch,项目名称:sumo,代码行数:32,代码来源:walkFactor.py
示例9: main
def main():
options = parse_args()
edges = set()
for routefile in options.routefiles:
for route in parse_fast(routefile, 'route', ['edges']):
edges.update(route.edges.split())
for walk in parse_fast(routefile, 'walk', ['edges']):
edges.update(walk.edges.split())
# warn about potentially missing edges
for trip in parse(routefile, ['trip', 'flow'], heterogeneous=True):
edges.update([trip.attr_from, trip.to])
if trip.via is not None:
edges.update(trip.via.split())
print(
"Warning: Trip %s is not guaranteed to be connected within the extracted edges." % trip.id)
for walk in parse_fast(routefile, 'walk', ['from', 'to']):
edges.update([walk.attr_from, walk.to])
print("Warning: Walk from %s to %s is not guaranteed to be connected within the extracted edges." % (
walk.attr_from, walk.to))
with open(options.outfile, 'w') as outf:
for e in sorted(list(edges)):
outf.write('edge:%s\n' % e)
开发者ID:fieryzig,项目名称:sumo,代码行数:25,代码来源:route2sel.py
示例10: write_diff
def write_diff(orig, new, out, earliest_out=None):
earliest_diffs = defaultdict(lambda: (uMax, None)) # diff -> (time, veh)
vehicles_orig = dict([(v.id, v) for v in parse(orig, "vehicle")])
origDurations = Statistics("original durations")
durations = Statistics("new durations")
durationDiffs = Statistics("duration differences")
with open(out, "w") as f:
f.write("<routeDiff>\n")
for v in parse(new, "vehicle"):
if v.id in vehicles_orig:
vOrig = vehicles_orig[v.id]
departDiff = float(v.depart) - float(vOrig.depart)
arrivalDiff = float(v.arrival) - float(vOrig.arrival)
if v.route[0].exitTimes is None:
sys.exit("Error: Need route input with 'exitTimes'\n")
exitTimes = map(float, v.route[0].exitTimes.split())
origExitTimes = map(float, vOrig.route[0].exitTimes.split())
exitTimesDiff = [e - eOrig for e, eOrig in zip(exitTimes, origExitTimes)]
durations.add(float(v.arrival) - float(v.depart), v.id)
origDurations.add(float(vOrig.arrival) - float(vOrig.depart), v.id)
durationDiffs.add(arrivalDiff - departDiff, v.id)
update_earliest(earliest_diffs, departDiff, vOrig.depart, v.id + " (depart)")
for diff, timestamp in zip(exitTimesDiff, origExitTimes):
update_earliest(earliest_diffs, diff, timestamp, v.id)
f.write(
""" <vehicle id="%s" departDiff="%s" arrivalDiff="%s" exitTimesDiff="%s"/>\n"""
% (v.id, departDiff, arrivalDiff, " ".join(map(str, exitTimesDiff)))
)
del vehicles_orig[v.id]
else:
f.write(' <vehicle id="%s" comment="new"/>\n' % v.id)
for id in vehicles_orig.keys():
f.write(' <vehicle id="%s" comment="missing"/>\n' % id)
f.write("</routeDiff>\n")
if earliest_out is not None:
with open(earliest_out, "w") as f:
for diff in reversed(sorted(earliest_diffs.keys())):
f.write("%s, %s\n" % (diff, earliest_diffs[diff]))
print(origDurations)
print(durations)
print(durationDiffs)
开发者ID:planetsumo,项目名称:sumo,代码行数:46,代码来源:vehrouteDiff.py
示例11: main
def main():
options = parse_args()
net = readNet(options.net)
with open(options.outfile, 'w') as outf:
outf.write('<polygons>\n')
for vehicle in parse(options.routefile, 'vehicle'):
generate_poly(net, vehicle.id, options.colorgen(), options.layer, vehicle.route[0].edges.split(), outf)
outf.write('</polygons>\n')
开发者ID:cathyyul,项目名称:sumo-0.18,代码行数:8,代码来源:route2poly.py
示例12: main
def main(options):
net = readNet(options.network)
edges = set([e.getID() for e in net.getEdges()])
if options.orig_net is not None:
orig_net = readNet(options.orig_net)
else:
orig_net = None
print("Valid area contains %s edges" % len(edges))
if options.trips:
output_type = 'trips'
writer = write_trip
else:
output_type = 'routes'
writer = write_route
busStopEdges = {}
if options.stops_output:
busStops = codecs.open(options.stops_output, 'w', encoding='utf8')
busStops.write(
'<additional xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/additional_file.xsd">\n')
if options.additional_input:
for busStop in parse(options.additional_input, 'busStop'):
edge = busStop.lane[:-2]
busStopEdges[busStop.id] = edge
if options.stops_output and edge in edges:
busStops.write(busStop.toXML(' '))
if options.stops_output:
busStops.write('</additional>\n')
busStops.close()
def write_to_file(vehicles, f):
f.write('<!-- generated with %s for %s from %s -->\n' %
(os.path.basename(__file__), options.network, options.routeFiles))
f.write(
('<%s xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">\n') % output_type)
num_routes = 0
for _, v in vehicles:
num_routes += 1
writer(f, v)
f.write('</%s>\n' % output_type)
print("Wrote %s %s" % (num_routes, output_type))
if options.big:
# write output unsorted
tmpname = options.output + ".unsorted"
with codecs.open(tmpname, 'w', encoding='utf8') as f:
write_to_file(
cut_routes(edges, orig_net, options, busStopEdges), f)
# sort out of memory
sort_routes.main([tmpname, '--big', '--outfile', options.output])
else:
routes = list(cut_routes(edges, orig_net, options, busStopEdges))
routes.sort(key=lambda v: v[0])
with codecs.open(options.output, 'w', encoding='utf8') as f:
write_to_file(routes, f)
开发者ID:fieryzig,项目名称:sumo,代码行数:58,代码来源:cutRoutes.py
示例13: cut_routes
def cut_routes(areaEdges, orig_net, options):
num_vehicles = 0
num_returned = 0
missingEdgeOccurences = defaultdict(lambda: 0)
multiAffectedRoutes = 0 # routes which enter the sub-scenario multiple times
teleportFactorSum = 0.0
too_short = 0
for routeFile in options.routeFiles:
print "Parsing routes from %s" % routeFile
for vehicle in parse(routeFile, "vehicle"):
num_vehicles += 1
edges = vehicle.route[0].edges.split()
fromIndex = getFirstIndex(areaEdges, edges)
if fromIndex is None:
continue # route does not touch the area
toIndex = len(edges) - 1 - getFirstIndex(areaEdges, reversed(edges))
# check for minimum length
if toIndex - fromIndex + 1 < options.min_length:
too_short += 1
continue
# check for connectivity
if missingEdges(areaEdges, edges[fromIndex:toIndex], missingEdgeOccurences):
multiAffectedRoutes += 1
if options.disconnected_action == "discard":
continue
# compute new departure
if vehicle.route[0].exitTimes is None:
if orig_net is not None:
# extrapolate new departure using default speed
newDepart = float(vehicle.depart) + sum(
[
(orig_net.getEdge(e).getLength() / (orig_net.getEdge(e).getSpeed() * options.speed_factor))
for e in edges[:fromIndex]
]
)
else:
print "Could not reconstruct new departure for vehicle '%s'. Using old departure" % vehicle.id
newDepart = vehicle.depart
else:
exitTimes = vehicle.route[0].exitTimes.split()
departTimes = [vehicle.depart] + exitTimes[:-1]
teleportFactor = len(departTimes) / float(len(edges))
teleportFactorSum += teleportFactor
# assume teleports were spread evenly across the vehicles route
newDepart = int(float(departTimes[int(fromIndex * teleportFactor)]))
yield (newDepart, vehicle.id, vehicle.type, edges[fromIndex : toIndex + 1])
num_returned += 1
if teleportFactorSum > 0:
teleports = " (avg teleportFactor %s)" % (1 - teleportFactorSum / num_returned)
else:
teleports = ""
print "Parsed %s vehicles and kept %s routes%s" % (num_vehicles, num_returned, teleports)
if too_short > 0:
print "Discared %s routes because they have less than %s edges" % (too_short, options.min_length)
print "Number of disconnected routes: %s. Most frequent missing edges:" % multiAffectedRoutes
printTop(missingEdgeOccurences)
开发者ID:namnatulco,项目名称:sumo-complete,代码行数:58,代码来源:cutRoutes.py
示例14: main
def main():
random.seed(42)
options = parse_args()
net = readNet(options.net)
with open(options.outfile, "w") as outf:
outf.write("<polygons>\n")
for taz in parse(options.routefile, "taz"):
generate_poly(net, taz.id, options.colorgen(), options.layer, taz.edges.split(), outf)
outf.write("</polygons>\n")
开发者ID:702nADOS,项目名称:sumo,代码行数:9,代码来源:districts2poly.py
示例15: write_diff
def write_diff(options):
diffStats = defaultdict(Statistics)
with open(options.out, 'w') as f:
f.write("<meandata>\n")
for interval_old, interval_new in zip(
parse(options.orig, 'interval', heterogeneous=True),
parse(options.new, 'interval', heterogeneous=True)):
f.write(' <interval begin="%s" end="%s">\n' %
(interval_old.begin, interval_old.end))
interval_new_edges = dict([(e.id, e) for e in interval_new.edge])
for edge_old in interval_old.edge:
edge_new = interval_new_edges.get(edge_old.id, None)
if edge_new is None:
continue
assert(edge_old.id == edge_new.id)
f.write(' <edge id="%s"' % edge_old.id)
for attr in edge_old._fields:
if attr == 'id':
continue
try:
val_new = float(getattr(edge_new, attr))
val_old = float(getattr(edge_old, attr))
delta = val_new - val_old
if options.relative:
if val_old != 0:
delta /= abs(val_old)
else:
delta = options.undefined
elif options.geh:
delta = geh(val_new, val_old)
diffStats[attr].add(delta, edge_old.id)
f.write(' %s="%s"' % (attr, delta))
except Exception:
pass
f.write("/>\n")
f.write("</interval>\n")
f.write("</meandata>\n")
for attr, stats in diffStats.items():
stats.label = attr
print(stats)
开发者ID:fieryzig,项目名称:sumo,代码行数:43,代码来源:edgeDataDiff.py
示例16: main
def main():
options = get_options()
net = readNet(options.network)
edges = set([e.getID() for e in net.getEdges()])
lengths = {}
lengths2 = {}
for vehicle in parse(options.routeFile, 'vehicle'):
lengths[vehicle.id] = getRouteLength(net, vehicle)
if options.routeFile2 is None:
# write statistics on a single route file
stats = Statistics(
"route lengths", histogram=True, scale=options.binwidth)
for id, length in lengths.items():
stats.add(length, id)
else:
# compare route lengths between two files
stats = Statistics(
"route length difference", histogram=True, scale=options.binwidth)
for vehicle in parse(options.routeFile2, 'vehicle'):
lengths2[vehicle.id] = getRouteLength(net, vehicle)
stats.add(lengths2[vehicle.id] - lengths[vehicle.id], vehicle.id)
print(stats)
if options.hist_output is not None:
with open(options.hist_output, 'w') as f:
for bin, count in stats.histogram():
f.write("%s %s\n" % (bin, count))
if options.full_output is not None:
with open(options.full_output, 'w') as f:
if options.routeFile2 is None:
data = [(v, k) for k, v in lengths.items()]
else:
data = [(lengths2[id] - lengths[id], id)
for id in lengths.keys()]
for val, id in sorted(data):
f.write("%s %s\n" % (val, id))
开发者ID:cbrafter,项目名称:sumo,代码行数:41,代码来源:routeStats.py
示例17: write_diff
def write_diff(orig, new, out, earliest_out=None):
earliest_diffs = defaultdict(lambda: (uMax, None)) # diff -> (time, veh)
vehicles_orig = dict([(v.id, v) for v in parse(orig, 'tripinfo')])
origDurations = Statistics('original durations')
durations = Statistics('new durations')
durationDiffs = Statistics('duration differences')
with open(out, 'w') as f:
f.write("<tripDiffs>\n")
for v in parse(new, 'tripinfo'):
if v.id in vehicles_orig:
vOrig = vehicles_orig[v.id]
departDiff = float(v.depart) - float(vOrig.depart)
arrivalDiff = float(v.arrival) - float(vOrig.arrival)
timeLossDiff = float(v.timeLoss) - float(vOrig.timeLoss)
durationDiff = float(v.duration) - float(vOrig.duration)
routeLengthDiff = float(v.routeLength) - \
float(vOrig.routeLength)
durations.add(float(v.duration), v.id)
origDurations.add(float(vOrig.duration), v.id)
durationDiffs.add(durationDiff, v.id)
f.write(''' <vehicle id="%s" departDiff="%s" arrivalDiff="%s" timeLossDiff="%s" durationDiff="%s" routeLengthDiff="%s"/>\n''' % (
v.id, departDiff, arrivalDiff, timeLossDiff, durationDiff, routeLengthDiff))
del vehicles_orig[v.id]
else:
f.write(' <vehicle id="%s" comment="new"/>\n' % v.id)
for id in vehicles_orig.keys():
f.write(' <vehicle id="%s" comment="missing"/>\n' % id)
f.write("</tripDiffs>\n")
if earliest_out is not None:
with open(earliest_out, 'w') as f:
for diff in reversed(sorted(earliest_diffs.keys())):
f.write("%s, %s\n" % (diff, earliest_diffs[diff]))
print(origDurations)
print(durations)
print(durationDiffs)
开发者ID:cbrafter,项目名称:sumo,代码行数:39,代码来源:tripinfoDiff.py
示例18: main
def main(tag, attr, *xmlfiles):
data = []
for xmlfile in xmlfiles:
stats = Statistics('%s %s' % (tag, attr))
for elem in parse(xmlfile, tag):
stats.add(float(elem.getAttribute(attr)), elem.id)
print(stats)
data.append(stats.values)
try:
import matplotlib.pyplot as plt
except Exception as e:
sys.exit(e)
plt.figure()
plt.xticks(range(len(xmlfiles)), xmlfiles)
plt.ylabel("%s %s" % (tag, attr))
plt.boxplot(data)
plt.show()
开发者ID:behrisch,项目名称:sumo,代码行数:17,代码来源:plotXMLAttr.py
示例19: main
def main(options):
net = readNet(options.network)
edges = set([e.getID() for e in net.getEdges()])
print("Valid area contains %s edges" % len(edges))
def write_to_file(vehicles, f):
f.write('<!-- generated with %s for %s from %s -->\n' %
(os.path.basename(__file__), options.network, options.routeFiles))
f.write(
('<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">\n'))
num_trips = 0
num_persons = 0
for _, v in vehicles:
if v.name == 'trip':
num_trips += 1
else:
num_persons += 1
writer(f, v)
f.write('</routes>\n')
if num_persons > 0:
print("Wrote %s trips and %s persons" % (num_trips, num_persons))
else:
print("Wrote %s trips" % (num_trips))
validTaz = set()
if options.additional_input:
for taz in parse(options.additional_input, 'taz'):
validTaz.add(taz.id)
if options.big:
# write output unsorted
tmpname = options.output + ".unsorted"
with codecs.open(tmpname, 'w', encoding='utf8') as f:
write_to_file(
cut_trips(edges, options, validTaz), f)
# sort out of memory
sort_routes.main([tmpname, '--big', '--outfile', options.output])
else:
routes = list(cut_trips(edges, options, validTaz))
routes.sort(key=lambda v: v[0])
with codecs.open(options.output, 'w', encoding='utf8') as f:
write_to_file(routes, f)
开发者ID:behrisch,项目名称:sumo,代码行数:43,代码来源:cutTrips.py
示例20: trackLanes
def trackLanes(netstate, out):
# veh_id -> values
laneTimes = defaultdict(list)
laneChanges = defaultdict(lambda: 0)
lastEdge = defaultdict(lambda: None)
arrivals = {}
running = set()
with open(out, 'w') as f:
f.write("<vehLanes>\n")
for timestep in parse(netstate, 'timestep'):
seen = set()
if timestep.edge is not None:
for edge in timestep.edge:
if edge.lane is not None:
for lane in edge.lane:
if lane.vehicle is not None:
for vehicle in lane.vehicle:
seen.add(vehicle.id)
if not vehicle.id in running or laneTimes[vehicle.id][-1][1] != lane.id:
laneTimes[vehicle.id].append(
(timestep.time, lane.id))
running.add(vehicle.id)
if lastEdge[vehicle.id] == edge.id:
laneChanges[vehicle.id] += 1
lastEdge[vehicle.id] = edge.id
for veh_id in running:
if not veh_id in seen:
arrivals[veh_id] = timestep.time
running = running - set(arrivals.keys())
for veh_id, lt in laneTimes.items():
f.write(' <vehicle id="%s" laneTimes="%s" arrival="%s" laneChanges="%s"/>\n' % (
veh_id,
' '.join(['%s,%s' % (t, l) for t, l in lt]),
arrivals.get(veh_id),
laneChanges[veh_id]))
f.write("</vehLanes>\n")
开发者ID:aarongolliver,项目名称:sumo,代码行数:39,代码来源:vehLanes.py
注:本文中的sumolib.output.parse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论