sumolib.scenario.scenarios.basic_corridor
1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 2# Copyright (C) 2012-2026 German Aerospace Center (DLR) and others. 3# This program and the accompanying materials are made available under the 4# terms of the Eclipse Public License 2.0 which is available at 5# https://www.eclipse.org/legal/epl-2.0/ 6# This Source Code may also be made available under the following Secondary 7# Licenses when the conditions for such availability set forth in the Eclipse 8# Public License 2.0 are satisfied: GNU General Public License, version 2 9# or later which is available at 10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 12 13# @file basic_corridor.py 14# @author Daniel Krajzewicz 15# @date 2014-09-01 16 17from __future__ import absolute_import 18from __future__ import print_function 19 20 21from . import fileNeedsRebuild, Scenario 22import os 23import sumolib.net.generator.corridor as netGenerator 24import sumolib.net.generator.demand as demandGenerator 25from sumolib.net.generator.network import Edge, Lane 26 27 28class Scenario_BasicCorridor(Scenario): 29 NAME = "BasicCorridor" 30 THIS_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), NAME) 31 TLS_FILE = os.path.join(THIS_DIR, "tls.add.xml") 32 NET_FILE = os.path.join(THIS_DIR, "corridor_%s.net.xml") 33 34 def __init__(self, xoff, withDefaultDemand=True): 35 Scenario.__init__(self, self.NAME) 36 self.NET_FILE = self.NET_FILE % xoff 37 self.netName = self.fullPath(self.NET_FILE) 38 self.demandName = self.fullPath("routes.rou.xml") 39 # network 40 if fileNeedsRebuild(self.netName, "netconvert"): 41 print("Network in '%s' needs to be rebuild" % self.netName) 42 defaultEdge = Edge(numLanes=1, maxSpeed=13.89) 43 defaultEdge.addSplit(100, 1) 44 defaultEdge.lanes = [Lane(dirs="rs"), Lane(dirs="l")] 45 netGen = netGenerator.corridor(5, None, defaultEdge) 46 xpos = xoff 47 for i in range(1, 6): 48 netGen._nodes["%s/0" % i].x = xpos 49 netGen._nodes["%s/1" % i].x = xpos 50 netGen._nodes["%s/2" % i].x = xpos 51 xpos = xpos + xoff 52 netGen._nodes["6/1"].x = xpos 53 # not nice, the network name should be given/returned 54 netGen.build(self.netName) 55 # demand 56 if withDefaultDemand: 57 print("Demand in '%s' needs to be rebuild" % self.demandName) 58 self.demand = demandGenerator.Demand() 59 # why isn't it possible to get a network and return all possible 60 # routes or whatever - to ease the process 61 self.demand.addStream(demandGenerator.Stream( 62 None, 0, 3600, 1000, "6/1_to_5/1", "1/1_to_0/1", {.2: "hdv", .8: "passenger"})) 63 if fileNeedsRebuild(self.demandName, "duarouter"): 64 self.demand.build(0, 3600, self.netName, self.demandName)
29class Scenario_BasicCorridor(Scenario): 30 NAME = "BasicCorridor" 31 THIS_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), NAME) 32 TLS_FILE = os.path.join(THIS_DIR, "tls.add.xml") 33 NET_FILE = os.path.join(THIS_DIR, "corridor_%s.net.xml") 34 35 def __init__(self, xoff, withDefaultDemand=True): 36 Scenario.__init__(self, self.NAME) 37 self.NET_FILE = self.NET_FILE % xoff 38 self.netName = self.fullPath(self.NET_FILE) 39 self.demandName = self.fullPath("routes.rou.xml") 40 # network 41 if fileNeedsRebuild(self.netName, "netconvert"): 42 print("Network in '%s' needs to be rebuild" % self.netName) 43 defaultEdge = Edge(numLanes=1, maxSpeed=13.89) 44 defaultEdge.addSplit(100, 1) 45 defaultEdge.lanes = [Lane(dirs="rs"), Lane(dirs="l")] 46 netGen = netGenerator.corridor(5, None, defaultEdge) 47 xpos = xoff 48 for i in range(1, 6): 49 netGen._nodes["%s/0" % i].x = xpos 50 netGen._nodes["%s/1" % i].x = xpos 51 netGen._nodes["%s/2" % i].x = xpos 52 xpos = xpos + xoff 53 netGen._nodes["6/1"].x = xpos 54 # not nice, the network name should be given/returned 55 netGen.build(self.netName) 56 # demand 57 if withDefaultDemand: 58 print("Demand in '%s' needs to be rebuild" % self.demandName) 59 self.demand = demandGenerator.Demand() 60 # why isn't it possible to get a network and return all possible 61 # routes or whatever - to ease the process 62 self.demand.addStream(demandGenerator.Stream( 63 None, 0, 3600, 1000, "6/1_to_5/1", "1/1_to_0/1", {.2: "hdv", .8: "passenger"})) 64 if fileNeedsRebuild(self.demandName, "duarouter"): 65 self.demand.build(0, 3600, self.netName, self.demandName)
Scenario_BasicCorridor(xoff, withDefaultDemand=True)
35 def __init__(self, xoff, withDefaultDemand=True): 36 Scenario.__init__(self, self.NAME) 37 self.NET_FILE = self.NET_FILE % xoff 38 self.netName = self.fullPath(self.NET_FILE) 39 self.demandName = self.fullPath("routes.rou.xml") 40 # network 41 if fileNeedsRebuild(self.netName, "netconvert"): 42 print("Network in '%s' needs to be rebuild" % self.netName) 43 defaultEdge = Edge(numLanes=1, maxSpeed=13.89) 44 defaultEdge.addSplit(100, 1) 45 defaultEdge.lanes = [Lane(dirs="rs"), Lane(dirs="l")] 46 netGen = netGenerator.corridor(5, None, defaultEdge) 47 xpos = xoff 48 for i in range(1, 6): 49 netGen._nodes["%s/0" % i].x = xpos 50 netGen._nodes["%s/1" % i].x = xpos 51 netGen._nodes["%s/2" % i].x = xpos 52 xpos = xpos + xoff 53 netGen._nodes["6/1"].x = xpos 54 # not nice, the network name should be given/returned 55 netGen.build(self.netName) 56 # demand 57 if withDefaultDemand: 58 print("Demand in '%s' needs to be rebuild" % self.demandName) 59 self.demand = demandGenerator.Demand() 60 # why isn't it possible to get a network and return all possible 61 # routes or whatever - to ease the process 62 self.demand.addStream(demandGenerator.Stream( 63 None, 0, 3600, 1000, "6/1_to_5/1", "1/1_to_0/1", {.2: "hdv", .8: "passenger"})) 64 if fileNeedsRebuild(self.demandName, "duarouter"): 65 self.demand.build(0, 3600, self.netName, self.demandName)