sumolib.scenario.scenarios.basic_rilsanet2x2

  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_rilsanet2x2.py
 14# @author  Daniel Krajzewicz
 15# @date    2014-09-01
 16
 17
 18from __future__ import absolute_import
 19from __future__ import print_function
 20
 21
 22from . import fileNeedsRebuild, Scenario
 23import os
 24import shutil
 25import sumolib.net.generator.grid as netGenerator
 26import sumolib.net.generator.demand as demandGenerator
 27from sumolib.net.generator.network import Edge, Lane
 28
 29
 30flowsRiLSA1 = [
 31    ["nmp", [
 32        ["ms", 359, 9],
 33        ["me", 59, 9],
 34        ["mw", 64, 12]
 35    ]],
 36
 37    ["wmp", [
 38        ["me", 508, 10],
 39        ["mn", 80, 14],
 40        ["ms", 130, 2]
 41    ]],
 42
 43    ["emp", [
 44        ["mw", 571, 10],
 45        ["mn", 57, 9],
 46        ["ms", 47, 3]
 47    ]],
 48
 49    ["smp", [
 50        ["mn", 354, 2],
 51        ["me", 49, 2],
 52        ["mw", 92, 2]
 53    ]]
 54
 55]
 56
 57
 58class Scenario_BasicRiLSANet2x2(Scenario):
 59    NAME = "BasicRiLSANet2x2"
 60    THIS_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), NAME)
 61    TLS_FILE = "tls.add.xml"
 62    NET_FILE = "network.net.xml"
 63
 64    def __init__(self, name, params, withDefaultDemand=True):
 65        Scenario.__init__(self, self.THIS_DIR)
 66        self.params = params
 67        self.demandName = self.fullPath("routes.rou.xml")
 68        self.netName = self.fullPath(self.NET_FILE)
 69        # network
 70        if fileNeedsRebuild(self.fullPath(self.NET_FILE), "netconvert"):
 71            print("Network in '%s' needs to be rebuild" %
 72                  self.fullPath(self.NET_FILE))
 73            # , Lane(dirs="l", disallowed="pedestrian")]
 74            lanes = [Lane(dirs="s", allowed="pedestrian"), Lane(
 75                dirs="rs", disallowed="pedestrian")]
 76            defaultEdge = Edge(numLanes=2, maxSpeed=13.89, lanes=lanes)
 77            defaultEdge.addSplit(100, 0, 1)
 78            defaultEdge.lanes[-1].dirs = "l"
 79            netGen = netGenerator.grid(4, 4, None, defaultEdge)
 80            for n in netGen._nodes:
 81                nid = n.split("/")
 82                nid[0] = int(nid[0])
 83                nid[1] = int(nid[1])
 84                if nid[0] > 0 and nid[0] < 5 and nid[1] > 0 and nid[1] < 5:
 85                    netGen._nodes[n].addCrossing(
 86                        "%s/%s_to_%s.-100" % (nid[0] - 1, nid[1], n), "%s_to_%s/%s" % (n, nid[0] - 1, nid[1]))
 87                    netGen._nodes[n].addCrossing(
 88                        "%s/%s_to_%s.-100" % (nid[0] + 1, nid[1], n), "%s_to_%s/%s" % (n, nid[0] + 1, nid[1]))
 89                    netGen._nodes[n].addCrossing(
 90                        "%s/%s_to_%s.-100" % (nid[0], nid[1] - 1, n), "%s_to_%s/%s" % (n, nid[0], nid[1] - 1))
 91                    netGen._nodes[n].addCrossing(
 92                        "%s/%s_to_%s.-100" % (nid[0], nid[1] + 1, n), "%s_to_%s/%s" % (n, nid[0], nid[1] + 1))
 93            # not nice, the network name should be given/returned
 94            netGen.build(self.fullPath(self.NET_FILE))
 95        if True:
 96            fdow = open(self.fullPath(self.TLS_FILE), "w")
 97            fdow.write('<additional>\n\n')
 98            for y in range(1, 5):
 99                for x in range(1, 5):
