mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-21 19:16:30 +00:00
Fix parse logic for vclass density
This commit is contained in:
parent
35aba76ff2
commit
128f8adebd
@ -20,13 +20,11 @@ vehicle_classes = {
|
|||||||
'--prefix': 'veh',
|
'--prefix': 'veh',
|
||||||
'--min-distance': 300,
|
'--min-distance': 300,
|
||||||
'--trip-attributes': 'departLane="best"',
|
'--trip-attributes': 'departLane="best"',
|
||||||
# '--validate': True
|
|
||||||
},
|
},
|
||||||
'bus': {
|
'bus': {
|
||||||
'--vehicle-class': 'bus',
|
'--vehicle-class': 'bus',
|
||||||
'--vclass': 'bus',
|
'--vclass': 'bus',
|
||||||
'--prefix': 'bus',
|
'--prefix': 'bus',
|
||||||
# '--validate': True
|
|
||||||
},
|
},
|
||||||
'truck': {
|
'truck': {
|
||||||
'--vehicle-class': 'truck',
|
'--vehicle-class': 'truck',
|
||||||
@ -34,7 +32,6 @@ vehicle_classes = {
|
|||||||
'--prefix': 'truck',
|
'--prefix': 'truck',
|
||||||
'--min-distance': 600,
|
'--min-distance': 600,
|
||||||
'--trip-attributes': 'departLane="best"',
|
'--trip-attributes': 'departLane="best"',
|
||||||
# '--validate': True
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,6 +39,7 @@ vehicle_classes = {
|
|||||||
class RandomTripsGenerator:
|
class RandomTripsGenerator:
|
||||||
def __init__(self, netpath, routepath, output, vclass, density, *flags, **opts):
|
def __init__(self, netpath, routepath, output, vclass, density, *flags, **opts):
|
||||||
self.vclass = vclass
|
self.vclass = vclass
|
||||||
|
self.density = density
|
||||||
self.options = {
|
self.options = {
|
||||||
# Default options
|
# Default options
|
||||||
'--net-file': netpath,
|
'--net-file': netpath,
|
||||||
@ -58,7 +56,7 @@ class RandomTripsGenerator:
|
|||||||
self.options[opt_name] = value
|
self.options[opt_name] = value
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
print(f'Generating trips for vehicle class {self.vclass}')
|
print(f'Generating trips for vehicle class {self.vclass} with density of {self.density} veh/km/h')
|
||||||
randomTrips.main(randomTrips.get_options(dict_to_list(self.options) + self.flags))
|
randomTrips.main(randomTrips.get_options(dict_to_list(self.options) + self.flags))
|
||||||
|
|
||||||
def _init_trips(self, edges, vclass, density):
|
def _init_trips(self, edges, vclass, density):
|
||||||
@ -159,12 +157,13 @@ def generate_mobility(out_path, name, vclasses):
|
|||||||
output = os.path.join(out_path, f'{name}.trips.xml')
|
output = os.path.join(out_path, f'{name}.trips.xml')
|
||||||
routefiles = []
|
routefiles = []
|
||||||
end_time = 200
|
end_time = 200
|
||||||
for vclass in vclasses:
|
for vclass, density in vclasses.items():
|
||||||
# simname.bus.rou.xml, simname.passenger.rou.xml, ...
|
# simname.bus.rou.xml, simname.passenger.rou.xml, ...
|
||||||
routefile = f'{name}.{vclass}.rou.xml'
|
routefile = f'{name}.{vclass}.rou.xml'
|
||||||
routepath = os.path.join(out_path, routefile)
|
routepath = os.path.join(out_path, routefile)
|
||||||
routefiles.append(routefile)
|
routefiles.append(routefile)
|
||||||
generator = RandomTripsGenerator(netpath, routepath, output, vclass, 10.0, '-l', **{'--end': end_time})
|
generator = RandomTripsGenerator(netpath, routepath, output, vclass, float(density), '-l', '--validate',
|
||||||
|
**{'--end': end_time})
|
||||||
generator.generate()
|
generator.generate()
|
||||||
return routefiles
|
return routefiles
|
||||||
|
|
||||||
@ -196,7 +195,7 @@ def dict_to_list(d):
|
|||||||
return [item for k in d for item in (k, d[k])]
|
return [item for k in d for item in (k, d[k])]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def parse_command_line():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('osmfile', help='Path to the .osm file to convert to a SUMO simulation')
|
parser.add_argument('osmfile', help='Path to the .osm file to convert to a SUMO simulation')
|
||||||
parser.add_argument('--path', help='Where to generate the files')
|
parser.add_argument('--path', help='Where to generate the files')
|
||||||
@ -209,8 +208,8 @@ def main():
|
|||||||
'given in vehicles per hour per kilometer. For now, the following vehicle classes are '
|
'given in vehicles per hour per kilometer. For now, the following vehicle classes are '
|
||||||
'available: passenger, truck, bus.')
|
'available: passenger, truck, bus.')
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
# If no vehicle classes are specified, use 'passenger' as a default
|
# If no vehicle classes are specified, use 'passenger' as a default with a density of 10 cars/km/h.
|
||||||
options.vclasses = options.vclasses or ('passenger',)
|
options.vclasses = options.vclasses or {'passenger': 10}
|
||||||
# Delete simul_dir if it already exists
|
# Delete simul_dir if it already exists
|
||||||
simul_dir = os.path.join(options.path, options.name)
|
simul_dir = os.path.join(options.path, options.name)
|
||||||
if os.path.isdir(simul_dir):
|
if os.path.isdir(simul_dir):
|
||||||
@ -220,5 +219,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
parse_command_line()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user