Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/net/createRoundaboutConnections.py
169673 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 createRoundaboutConnections.py
15
# @author Laura Bieker
16
# @author Daniel Krajzewicz
17
# @author Michael Behrisch
18
# @date 2007-02-21
19
20
"""
21
This script reads in the network given as
22
first parameter and generates additional connections for roundabouts.
23
"""
24
from __future__ import absolute_import
25
from __future__ import print_function
26
27
28
import os
29
import sys
30
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
31
import sumolib.net # noqa
32
33
34
def writeConnections(net):
35
fd = open("roundabout-connection.con.xml", "w")
36
fd.write("<connections>\n")
37
for ra in net.getRoundabouts():
38
for node in ra.getNodes():
39
edgesOut = net.getNode(node)._outgoing
40
edgesIn = net.getNode(node)._incoming
41
for edgeOut in edgesOut:
42
outNumber = edgeOut.getLaneNumber()
43
for edgeIn in edgesIn:
44
if edgeOut not in edgeIn._outgoing:
45
continue
46
inNumber = edgeIn.getLaneNumber()
47
for x in range(inNumber):
48
if x < inNumber and x < outNumber:
49
fd.write(" <connection from=\"" + str(edgeIn._id) + "\" to=\"" + str(
50
edgeOut._id) + "\" lane=\"" + str(x) + ":" + str(x) + "\" />\n")
51
fd.write("</connections>\n")
52
53
54
if __name__ == "__main__":
55
op = sumolib.options.ArgumentParser(
56
description='Create connections in roundabout')
57
58
op.add_argument("-n", "--net-file", category="input", type=op.net_file, dest="net", required=True,
59
help='Input file name')
60
61
try:
62
options = op.parse_args()
63
except (NotImplementedError, ValueError) as e:
64
print(e, file=sys.stderr)
65
sys.exit(1)
66
67
print("Reading net...")
68
net = sumolib.net.readNet(options.net)
69
print("Writing connections...")
70
writeConnections(net)
71
72