100                    eedge = "%s/%s_to_%s/%s.-100" % (x - 1, y, x, y)
101                    wedge = "%s/%s_to_%s/%s.-100" % (x + 1, y, x, y)
102                    nedge = "%s/%s_to_%s/%s.-100" % (x, y + 1, x, y)
103                    sedge = "%s/%s_to_%s/%s.-100" % (x, y - 1, x, y)
104                    fdow.write(
105                        '   <tlLogic id="%s/%s" type="actuated" programID="adapted" offset="0">\n' % (x, y))
106                    fdow.write(
107                        ('      <phase duration="31" state="rrrrrGGgrrrrrGGgGrGr" minDur="10" maxDur="50" ' +
108                         'type="target;decisional" targetLanes="%s_1 %s_2 %s_1 %s_2"/>\n') % (
109                            eedge, eedge, wedge, wedge))
110                    fdow.write(
111                        '      <phase duration="4"  state="rrrrryygrrrrryygrrrr" type="transient"/>\n')
112                    fdow.write(
113                        ('      <phase duration="6"  state="rrrrrrrGrrrrrrrGrrrr" minDur="2" maxDur="20" ' +
114                         'type="decisional" targetLanes="%s_2 %s_2"/>\n') % (eedge, wedge))
115                    fdow.write(
116                        '      <phase duration="4"  state="rrrrrrryrrrrrrryrrrr" type="transient"/>\n')
117                    fdow.write(
118                        '      <phase duration="4"  state="rrrrrrrrrrrrrrrrrrrr" type="transient;commit"/>\n')
119                    fdow.write(
120                        ('      <phase duration="31" state="rGGgrrrrrGGgrrrrrGrG" minDur="10" maxDur="50" ' +
121                         'type="target;decisional" targetLanes="%s_1 %s_2 %s_1 %s_2"/>\n') % (
122                            sedge, sedge, nedge, nedge))
123                    fdow.write(
124                        '      <phase duration="4"  state="ryygrrrrryygrrrrrrrr" type="transient"/>\n')
125                    fdow.write(
126                        ('      <phase duration="6"  state="rrrGrrrrrrrGrrrrrrrr" minDur="2" maxDur="20" ' +
127                         'type="decisional" targetLanes="%s_2 %s_2"/>\n') % (sedge, nedge))
128                    fdow.write(
129                        '      <phase duration="4"  state="rrryrrrrrrryrrrrrrrr" type="transient"/>\n')
130                    fdow.write(
131                        '      <phase duration="4"  state="rrrrrrrrrrrrrrrrrrrr" type="transient;commit"/>\n')
132                    fdow.write('   </tlLogic>\n\n')
133            fdow.write('</additional>\n')
134        # demand
135        if withDefaultDemand:
136            self.demand = demandGenerator.Demand()
137            for f in flowsRiLSA1:
138                for oe, rel in enumerate(f[1]):
139                    flow = int(rel[1] * .75)
140                    prob = rel[2] / 100.
141                    iprob = 1. - prob
142                    pkwEprob = iprob * self.params["equipment-rate"]
143                    pkwNprob = iprob - pkwEprob
144                    lkwEprob = prob * self.params["equipment-rate"]
145                    lkwNprob = prob - lkwEprob
146                    for ie in range(1, 5):  # over input
147                        via = []
148                        if f[0] == "nmp":
149                            iedge = "%s/5_to_%s/4" % (ie, ie)
150                            for ve in range(5, 0, -1):
151                                via.append("%s/%s_to_%s/%s" %
152                                           (ie, ve, ie, ve - 1))
153                        if f[0] == "smp":
154                            iedge = "%s/0_to_%s/1" % (ie, ie)
155                            for ve in range(0, 5, 1):
156                                via.append("%s/%s_to_%s/%s" %
157                                           (ie, ve, ie, ve + 1))
158                        if f[0] == "wmp":
159                            iedge = "0/%s_to_1/%s" % (ie, ie)
160                            for ve in range(0, 5, 1):
161                                via.append("%s/%s_to_%s/%s" %
162                                           (ve, ie, ve + 1, ie))
163                        if f[0] == "emp":
164                            iedge = "5/%s_to_4/%s" % (ie, ie)
165                            for ve in range(5, 0, -1):
166                                via.append("%s/%s_to_%s/%s" %
167                                           (ve, ie, ve - 1, ie))
168                        if oe == 0:
169                            # if ie<2 or ie>3: continue # discard vehicles not
170                            # passing the center
171                            if rel[0] == "mn":
172                                oedge = "%s/4_to_%s/5.-100" % (ie, ie)
173                            if rel[0] == "ms":
174                                oedge = "%s/1_to_%s/0.-100" % (ie, ie)
175                            if rel[0] == "mw":
176                                oedge = "1/%s_to_0/%s.-100" % (ie, ie)
177                            if rel[0] == "me":
178                                oedge = "4/%s_to_5/%s.-100" % (ie, ie)
179                            self.demand.addStream(demandGenerator.Stream(iedge + "__" + oedge, 0, 3600, flow, iedge,
180                                                                         oedge,
181                                                                         {"passenger": pkwEprob,
182                                                                          "COLOMBO_undetectable_passenger": pkwNprob,
183                                                                          "hdv": lkwEprob,
184                                                                          "COLOMBO_undetectable_hdv": lkwNprob}))
185                            continue
186                        for oee in range(1, 4):
187                            if rel[0] == "mn":
188                                oedge = "%s/4_to_%s/5.-100" % (oee, oee)
189                            if rel[0] == "ms":
190                                oedge = "%s/1_to_%s/0.-100" % (oee, oee)
191                            if rel[0] == "mw":
192                                oedge = "1/%s_to_0/%s.-100" % (oee, oee)
193                            if rel[0] == "me":
194                                oedge = "4/%s_to_5/%s.-100" % (oee, oee)
195                            # if (ie<2 or ie>3) and (oee<2 or oee>3): continue
196                            # # discard vehicles not passing the center
197                            self.demand.addStream(demandGenerator.Stream(iedge + "__" + oedge, 0, 3600, int(flow / 3.),
198                                                                         iedge, oedge,
199                                                                         {"passenger": pkwEprob,
200                                                                          "COLOMBO_undetectable_passenger": pkwNprob,
201                                                                          "hdv": lkwEprob,
202                                                                          "COLOMBO_undetectable_hdv": lkwNprob}))
203            if fileNeedsRebuild(self.demandName, "duarouter"):
204                self.demand.build(0, 86400, self.netName, self.demandName)
205
206        self.netName = self.fullPath(self.NET_FILE)
207        shutil.copy(
208            self.fullPath(self.NET_FILE), self.sandboxPath(self.NET_FILE))
209        shutil.copy(
210            self.fullPath(self.TLS_FILE), self.sandboxPath(self.TLS_FILE))
211        print("Huah")
flowsRiLSA1 = [['nmp', [['ms', 359, 9], ['me', 59, 9], ['mw', 64, 12]]], ['wmp', [['me', 508, 10], ['mn', 80, 14], ['ms', 130, 2]]], ['emp', [['mw', 571, 10], ['mn', 57, 9], ['ms', 47, 3]]], ['smp', [['mn', 354, 2], ['me', 49, 2], ['mw', 92, 2]]]]
class Scenario_BasicRiLSANet2x2(sumolib.scenario.scenarios.Scenario):
 59class Scenario_BasicRiLSANet2x2(Scenario):
 60    NAME = "BasicRiLSANet2x2"
 61    THIS_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), NAME)
 62    TLS_FILE = "tls.add.xml"
 63    NET_FILE = "network.net.xml"
 64
 65    def __init__(self, name, params, withDefaultDemand=True):
 66        Scenario.__init__(self, self.THIS_DIR)
 67        self.params = params
 68        self.demandName = self.fullPath("routes.rou.xml")
 69        self.netName = self.fullPath(self.NET_FILE)
 70        # network
 71        if fileNeedsRebuild(self.fullPath(self.NET_FILE), "netconvert"):
 72            print("Network in '%s' needs to be rebuild" %
 73                  self.fullPath(self.NET_FILE))
 74            # , Lane(dirs="l", disallowed="pedestrian")]
 75            lanes = [Lane(dirs="s", allowed="pedestrian"), Lane(
 76                dirs="rs", disallowed="pedestrian")]
 77            defaultEdge = Edge(numLanes=2, maxSpeed=13.89, lanes=lanes)
 78            defaultEdge.addSplit(100, 0, 1)
 79            defaultEdge.lanes[-1].dirs = "l"
 80            netGen = netGenerator.grid(4, 4, None, defaultEdge)
 81            for n in netGen._nodes:
 82                nid = n.split("/")
 83                nid[0] = int(nid[0])
 84                nid[1] = int(nid[1])
 85                if nid[0] > 0 and nid[0] < 5 and nid[1] > 0 and nid[1] < 5:
 86                    netGen._nodes[n].addCrossing(
 87                        "%s/%s_to_%s.-100" % (nid[0] - 1, nid[1], n), "%s_to_%s/%s" % (n, nid[0] - 1, nid[1]))
 88                    netGen._nodes[n].addCrossing(
 89                        "%s/%s_to_%s.-100" % (nid[0] + 1, nid[1], n), "%s_to_%s/%s" % (n, nid[0] + 1, nid[1]))
 90                    netGen._nodes[n].addCrossing(
 91                        "%s/%s_to_%s.-100" % (nid[0], nid[1] - 1, n), "%s_to_%s/%s" % (n, nid[0], nid[1] - 1))
 92                    netGen._nodes[n].addCrossing(
 93                        "%s/%s_to_%s.-100" % (nid[0], nid[1] + 1, n), "%s_to_%s/%s" % (n, nid[0], nid[1] + 1))
 94            # not nice, the network name should be given/returned
 95            netGen.build(self.fullPath(self.NET_FILE))
 96        if True:
 97            fdow = open(self.fullPath(self.TLS_FILE), "w")
 98            fdow.write('<additional>\n\n')
 99            for y in range(1, 5):
