Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/route/addParkingAreaStops2Routes.py
169674 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2010-2025 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file addParkingAreaStops2Routes.py
15
# @author Evamarie Wiessner
16
# @date 2017-01-09
17
18
"""
19
add stops at parkingAreas to vehicle routes
20
"""
21
22
from __future__ import print_function
23
from __future__ import absolute_import
24
import os
25
import sys
26
27
if 'SUMO_HOME' in os.environ:
28
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
29
sys.path.append(tools)
30
else:
31
sys.exit("please declare environment variable 'SUMO_HOME'")
32
33
import sumolib # noqa
34
35
36
def get_options(args=None):
37
optParser = sumolib.options.ArgumentParser()
38
optParser.add_option("-r", "--route-file", category='input', dest="routefile", help="define the route file")
39
optParser.add_option("-o", "--output-file", category='output', dest="outfile",
40
help="output route file including parking")
41
optParser.add_option("-p", "--parking-areas", category='input', dest="parking",
42
help="define the parking areas separated by comma")
43
optParser.add_option("-d", "--parking-duration", dest="duration",
44
help="define the parking duration (in seconds)", default=3600)
45
optParser.add_option("-v", "--verbose", dest="verbose", action="store_true",
46
default=False, help="tell me what you are doing")
47
options = optParser.parse_args(args=args)
48
if not options.routefile or not options.parking:
49
optParser.print_help()
50
sys.exit()
51
return options
52
53
54
def main(options):
55
infile = options.routefile
56
if not options.outfile:
57
outfile = infile.replace(".xml", ".parking.xml")
58
59
with open(outfile, 'w') as outf:
60
outf.write("<?xml version= \"1.0\" encoding=\"UTF-8\"?>\n\n")
61
outf.write("<routes>\n")
62
for veh in sumolib.xml.parse(infile, "vehicle"):
63
stops = [x for x in options.parking.split(',') if x in veh.id]
64
for stop in stops:
65
veh.addChild("stop", {"parkingArea": stop, "duration": int(options.duration)})
66
veh.setAttribute("arrivalPos", -2)
67
outf.write(veh.toXML(initialIndent=" "))
68
outf.write("</routes>\n")
69
70
71
if __name__ == "__main__":
72
options = get_options()
73
main(options)
74
75