sumolib.net.generator.grid
1#!/usr/bin/env python 2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3# Copyright (C) 2013-2026 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 grid.py 15# @author Daniel Krajzewicz 16# @date 2013-10-10 17 18from __future__ import absolute_import 19# relative imports don't work if a file is used as a library and executable 20# (https://peps.python.org/pep-0366/#rationale-for-change) 21import os 22import sys 23sys.path.append(os.path.dirname(os.path.realpath(__file__))) 24import network # noqa 25 26 27def grid(numIntersectionsX=10, numIntersectionsY=5, defaultNode=None, defaultEdge=None, centralReservation=0): 28 net = network.Net(defaultNode, defaultEdge) 29 for x in range(0, numIntersectionsX): 30 net.addNode( 31 network.Node(str(x + 1) + "/0", (x + 1) * 500, 0, "priority")) 32 net.addNode(network.Node(str(x + 1) + "/" + str(numIntersectionsY + 1), 33 (x + 1) * 500, (numIntersectionsY + 1) * 500, "priority")) 34 for y in range(0, numIntersectionsY): 35 net.addNode( 36 network.Node("0/" + str(y + 1), 0, (y + 1) * 500, "priority")) 37 net.addNode(network.Node(str(numIntersectionsX + 1) + "/" + 38 str(y + 1), (numIntersectionsX + 1) * 500, (y + 1) * 500, "priority")) 39 for x in range(0, numIntersectionsX): 40 for y in range(0, numIntersectionsY): 41 net.addNode(network.Node( 42 str(x + 1) + "/" + str(y + 1), (x + 1) * 500, (y + 1) * 500, "traffic_light")) 43 for x in range(0, numIntersectionsX): 44 for y in range(0, numIntersectionsY): 45 net.connectNodes(str( 46 x) + "/" + str(y + 1), str(x + 1) + "/" + str(y + 1), True, centralReservation) 47 net.connectNodes(str( 48 x + 1) + "/" + str(y), str(x + 1) + "/" + str(y + 1), True, centralReservation) 49 for x in range(0, numIntersectionsX): 50 net.connectNodes(str(x + 1) + "/" + str(numIntersectionsY), 51 str(x + 1) + "/" + str(numIntersectionsY + 1), True, centralReservation) 52 for y in range(0, numIntersectionsY): 53 net.connectNodes(str(numIntersectionsX) + "/" + str(y + 1), 54 str(numIntersectionsX + 1) + "/" + str(y + 1), True, centralReservation) 55 return net 56# d = demand.Demand() 57# d.addStream(demand.Stream("1/0_to_1/2", 10, "1/0 1/2")) 58# d.build(3600) 59 60 61if __name__ == "__main__": 62 net = grid() 63 net.build()
def
grid( numIntersectionsX=10, numIntersectionsY=5, defaultNode=None, defaultEdge=None, centralReservation=0):
28def grid(numIntersectionsX=10, numIntersectionsY=5, defaultNode=None, defaultEdge=None, centralReservation=0): 29 net = network.Net(defaultNode, defaultEdge) 30 for x in range(0, numIntersectionsX): 31 net.addNode( 32 network.Node(str(x + 1) + "/0", (x + 1) * 500, 0, "priority")) 33 net.addNode(network.Node(str(x + 1) + "/" + str(numIntersectionsY + 1), 34 (x + 1) * 500, (numIntersectionsY + 1) * 500, "priority")) 35 for y in range(0, numIntersectionsY): 36 net.addNode( 37 network.Node("0/" + str(y + 1), 0, (y + 1) * 500, "priority")) 38 net.addNode(network.Node(str(numIntersectionsX + 1) + "/" + 39 str(y + 1), (numIntersectionsX + 1) * 500, (y + 1) * 500, "priority")) 40 for x in range(0, numIntersectionsX): 41 for y in range(0, numIntersectionsY): 42 net.addNode(network.Node( 43 str(x + 1) + "/" + str(y + 1), (x + 1) * 500, (y + 1) * 500, "traffic_light")) 44 for x in range(0, numIntersectionsX): 45 for y in range(0, numIntersectionsY): 46 net.connectNodes(str( 47 x) + "/" + str(y + 1), str(x + 1) + "/" + str(y + 1), True, centralReservation) 48 net.connectNodes(str( 49 x + 1) + "/" + str(y), str(x + 1) + "/" + str(y + 1), True, centralReservation) 50 for x in range(0, numIntersectionsX): 51 net.connectNodes(str(x + 1) + "/" + str(numIntersectionsY), 52 str(x + 1) + "/" + str(numIntersectionsY + 1), True, centralReservation) 53 for y in range(0, numIntersectionsY): 54 net.connectNodes(str(numIntersectionsX) + "/" + str(y + 1), 55 str(numIntersectionsX + 1) + "/" + str(y + 1), True, centralReservation) 56 return net