100                for x in range(1, 5):
101                    eedge = "%s/%s_to_%s/%s.-100" % (x - 1, y, x, y)
102                    wedge = "%s/%s_to_%s/%s.-100" % (x + 1, y, x, y)
103                    nedge = "%s/%s_to_%s/%s.-100" % (x, y + 1, x, y)
104                    sedge = "%s/%s_to_%s/%s.-100" % (x, y - 1, x, y)
105                    fdow.write(
106                        '   <tlLogic id="%s/%s" type="actuated" programID="adapted" offset="0">\n' % (x, y))
107                    fdow.write(
108                        ('      <phase duration="31" state="rrrrrGGgrrrrrGGgGrGr" minDur="10" maxDur="50" ' +
109                         'type="target;decisional" targetLanes="%s_1 %s_2 %s_1 %s_2"/>\n') % (
110                            eedge, eedge, wedge, wedge))
111                    fdow.write(
112                        '      <phase duration="4"  state="rrrrryygrrrrryygrrrr" type="transient"/>\n')
113                    fdow.write(
114                        ('      <phase duration="6"  state="rrrrrrrGrrrrrrrGrrrr" minDur="2" maxDur="20" ' +
115                         'type="decisional" targetLanes="%s_2 %s_2"/>\n') % (eedge, wedge))
116                    fdow.write(
117                        '      <phase duration="4"  state="rrrrrrryrrrrrrryrrrr" type="transient"/>\n')
118                    fdow.write(
119                        '      <phase duration="4"  state="rrrrrrrrrrrrrrrrrrrr" type="transient;commit"/>\n')
120                    fdow.write(
121                        ('      <phase duration="31" state="rGGgrrrrrGGgrrrrrGrG" minDur="10" maxDur="50" ' +
122                         'type="target;decisional" targetLanes="%s_1 %s_2 %s_1 %s_2"/>\n') % (
123                            sedge, sedge, nedge, nedge))
124                    fdow.write(
125                        '      <phase duration="4"  state="ryygrrrrryygrrrrrrrr" type="transient"/>\n')
126                    fdow.write(
127                        ('      <phase duration="6"  state="rrrGrrrrrrrGrrrrrrrr" minDur="2" maxDur="20" ' +
128                         'type="decisional" targetLanes="%s_2 %s_2"/>\n') % (sedge, nedge))
129                    fdow.write(
130                        '      <phase duration="4"  state="rrryrrrrrrryrrrrrrrr" type="transient"/>\n')
131                    fdow.write(
132                        '      <phase duration="4"  state="rrrrrrrrrrrrrrrrrrrr" type="transient;commit"/>\n')
133                    fdow.write('   </tlLogic>\n\n')
134            fdow.write('</additional>\n')
135        # demand
136        if withDefaultDemand:
137            self.demand = demandGenerator.Demand()
138            for f in flowsRiLSA1:
139                for oe, rel in enumerate(f[1]):
140                    flow = int(rel[1] * .75)
141                    prob = rel[2] / 100.
142                    iprob = 1. - prob
143                    pkwEprob = iprob * self.params["equipment-rate"]
144                    pkwNprob = iprob - pkwEprob
145                    lkwEprob = prob * self.params["equipment-rate"]
146                    lkwNprob = prob - lkwEprob
147                    for ie in range(1, 5):  # over input
148                        via = []
149                        if f[0] == "nmp":
150                            iedge = "%s/5_to_%s/4" % (ie, ie)
151                            for ve in range(5, 0, -1):
152                                via.append("%s/%s_to_%s/%s" %
153                                           (ie, ve, ie, ve - 1))
154                        if f[0] == "smp":
155                            iedge = "%s/0_to_%s/1" % (ie, ie)
156                            for ve in range(0, 5, 1):
157                                via.append("%s/%s_to_%s/%s" %
158                                           (ie, ve, ie, ve + 1))
159                        if f[0] == "wmp":
160                            iedge = "0/%s_to_1/%s" % (ie, ie)
161                            for ve in range(0, 5, 1):
162                                via.append("%s/%s_to_%s/%s" %
163                                           (ve, ie, ve + 1, ie))
164                        if f[0] == "emp":
165                            iedge = "5/%s_to_4/%s" % (ie, ie)
166                            for ve in range(5, 0, -1):
167                                via.append("%s/%s_to_%s/%s" %
168                                           (ve, ie, ve - 1, ie))
169                        if oe == 0:
170                            # if ie<2 or ie>3: continue # discard vehicles not
171                            # passing the center
172                            if rel[0] == "mn":
173                                oedge = "%s/4_to_%s/5.-100" % (ie, ie)
174                            if rel[0] == "ms":
175                                oedge = "%s/1_to_%s/0.-100" % (ie, ie)
176                            if rel[0] == "mw":
177                                oedge = "1/%s_to_0/%s.-100" % (ie, ie)
178                            if rel[0] == "me":
179                                oedge = "4/%s_to_5/%s.-100" % (ie, ie)
180                            self.demand.addStream(demandGenerator.Stream(iedge + "__" + oedge, 0, 3600, flow, iedge,
181                                                                         oedge,
182                                                                         {"passenger": pkwEprob,
183                                                                          "COLOMBO_undetectable_passenger": pkwNprob,
184                                                                          "hdv": lkwEprob,
185                                                                          "COLOMBO_undetectable_hdv": lkwNprob}))
186                            continue
187                        for oee in range(1, 4):
188                            if rel[0] == "mn":
189                                oedge = "%s/4_to_%s/5.-100" % (oee, oee)
190                            if rel[0] == "ms":
191                                oedge = "%s/1_to_%s/0.-100" % (oee, oee)
192                            if rel[0] == "mw":
193                                oedge = "1/%s_to_0/%s.-100" % (oee, oee)
194                            if rel[0] == "me":
195                                oedge = "4/%s_to_5/%s.-100" % (oee, oee)
196                            # if (ie<2 or ie>3) and (oee<2 or oee>3): continue
197                            # # discard vehicles not passing the center
198                            self.demand.addStream(demandGenerator.Stream(iedge + "__" + oedge, 0, 3600, int(flow / 3.),
199                                                                         iedge, oedge,
200                                                                         {"passenger": pkwEprob,
201                                                                          "COLOMBO_undetectable_passenger": pkwNprob,
202                                                                          "hdv": lkwEprob,
203                                                                          "COLOMBO_undetectable_hdv": lkwNprob}))
204            if fileNeedsRebuild(self.demandName, "duarouter"):
205                self.demand.build(0, 86400, self.netName, self.demandName)
206
207        self.netName = self.fullPath(self.NET_FILE)
208        shutil.copy(
209            self.fullPath(self.NET_FILE), self.sandboxPath(self.NET_FILE))
210        shutil.copy(
211            self.fullPath(self.TLS_FILE), self.sandboxPath(self.TLS_FILE))
212        print("Huah")
Scenario_BasicRiLSANet2x2(name, params, withDefaultDemand=True)
 65    def __init__(self, name, params, withDefaultDemand=True):
 66        Scenario.__init__(self, self.THIS_DIR)
 67        self.params = params
 68        self.demandName = self.fullPath("routes.rou.xml")
 69        self.netName = self.fullPath(self.NET_FILE)
 70        # network
 71        if fileNeedsRebuild(self.fullPath(self.NET_FILE), "netconvert"):
 72            print("Network in '%s' needs to be rebuild" %
 73                  self.fullPath(self.NET_FILE))
 74            # , Lane(dirs="l", disallowed="pedestrian")]
 75            lanes = [Lane(dirs="s", allowed="pedestrian"), Lane(
 76                dirs="rs", disallowed="pedestrian")]
 77            defaultEdge = Edge(numLanes=2, maxSpeed=13.89, lanes=lanes)
 78            defaultEdge.addSplit(100, 0, 1)
 79            defaultEdge.lanes[-1].dirs = "l"
 80            netGen = netGenerator.grid(4, 4, None, defaultEdge)
 81            for n in netGen._nodes:
 82                nid = n.split("/")
 83                nid[0] = int(nid[0])
 84                nid[1] = int(nid[1])
 85                if nid[0] > 0 and nid[0] < 5 and nid[1] > 0 and nid[1] < 5:
 86                    netGen._nodes[n].addCrossing(
 87                        "%s/%s_to_%s.-100" % (nid[0] - 1, nid[1], n), "%s_to_%s/%s" % (n, nid[0] - 1, nid[1]))
 88                    netGen._nodes[n].addCrossing(
 89                        "%s/%s_to_%s.-100" % (nid[0] + 1, nid[1], n), "%s_to_%s/%s" % (n, nid[0] + 1, nid[1]))
 90                    netGen._nodes[n].addCrossing(
 91                        "%s/%s_to_%s.-100" % (nid[0], nid[1] - 1, n), "%s_to_%s/%s" % (n, nid[0], nid[1] - 1))
 92                    netGen._nodes[n].addCrossing(
 93                        "%s/%s_to_%s.-100" % (nid[0], nid[1] + 1, n), "%s_to_%s/%s" % (n, nid[0], nid[1] + 1))
 94            # not nice, the network name should be given/returned
 95            netGen.build(self.fullPath(self.NET_FILE))
 96        if True:
 97            fdow = open(self.fullPath(self.TLS_FILE), "w")
 98            fdow.write('<additional>\n\n')
 99            for y in range(1, 5):
