Path: blob/main/tools/net/createRoundaboutConnections.py
169673 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 createRoundaboutConnections.py14# @author Laura Bieker15# @author Daniel Krajzewicz16# @author Michael Behrisch17# @date 2007-02-211819"""20This script reads in the network given as21first parameter and generates additional connections for roundabouts.22"""23from __future__ import absolute_import24from __future__ import print_function252627import os28import sys29sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))30import sumolib.net # noqa313233def writeConnections(net):34fd = open("roundabout-connection.con.xml", "w")35fd.write("<connections>\n")36for ra in net.getRoundabouts():37for node in ra.getNodes():38edgesOut = net.getNode(node)._outgoing39edgesIn = net.getNode(node)._incoming40for edgeOut in edgesOut:41outNumber = edgeOut.getLaneNumber()42for edgeIn in edgesIn:43if edgeOut not in edgeIn._outgoing:44continue45inNumber = edgeIn.getLaneNumber()46for x in range(inNumber):47if x < inNumber and x < outNumber:48fd.write(" <connection from=\"" + str(edgeIn._id) + "\" to=\"" + str(49edgeOut._id) + "\" lane=\"" + str(x) + ":" + str(x) + "\" />\n")50fd.write("</connections>\n")515253if __name__ == "__main__":54op = sumolib.options.ArgumentParser(55description='Create connections in roundabout')5657op.add_argument("-n", "--net-file", category="input", type=op.net_file, dest="net", required=True,58help='Input file name')5960try:61options = op.parse_args()62except (NotImplementedError, ValueError) as e:63print(e, file=sys.stderr)64sys.exit(1)6566print("Reading net...")67net = sumolib.net.readNet(options.net)68print("Writing connections...")69writeConnections(net)707172