Path: blob/main/tools/output/generateITetrisNetworkMetrics.py
169674 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file generateITetrisNetworkMetrics.py14# @author Daniel Krajzewicz15# @author Michael Behrisch16# @date 2007-10-251718from __future__ import absolute_import19from __future__ import print_function20from optparse import OptionParser21import os22import sys23import numpy24from xml.sax import make_parser, handler25sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))26import sumolib.net # noqa272829def quantil(a, alpha):30asort = numpy.sort(a)31n = len(asort)32j = int(n * alpha)33if (j * alpha == n):34return 0.5 * (asort[j - 1] + asort[j])35else:36return asort[j]3738# This class is for storing vehicle information, such as departure time,39# route and travel time.404142class Vehicle:4344def __init__(self, label):45self.label = label46self.depart = 0.47self.arrival = 0.48self.speed = 0.49self.traveltime = 0.50self.travellength = 0.51self.departdelay = 0.52self.waittime = 0.53self.fuel_consumption = 0.54self.co = 0.55self.co2 = 0.56self.hc = 0.57self.pmx = 0.58self.nox = 0.59self.vtype = None6061def __repr__(self):62return "%s_%s_%s_%s_%s_%s" % (63self.label, self.depart, self.arrival, self.speed, self.traveltime, self.travellength)646566class VehInformationReader(handler.ContentHandler):6768def __init__(self, vehList):69self._vehList = vehList70self._Vehicle = None7172def startElement(self, name, attrs):73if name == 'tripinfo':74self._Vehicle = Vehicle(attrs['id'])75self._Vehicle.vtype = attrs['vtype']76self._Vehicle.traveltime = float(attrs['duration'])77self._Vehicle.travellength = float(attrs['routeLength'])78self._Vehicle.departdelay = float(attrs['departDelay'])79self._Vehicle.waittime = float(80attrs['departDelay']) + float(attrs['waitingTime'])81self._Vehicle.depart = float(attrs['depart'])82self._vehList.append(self._Vehicle)83if name == 'emissions':84self._Vehicle.fuel_consumption = float(attrs['fuel_abs'])85self._Vehicle.co = float(attrs['CO_abs'])86self._Vehicle.co2 = float(attrs['CO2_abs'])87self._Vehicle.hc = float(attrs['HC_abs'])88self._Vehicle.pmx = float(attrs['PMx_abs'])89self._Vehicle.nox = float(attrs['NOx_abs'])909192class VehRoutesReader(handler.ContentHandler):9394def __init__(self):95self._routes = []96self._depart = 097self._arrival = 09899def startElement(self, name, attrs):100if name == 'vehicle':101self._depart = int(attrs['depart'])102self._arrival = int(attrs['arrival'])103if name == 'route':104self._routes.append((attrs['edges'], self._arrival - self._depart))105106107def getAvgNrLanesPerStreet(netfile):108net = sumolib.net.readNet(netfile)109nrLanes = 0110for edge in net._edges:111nrLanes += len(edge._lanes)112113return 1.0 * nrLanes / len(net._edges)114115116def getRouteDistributions(vehroutesFile):117parser = make_parser()118viReader = VehRoutesReader()119parser.setContentHandler(viReader)120parser.parse(vehroutesFile)121122routes = viReader._routes123124startEnd = {}125for route in routes:126routeSplit = route[0].split(' ')127if ((routeSplit[0], routeSplit[-1]) not in startEnd):128startEnd[routeSplit[0], routeSplit[-1]] = {}129if (route[0] not in startEnd[routeSplit[0], routeSplit[-1]]):130startEnd[routeSplit[0], routeSplit[-1]][route[0]] = [0, 0]131startEnd[routeSplit[0], routeSplit[-1]][route[0]][0] += 1132startEnd[routeSplit[0], routeSplit[-1]][route[0]][1] += route[1]133return startEnd134135136def getBasicStats(vehicles):137totalVeh = 0.138aTravelTime = []139aTravelLength = []140aTravelSpeed = []141aWaitTime = []142aDepartDelay = []143aFuelConsumption = []144aCO = []145aCO2 = []146aHC = []147aPMx = []148aNOx = []149150for veh in vehicles:151totalVeh += 1152# unit: speed - m/s; traveltime - s; travel length - m153veh.speed = veh.travellength / veh.traveltime154aTravelTime.append(veh.traveltime)155aTravelLength.append(veh.travellength)156aWaitTime.append(veh.waittime)157aTravelSpeed.append(veh.speed)158aDepartDelay.append(veh.departdelay)159aFuelConsumption.append(veh.fuel_consumption)160aCO.append(veh.co)161aCO2.append(veh.co2)162aHC.append(veh.hc)163aPMx.append(veh.pmx)164aNOx.append(veh.nox)165166assignments = {}167assignments['totalVeh'] = totalVeh168assignments['totalTravelTime'] = sum(aTravelTime)169assignments['totalTravelLength'] = sum(aTravelLength)170assignments['totalDepartDelay'] = sum(aDepartDelay)171assignments['totalWaitTime'] = sum(aWaitTime)172assignments['totalFuelConsumption'] = sum(aFuelConsumption)173assignments['totalCO'] = sum(aCO)174assignments['totalCO2'] = sum(aCO2)175assignments['totalHC'] = sum(aHC)176assignments['totalPMx'] = sum(aPMx)177assignments['totalNOx'] = sum(aNOx)178179assignments['avgTravelTime'] = numpy.mean(aTravelTime)180assignments['avgTravelLength'] = numpy.mean(aTravelLength)181assignments['avgTravelSpeed'] = numpy.mean(aTravelSpeed)182assignments['avgDepartDelay'] = numpy.mean(aDepartDelay)183assignments['avgWaitTime'] = numpy.mean(aWaitTime)184assignments['avgFuelConsumption'] = numpy.mean(aFuelConsumption)185assignments['avgCO'] = numpy.mean(aCO)186assignments['avgCO2'] = numpy.mean(aCO2)187assignments['avgHC'] = numpy.mean(aHC)188assignments['avgPMx'] = numpy.mean(aPMx)189assignments['avgNOx'] = numpy.mean(aNOx)190191assignments['SDTravelTime'] = numpy.std(aTravelTime)192assignments['SDLength'] = numpy.std(aTravelLength)193assignments['SDSpeed'] = numpy.std(aTravelSpeed)194assignments['SDWaitTime'] = numpy.std(aWaitTime)195assignments['SDFuelConsumption'] = numpy.std(aFuelConsumption)196assignments['SDCO'] = numpy.std(aCO)197assignments['SDCO2'] = numpy.std(aCO2)198assignments['SDHC'] = numpy.std(aHC)199assignments['SDPMx'] = numpy.std(aPMx)200assignments['SDNOx'] = numpy.std(aNOx)201202assignments['quartil25TravelTime'] = quantil(aTravelTime, 0.25)203assignments['quartil25Length'] = quantil(aTravelLength, 0.25)204assignments['quartil25Speed'] = quantil(aTravelSpeed, 0.25)205assignments['quartil25WaitTime'] = quantil(aWaitTime, 0.25)206assignments['quartil25FuelConsumption'] = quantil(aFuelConsumption, 0.25)207assignments['quartil25CO'] = quantil(aCO, 0.25)208assignments['quartil25CO2'] = quantil(aCO2, 0.25)209assignments['quartil25HC'] = quantil(aHC, 0.25)210assignments['quartil25PMx'] = quantil(aPMx, 0.25)211assignments['quartil25NOx'] = quantil(aNOx, 0.25)212213assignments['quartil75TravelTime'] = quantil(aTravelTime, 0.75)214assignments['quartil75Length'] = quantil(aTravelLength, 0.75)215assignments['quartil75Speed'] = quantil(aTravelSpeed, 0.75)216assignments['quartil75WaitTime'] = quantil(aWaitTime, 0.75)217assignments['quartil75FuelConsumption'] = quantil(aFuelConsumption, 0.75)218assignments['quartil75CO'] = quantil(aCO, 0.75)219assignments['quartil75CO2'] = quantil(aCO2, 0.75)220assignments['quartil75HC'] = quantil(aHC, 0.75)221assignments['quartil75PMx'] = quantil(aPMx, 0.75)222assignments['quartil75NOx'] = quantil(aNOx, 0.75)223224assignments['medianTravelTime'] = quantil(aTravelTime, 0.5)225assignments['medianLength'] = quantil(aTravelLength, 0.5)226assignments['medianSpeed'] = quantil(aTravelSpeed, 0.5)227assignments['medianWaitTime'] = quantil(aWaitTime, 0.5)228assignments['medianFuelConsumption'] = quantil(aFuelConsumption, 0.5)229assignments['medianCO'] = quantil(aCO, 0.5)230assignments['medianCO2'] = quantil(aCO2, 0.5)231assignments['medianHC'] = quantil(aHC, 0.5)232assignments['medianPMx'] = quantil(aPMx, 0.5)233assignments['medianNOx'] = quantil(aNOx, 0.5)234235return assignments236237238# output the network statistics based on the sumo-simulation results239def writeStatistics(assignments, out):240out.write('mean number of lanes per street : %f\n\n' %241assignments['avgNrLanes'])242243out.write('total number of vehicles : %f\n\n' % assignments['totalVeh'])244245out.write('travel time\n')246out.write('===========\n')247out.write('total : %f\n' % assignments['totalTravelTime'])248out.write('mean : %f\n' % assignments['avgTravelTime'])249out.write('std : %f\n' % assignments['SDTravelTime'])250out.write('1/4-quantil : %f\n' % assignments['quartil25TravelTime'])251out.write('median : %f\n' % assignments['medianTravelTime'])252out.write('3/4-quantil : %f\n\n' % assignments['quartil75TravelTime'])253254out.write('travel speed\n')255out.write('============\n')256out.write('mean : %f\n' % assignments['avgTravelSpeed'])257out.write('std : %f\n' % assignments['SDSpeed'])258out.write('1/4-quantil : %f\n' % assignments['quartil25Speed'])259out.write('median : %f\n' % assignments['medianSpeed'])260out.write('3/4-quantil : %f\n\n' % assignments['quartil75Speed'])261262out.write('waiting time\n')263out.write('============\n')264out.write('total : %f\n' % assignments['totalWaitTime'])265out.write('mean : %f\n' % assignments['avgWaitTime'])266out.write('std : %f\n' % assignments['SDWaitTime'])267out.write('1/4-quantil : %f\n' % assignments['quartil25WaitTime'])268out.write('median : %f\n' % assignments['medianWaitTime'])269out.write('3/4-quantil : %f\n\n' % assignments['quartil75WaitTime'])270271out.write('distance travelled\n')272out.write('==================\n')273out.write('total : %f\n' % assignments['totalTravelLength'])274out.write('mean : %f\n' % assignments['avgTravelLength'])275out.write('std : %f\n' % assignments['SDLength'])276out.write('1/4-quantil : %f\n' % assignments['quartil25Length'])277out.write('median : %f\n' % assignments['medianLength'])278out.write('3/4-quantil : %f\n\n' % assignments['quartil75Length'])279280out.write('fuel consumption\n')281out.write('================\n')282out.write('total : %f\n' % assignments['totalFuelConsumption'])283out.write('mean : %f\n' % assignments['avgFuelConsumption'])284out.write('std : %f\n' % assignments['SDFuelConsumption'])285out.write('1/4-quantil : %f\n' % assignments['quartil25FuelConsumption'])286out.write('median : %f\n' % assignments['medianFuelConsumption'])287out.write('3/4-quantil : %f\n\n' % assignments['quartil75FuelConsumption'])288289out.write('CO emissions\n')290out.write('============\n')291out.write('total : %f\n' % assignments['totalCO'])292out.write('mean : %f\n' % assignments['avgCO'])293out.write('std : %f\n' % assignments['SDCO'])294out.write('1/4-quantil : %f\n' % assignments['quartil25CO'])295out.write('median : %f\n' % assignments['medianCO'])296out.write('3/4-quantil : %f\n\n' % assignments['quartil75CO'])297298out.write('CO2 emissions\n')299out.write('=============\n')300out.write('total : %f\n' % assignments['totalCO2'])301out.write('mean : %f\n' % assignments['avgCO2'])302out.write('std : %f\n' % assignments['SDCO2'])303out.write('1/4-quantil : %f\n' % assignments['quartil25CO2'])304out.write('median : %f\n' % assignments['medianCO2'])305out.write('3/4-quantil : %f\n\n' % assignments['quartil75CO2'])306307out.write('HC emissions\n')308out.write('============\n')309out.write('total : %f\n' % assignments['totalHC'])310out.write('mean : %f\n' % assignments['avgHC'])311out.write('std : %f\n' % assignments['SDHC'])312out.write('1/4-quantil : %f\n' % assignments['quartil25HC'])313out.write('median : %f\n' % assignments['medianHC'])314out.write('3/4-quantil : %f\n\n' % assignments['quartil75HC'])315316out.write('PMx emissions\n')317out.write('=============\n')318out.write('total : %f\n' % assignments['totalPMx'])319out.write('mean : %f\n' % assignments['avgPMx'])320out.write('std : %f\n' % assignments['SDPMx'])321out.write('1/4-quantil : %f\n' % assignments['quartil25PMx'])322out.write('median : %f\n' % assignments['medianPMx'])323out.write('3/4-quantil : %f\n\n' % assignments['quartil75PMx'])324325out.write('NOx emissions\n')326out.write('=============\n')327out.write('total : %f\n' % assignments['totalNOx'])328out.write('mean : %f\n' % assignments['avgNOx'])329out.write('std : %f\n' % assignments['SDNOx'])330out.write('1/4-quantil : %f\n' % assignments['quartil25NOx'])331out.write('median : %f\n' % assignments['medianNOx'])332out.write('3/4-quantil : %f\n\n' % assignments['quartil75NOx'])333334335# output the network statistics based on the sumo-simulation results336def getStatisticsOutput(assignments, outputfile):337foutveh = open(outputfile, 'w')338writeStatistics(assignments, foutveh)339foutveh.write('\n\nRoute distribution:\n')340foutveh.write('==================:\n')341startEnd = assignment['routeDistr']342for se in startEnd:343for r in startEnd[se]:344foutveh.write('%s: Number of vehicles: %d, Avg Travel Time: %d\n' % (345r, startEnd[se][r][0], 1.0 * startEnd[se][r][1] / startEnd[se][r][0]))346foutveh.write('\n')347foutveh.close()348writeStatistics(assignments, sys.stdout)349350351def getCSVOutput(assignments, path, veh_types, interval):352f_mean_travel_time = open(353os.path.join(options.path, 'mean_travel_time.csv'), 'w')354f_mean_speed = open(os.path.join(options.path, 'mean_speed.csv'), 'w')355f_mean_waiting_time = open(356os.path.join(options.path, 'mean_waiting_time.csv'), 'w')357f_mean_distance_travelled = open(358os.path.join(options.path, 'mean_distance_travelled.csv'), 'w')359f_mean_fuel_consumption = open(360os.path.join(options.path, 'mean_fuel_consumption.csv'), 'w')361f_mean_CO_emissions = open(362os.path.join(options.path, 'mean_CO_emissions.csv'), 'w')363f_mean_CO2_emissions = open(364os.path.join(options.path, 'mean_CO2_emissions.csv'), 'w')365f_mean_HC_emissions = open(366os.path.join(options.path, 'mean_HC_emissions.csv'), 'w')367f_mean_PMx_emissions = open(368os.path.join(options.path, 'mean_PMx_emissions.csv'), 'w')369f_mean_NOx_emissions = open(370os.path.join(options.path, 'mean_NOx_emissions.csv'), 'w')371f_abs_travel_time = open(372os.path.join(options.path, 'abs_travel_time.csv'), 'w')373f_abs_waiting_time = open(374os.path.join(options.path, 'abs_waiting_time.csv'), 'w')375f_abs_distance_travelled = open(376os.path.join(options.path, 'abs_distance_travelled.csv'), 'w')377f_abs_fuel_consumption = open(378os.path.join(options.path, 'abs_fuel_consumption.csv'), 'w')379f_abs_CO_emissions = open(380os.path.join(options.path, 'abs_CO_emissions.csv'), 'w')381f_abs_CO2_emissions = open(382os.path.join(options.path, 'abs_CO2_emissions.csv'), 'w')383f_abs_HC_emissions = open(384os.path.join(options.path, 'abs_HC_emissions.csv'), 'w')385f_abs_PMx_emissions = open(386os.path.join(options.path, 'abs_PMx_emissions.csv'), 'w')387f_abs_NOx_emissions = open(388os.path.join(options.path, 'abs_NOx_emissions.csv'), 'w')389390files = []391files.append(f_mean_travel_time)392files.append(f_mean_speed)393files.append(f_mean_waiting_time)394files.append(f_mean_distance_travelled)395files.append(f_mean_fuel_consumption)396files.append(f_mean_CO_emissions)397files.append(f_mean_CO2_emissions)398files.append(f_mean_HC_emissions)399files.append(f_mean_PMx_emissions)400files.append(f_mean_NOx_emissions)401files.append(f_abs_travel_time)402files.append(f_abs_waiting_time)403files.append(f_abs_distance_travelled)404files.append(f_abs_fuel_consumption)405files.append(f_abs_CO_emissions)406files.append(f_abs_CO2_emissions)407files.append(f_abs_HC_emissions)408files.append(f_abs_PMx_emissions)409files.append(f_abs_NOx_emissions)410411for f in files:412f.write(';')413414for veh_type in veh_types:415head = veh_type + '(mean);' + veh_type + '(std);' + veh_type + \416'(1/4-quantil);' + veh_type + \417'(median);' + veh_type + '(3/4-quantil);'418f_mean_travel_time.write(head)419f_mean_speed.write(head)420f_mean_waiting_time.write(head)421f_mean_distance_travelled.write(head)422f_mean_fuel_consumption.write(head)423f_mean_CO_emissions.write(head)424f_mean_CO2_emissions.write(head)425f_mean_HC_emissions.write(head)426f_mean_PMx_emissions.write(head)427f_mean_NOx_emissions.write(head)428f_abs_travel_time.write(veh_type + ';')429f_abs_waiting_time.write(veh_type + ';')430f_abs_distance_travelled.write(veh_type + ';')431f_abs_fuel_consumption.write(veh_type + ';')432f_abs_CO_emissions.write(veh_type + ';')433f_abs_CO2_emissions.write(veh_type + ';')434f_abs_HC_emissions.write(veh_type + ';')435f_abs_PMx_emissions.write(veh_type + ';')436f_abs_NOx_emissions.write(veh_type + ';')437438for f in files:439f.write('\n')440441t = 0442while t in assignments:443for f in files:444f.write('[' + str(t) + ':' + str(t + interval - 1) + '];')445for veh_type in assignments[t].values():446f_mean_travel_time.write(str(veh_type['avgTravelTime']) + ";" + str(veh_type['SDTravelTime']) + ";" +447str(veh_type['quartil25TravelTime']) + ";" + str(veh_type['medianTravelTime']) +448";" + str(veh_type['quartil75TravelTime']) + ";")449f_mean_speed.write(str(veh_type['avgTravelSpeed']) + ";" + str(veh_type['SDSpeed']) + ";" +450str(veh_type['quartil25Speed']) + ";" + str(veh_type['medianSpeed']) + ";" +451str(veh_type['quartil75Speed']) + ";")452f_mean_waiting_time.write(str(veh_type['avgWaitTime']) + ";" + str(veh_type['SDWaitTime']) + ";" +453str(veh_type['quartil25WaitTime']) + ";" + str(veh_type['medianWaitTime']) +454";" + str(veh_type['quartil75WaitTime']) + ";")455f_mean_distance_travelled.write(str(veh_type['avgTravelLength']) + ";" + str(veh_type['SDLength']) + ";" +456str(veh_type['quartil25Length']) + ";" + str(veh_type['medianLength']) +457";" + str(veh_type['quartil75Length']) + ";")458f_mean_fuel_consumption.write(str(veh_type['avgFuelConsumption']) + ";" +459str(veh_type['SDFuelConsumption']) + ";" +460str(veh_type['quartil25FuelConsumption']) + ";" +461str(veh_type['medianFuelConsumption']) + ";" +462str(veh_type['quartil75FuelConsumption']) + ";")463f_mean_CO_emissions.write(str(veh_type['avgCO']) + ";" + str(veh_type['SDCO']) + ";" + str(464veh_type['quartil25CO']) + ";" + str(veh_type['medianCO']) + ";" + str(veh_type['quartil75CO']) + ";")465f_mean_CO2_emissions.write(str(veh_type['avgCO2']) + ";" + str(veh_type['SDCO2']) + ";" + str(466veh_type['quartil25CO2']) + ";" + str(veh_type['medianCO2']) + ";" + str(467veh_type['quartil75CO2']) + ";")468f_mean_HC_emissions.write(str(veh_type['avgHC']) + ";" + str(veh_type['SDHC']) + ";" + str(469veh_type['quartil25HC']) + ";" + str(veh_type['medianHC']) + ";" + str(veh_type['quartil75HC']) + ";")470f_mean_PMx_emissions.write(str(veh_type['avgPMx']) + ";" + str(veh_type['SDPMx']) + ";" + str(471veh_type['quartil25PMx']) + ";" + str(veh_type['medianPMx']) + ";" + str(472veh_type['quartil75PMx']) + ";")473f_mean_NOx_emissions.write(str(veh_type['avgNOx']) + ";" + str(veh_type['SDNOx']) + ";" + str(474veh_type['quartil25NOx']) + ";" + str(veh_type['medianNOx']) + ";" + str(475veh_type['quartil75NOx']) + ";")476f_abs_travel_time.write(str(veh_type['totalTravelTime']) + ";")477f_abs_waiting_time.write(str(veh_type['totalWaitTime']) + ";")478f_abs_distance_travelled.write(479str(veh_type['totalTravelLength']) + ";")480f_abs_fuel_consumption.write(481str(veh_type['totalFuelConsumption']) + ";")482f_abs_CO_emissions.write(str(veh_type['totalCO']) + ";")483f_abs_CO2_emissions.write(str(veh_type['totalCO2']) + ";")484f_abs_HC_emissions.write(str(veh_type['totalHC']) + ";")485f_abs_PMx_emissions.write(str(veh_type['totalPMx']) + ";")486f_abs_NOx_emissions.write(str(veh_type['totalNOx']) + ";")487for f in files:488f.write('\n')489t += interval490491for f in files:492f.close()493494495# initialise496optParser = OptionParser()497optParser.add_option("-n", "--netfile", dest="netfile",498help="name of the netfile (f.e. 'inputs\\pasubio\\a_costa.net.xml')",499metavar="<FILE>", type="string")500optParser.add_option("-p", "--path", dest="path",501help="name of folder to work with (f.e. 'outputs\\a_costa\\')", metavar="<FOLDER>", type="string")502optParser.add_option("-t", "--vehicle-types", dest="vehicle_types",503help="vehicle-types for which the values shall be generated",504metavar="<VEHICLE_TYPE>[,<VEHICLE_TYPE>]", type="string")505optParser.add_option("-i", "--intervals", dest="interval",506help="intervals to be generated ([0:<TIME>-1], [<TIME>:2*<TIME>-1], ...)",507metavar="<TIME>", type="int")508509optParser.set_usage('\ngenerateITetrisNetworkMetrics.py -n inputs\\a_costa\\acosta.net.xml -p outputs\\a_costa\\ -t ' +510'passenger2a,passenger5,passenger1,passenger2b,passenger3,passenger4 -i 500 \n' +511'generateITetrisNetworkMetrics.py -n inputs\\a_costa\\acosta.net.xml -p outputs\\a_costa\\ ' +512'-i 500\n' + 'generateITetrisNetworkMetrics.py -n inputs\\a_costa\\acosta.net.xml ' +513'-p outputs\\a_costa\\')514# parse options515(options, args) = optParser.parse_args()516if not options.netfile or not options.path:517print("Missing arguments")518optParser.print_help()519exit()520521interval = options.interval522netfile = options.netfile523vehroutefile = os.path.join(options.path, 'vehroutes.xml')524525if interval is None:526interval = 10000000527528529vehicles = []530parser = make_parser()531parser.setContentHandler(VehInformationReader(vehicles))532parser.parse(os.path.join(options.path, 'tripinfos.xml'))533534if options.vehicle_types is None:535vehicle_types = ['all']536else:537vehicle_types = options.vehicle_types.split(',')538539vehicles_of_type_interval = {}540for veh in vehicles:541t = int(veh.depart / interval) * interval542if (t not in vehicles_of_type_interval):543vehicles_of_type_interval[t] = {}544for veh_type in vehicle_types:545vehicles_of_type_interval[t][veh_type] = []546if vehicle_types[0] == 'all':547vehicles_of_type_interval[t]['all'].append(veh)548else:549if (veh.vtype in vehicle_types):550vehicles_of_type_interval[t][veh.vtype].append(veh)551assignments = {}552for t in vehicles_of_type_interval.keys():553assignments[t] = {}554for veh_type in vehicle_types:555assignments[t][veh_type] = getBasicStats(556vehicles_of_type_interval[t][veh_type])557558getCSVOutput(assignments, options.path, vehicle_types, interval)559560assignment = getBasicStats(vehicles)561assignment['avgNrLanes'] = getAvgNrLanesPerStreet(netfile)562assignment['routeDistr'] = getRouteDistributions(vehroutefile)563getStatisticsOutput(564assignment, os.path.join(options.path, "network_metrics_summary.txt"))565566print('The calculation is done!')567568569