100                for x in range(1, 5):
101                    eedge = "%s/%s_to_%s/%s.-100" % (x - 1, y, x, y)
102                    wedge = "%s/%s_to_%s/%s.-100" % (x + 1, y, x, y)
103                    nedge = "%s/%s_to_%s/%s.-100" % (x, y + 1, x, y)
104                    sedge = "%s/%s_to_%s/%s.-100" % (x, y - 1, x, y)
105                    fdow.write(
106                        '   <tlLogic id="%s/%s" type="actuated" programID="adapted" offset="0">\n' % (x, y))
107                    fdow.write(
108                        ('      <phase duration="31" state="rrrrrGGgrrrrrGGgGrGr" minDur="10" maxDur="50" ' +
109                         'type="target;decisional" targetLanes="%s_1 %s_2 %s_1 %s_2"/>\n') % (
110                            eedge, eedge, wedge, wedge))
111                    fdow.write(
112                        '      <phase duration="4"  state="rrrrryygrrrrryygrrrr" type="transient"/>\n')
113                    fdow.write(
114                        ('      <phase duration="6"  state="rrrrrrrGrrrrrrrGrrrr" minDur="2" maxDur="20" ' +
115                         'type="decisional" targetLanes="%s_2 %s_2"/>\n') % (eedge, wedge))
116                    fdow.write(
117                        '      <phase duration="4"  state="rrrrrrryrrrrrrryrrrr" type="transient"/>\n')
118                    fdow.write(
119                        '      <phase duration="4"  state="rrrrrrrrrrrrrrrrrrrr" type="transient;commit"/>\n')
120                    fdow.write(
121                        ('      <phase duration="31" state="rGGgrrrrrGGgrrrrrGrG" minDur="10" maxDur="50" ' +
122                         'type="target;decisional" targetLanes="%s_1 %s_2 %s_1 %s_2"/>\n') % (
123                            sedge, sedge, nedge, nedge))
124                    fdow.write(
125                        '      <phase duration="4"  state="ryygrrrrryygrrrrrrrr" type="transient"/>\n')
126                    fdow.write(
127                        ('      <phase duration="6"  state="rrrGrrrrrrrGrrrrrrrr" minDur="2" maxDur="20" ' +
128                         'type="decisional" targetLanes="%s_2 %s_2"/>\n') % (sedge, nedge))
129                    fdow.write(
130                        '      <phase duration="4"  state="rrryrrrrrrryrrrrrrrr" type="transient"/>\n')
131                    fdow.write(
132                        '      <phase duration="4"  state="rrrrrrrrrrrrrrrrrrrr" type="transient;commit"/>\n')
133                    fdow.write('   </tlLogic>\n\n')
134            fdow.write('</additional>\n')
135        # demand
136        if withDefaultDemand:
137            self.demand = demandGenerator.Demand()
138            for f in flowsRiLSA1:
139                for oe, rel in enumerate(f[1]):
140                    flow = int(rel[1] * .75)
141                    prob = rel[2] / 100.
142                    iprob = 1. - prob
143                    pkwEprob = iprob * self.params["equipment-rate"]
144                    pkwNprob = iprob - pkwEprob
145                    lkwEprob = prob * self.params["equipment-rate"]
146                    lkwNprob = prob - lkwEprob
147                    for ie in range(1, 5):  # over input
148                        via = []
149                        if f[0] == "nmp":
150                            iedge = "%s/5_to_%s/4" % (ie, ie)
151                            for ve in range(5, 0, -1):
152                                via.append("%s/%s_to_%s/%s" %
153                                           (ie, ve, ie, ve - 1))
154                        if f[0] == "smp":
155                            iedge = "%s/0_to_%s/1" % (ie, ie)
156                            for ve in range(0, 5, 1):
157                                via.append("%s/%s_to_%s/%s" %
158                                           (ie, ve, ie, ve + 1))
159                        if f[0] == "wmp":
160                            iedge = "0/%s_to_1/%s" % (ie, ie)
161                            for ve in range(0, 5, 1):
162                                via.append("%s/%s_to_%s/%s" %
163                                           (ve, ie, ve + 1, ie))
164                        if f[0] == "emp":
165                            iedge = "5/%s_to_4/%s" % (ie, ie)
166                            for ve in range(5, 0, -1):
167                                via.append("%s/%s_to_%s/%s" %
168                                           (ve, ie, ve - 1, ie))
169                        if oe == 0:
170                            # if ie<2 or ie>3: continue # discard vehicles not
171                            # passing the center
172                            if rel[0] == "mn":
173                                oedge = "%s/4_to_%s/5.-100" % (ie, ie)
174                            if rel[0] == "ms":
175                                oedge = "%s/1_to_%s/0.-100" % (ie, ie)
176                            if rel[0] == "mw":
177                                oedge = "1/%s_to_0/%s.-100" % (ie, ie)
178                            if rel[0] == "me":
179                                oedge = "4/%s_to_5/%s.-100" % (ie, ie)
180                            self.demand.addStream(demandGenerator.Stream(iedge + "__" + oedge, 0, 3600, flow, iedge,
181                                                                         oedge,
182                                                                         {"passenger": pkwEprob,
183                                                                          "COLOMBO_undetectable_passenger": pkwNprob,
184                                                                          "hdv": lkwEprob,
185                                                                          "COLOMBO_undetectable_hdv": lkwNprob}))
186                            continue
187                        for oee in range(1, 4):
188                            if rel[0] == "mn":
189                                oedge = "%s/4_to_%s/5.-100" % (oee, oee)
190                            if rel[0] == "ms":
191                                oedge = "%s/1_to_%s/0.-100" % (oee, oee)
192                            if rel[0] == "mw":
193                                oedge = "1/%s_to_0/%s.-100" % (oee, oee)
194                            if rel[0] == "me":
195                                oedge = "4/%s_to_5/%s.-100" % (oee, oee)
196                            # if (ie<2 or ie>3) and (oee<2 or oee>3): continue
197                            # # discard vehicles not passing the center
198                            self.demand.addStream(demandGenerator.Stream(iedge + "__" + oedge, 0, 3600, int(flow / 3.),
199                                                                         iedge, oedge,
200                                                                         {"passenger": pkwEprob,
201                                                                          "COLOMBO_undetectable_passenger": pkwNprob,
202                                                                          "hdv": lkwEprob,
203                                                                          "COLOMBO_undetectable_hdv": lkwNprob}))
204            if fileNeedsRebuild(self.demandName, "duarouter"):
205                self.demand.build(0, 86400, self.netName, self.demandName)
206
207        self.netName = self.fullPath(self.NET_FILE)
208        shutil.copy(
209            self.fullPath(self.NET_FILE), self.sandboxPath(self.NET_FILE))
210        shutil.copy(
211            self.fullPath(self.TLS_FILE), self.sandboxPath(self.TLS_FILE))
212        print("Huah")
NAME = 'BasicRiLSANet2x2'
THIS_DIR = '/home/delphi/gcc/sumo/tools/sumolib/scenario/scenarios/BasicRiLSANet2x2'
TLS_FILE = 'tls.add.xml'
NET_FILE = 'network.net.xml'
params
demandName
netName