sumolib.net.generator.corridor

 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    corridor.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 corridor(numIntersections=10, defaultNode=None, defaultEdge=None, centralReservation=0, hdistance=500):
28    net = network.Net(defaultNode, defaultEdge)
29    net.addNode(network.Node("0/1", 0, 500, "priority"))
30    for i in range(0, numIntersections):
31        net.addNode(
32            network.Node(str(i + 1) + "/0", (i + 1) * hdistance, 0, "priority"))
33        net.addNode(
34            network.Node(str(i + 1) + "/1", (i + 1) * hdistance, 500, "traffic_light"))
35        net.addNode(
36            network.Node(str(i + 1) + "/2", (i + 1) * hdistance, 1000, "priority"))
37        net.connectNodes(
38            str(i) + "/1", str(i + 1) + "/1", True, centralReservation)
39        net.connectNodes(
40            str(i + 1) + "/0", str(i + 1) + "/1", True, centralReservation)
41        net.connectNodes(
42            str(i + 1) + "/1", str(i + 1) + "/2", True, centralReservation)
43    net.addNode(network.Node(str(numIntersections + 1) + "/1",
44                             (numIntersections + 1) * 500, 500, "priority"))
45    net.connectNodes(str(numIntersections) + "/1",
46                     str(numIntersections + 1) + "/1", True, centralReservation)
47    return net
48#  d = demand.Demand()
49#  d.addStream(demand.Stream("1/0_to_1/2", 10, "1/0 1/2"))
50#  d.build(3600)
51
52
53if __name__ == "__main__":
54    net = corridor()
55    net.build()
def corridor( numIntersections=10, defaultNode=None, defaultEdge=None, centralReservation=0, hdistance=500):
28def corridor(numIntersections=10, defaultNode=None, defaultEdge=None, centralReservation=0, hdistance=500):
29    net = network.Net(defaultNode, defaultEdge)
30    net.addNode(network.Node("0/1", 0, 500, "priority"))
31    for i in range(0, numIntersections):
32        net.addNode(
33            network.Node(str(i + 1) + "/0", (i + 1) * hdistance, 0, "priority"))
34        net.addNode(
35            network.Node(str(i + 1) + "/1", (i + 1) * hdistance, 500, "traffic_light"))
36        net.addNode(
37            network.Node(str(i + 1) + "/2", (i + 1) * hdistance, 1000, "priority"))
38        net.connectNodes(
39            str(i) + "/1", str(i + 1) + "/1", True, centralReservation)
40        net.connectNodes(
41            str(i + 1) + "/0", str(i + 1) + "/1", True, centralReservation)
42        net.connectNodes(
43            str(i + 1) + "/1", str(i + 1) + "/2", True, centralReservation)
44    net.addNode(network.Node(str(numIntersections + 1) + "/1",
45                             (numIntersections + 1) * 500, 500, "priority"))
46    net.connectNodes(str(numIntersections) + "/1",
47                     str(numIntersections + 1) + "/1", True, centralReservation)
48    return net