Path: blob/main/tools/route/addParkingAreaStops2Routes.py
169674 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2010-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 addParkingAreaStops2Routes.py14# @author Evamarie Wiessner15# @date 2017-01-091617"""18add stops at parkingAreas to vehicle routes19"""2021from __future__ import print_function22from __future__ import absolute_import23import os24import sys2526if 'SUMO_HOME' in os.environ:27tools = os.path.join(os.environ['SUMO_HOME'], 'tools')28sys.path.append(tools)29else:30sys.exit("please declare environment variable 'SUMO_HOME'")3132import sumolib # noqa333435def get_options(args=None):36optParser = sumolib.options.ArgumentParser()37optParser.add_option("-r", "--route-file", category='input', dest="routefile", help="define the route file")38optParser.add_option("-o", "--output-file", category='output', dest="outfile",39help="output route file including parking")40optParser.add_option("-p", "--parking-areas", category='input', dest="parking",41help="define the parking areas separated by comma")42optParser.add_option("-d", "--parking-duration", dest="duration",43help="define the parking duration (in seconds)", default=3600)44optParser.add_option("-v", "--verbose", dest="verbose", action="store_true",45default=False, help="tell me what you are doing")46options = optParser.parse_args(args=args)47if not options.routefile or not options.parking:48optParser.print_help()49sys.exit()50return options515253def main(options):54infile = options.routefile55if not options.outfile:56outfile = infile.replace(".xml", ".parking.xml")5758with open(outfile, 'w') as outf:59outf.write("<?xml version= \"1.0\" encoding=\"UTF-8\"?>\n\n")60outf.write("<routes>\n")61for veh in sumolib.xml.parse(infile, "vehicle"):62stops = [x for x in options.parking.split(',') if x in veh.id]63for stop in stops:64veh.addChild("stop", {"parkingArea": stop, "duration": int(options.duration)})65veh.setAttribute("arrivalPos", -2)66outf.write(veh.toXML(initialIndent=" "))67outf.write("</routes>\n")686970if __name__ == "__main__":71options = get_options()72main(options)737475