1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-24 04:26:29 +00:00

Fix sumoconfig when polygon generation is disabled

This commit is contained in:
Thibaud Gasser 2019-01-30 14:20:15 +01:00
parent 39f84ad4b1
commit 35aba76ff2
2 changed files with 13 additions and 7 deletions

View File

@ -113,8 +113,11 @@ def load_sumoconfig_template(simulation_name, routefiles=(), generate_polygons=F
root = sumoconfig.getroot() root = sumoconfig.getroot()
root.find('input/net-file').set('value', f'{simulation_name}.net.xml') root.find('input/net-file').set('value', f'{simulation_name}.net.xml')
root.find('input/route-files').set('value', ','.join(routefiles)) root.find('input/route-files').set('value', ','.join(routefiles))
additional = root.find('input/additional-files')
if generate_polygons: if generate_polygons:
root.find('input/additional-files').set('value', f'{simulation_name}.poly.xml') additional.set('value', f'{simulation_name}.poly.xml')
else:
root.find('input').remove(additional)
root.find('report/log').set('value', f'{simulation_name}.log') root.find('report/log').set('value', f'{simulation_name}.log')
return sumoconfig return sumoconfig
@ -198,21 +201,24 @@ def main():
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')
parser.add_argument('--name', required=True, help='Name of the SUMO scenario to generate') parser.add_argument('--name', required=True, help='Name of the SUMO scenario to generate')
parser.add_argument('--generate-polygons', default=False) parser.add_argument('--generate-polygons', default=False, action='store_true', help='Whether to generate polygons '
'and POIs (defaults to false).')
parser.add_argument('--vclass', dest='vclasses', action=StoreDictKeyPair, parser.add_argument('--vclass', dest='vclasses', action=StoreDictKeyPair,
nargs="+", metavar="VCLASS=DENSITY", nargs="+", metavar="VCLASS=DENSITY",
help='Generate this vclass with given density, in pair form vclass=density. The density is ' help='Generate this vclass with given density, in pair form vclass=density. The density is '
'given in vehicles per hour per kilometer.') 'given in vehicles per hour per kilometer. For now, the following vehicle classes are '
'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
vclasses = options.vclasses or ('passenger',) options.vclasses = options.vclasses or ('passenger',)
# FIXME 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):
input(f'{simul_dir} already exists ! Press Enter to overwrite...') input(f'{simul_dir} already exists ! Press Enter to delete...')
shutil.rmtree(simul_dir) shutil.rmtree(simul_dir)
generate_all(options) generate_all(options)
if __name__ == '__main__': if __name__ == '__main__':
main() main()