@@ -103,7 +103,7 @@ def getPrograms(self):
103
103
104
104
class Phase :
105
105
106
- def __init__ (self , duration , state , minDur = None , maxDur = None , next = tuple (), name = "" ):
106
+ def __init__ (self , duration , state , minDur = None , maxDur = None , next = tuple (), name = "" , earlyTarget = "" ):
107
107
"""
108
108
Constructs a traffic light phase
109
109
duration (float): the duration of the phase in seconds
@@ -112,6 +112,7 @@ def __init__(self, duration, state, minDur=None, maxDur=None, next=tuple(), name
112
112
maxDur (float): the maximum duration (ignored by static tls)
113
113
next (intList): possible succesor phase (optional)
114
114
name (string): the name of the phase
115
+ earlyTarget (string): early switching to phase with the given index(es)
115
116
"""
116
117
self .duration = duration
117
118
self .state = state
@@ -120,12 +121,14 @@ def __init__(self, duration, state, minDur=None, maxDur=None, next=tuple(), name
120
121
self .maxDur = maxDur if maxDur is not None else duration
121
122
self .next = next
122
123
self .name = name
124
+ self .earlyTarget = earlyTarget
123
125
124
126
def __repr__ (self ):
125
127
name = (", name='%s'" % self .name ) if self .name else ""
126
128
next = (", next='%s'" % str (self .next )) if self .next else ""
127
- return ("Phase(duration=%s, state='%s', minDur=%s, maxDur=%s%s%s)" %
128
- (self .duration , self .state , self .minDur , self .maxDur , name , next ))
129
+ earlyTarget = (", earlyTarget='%s'" % self .earlyTarget ) if self .earlyTarget else ""
130
+ return ("Phase(duration=%s, state='%s', minDur=%s, maxDur=%s%s%s%s)"
131
+ % (self .duration , self .state , self .minDur , self .maxDur , name , next , earlyTarget ))
129
132
130
133
131
134
class TLSProgram :
@@ -136,9 +139,13 @@ def __init__(self, id, offset, type):
136
139
self ._offset = offset
137
140
self ._phases = []
138
141
self ._params = {}
142
+ self ._conditions = {}
139
143
140
- def addPhase (self , state , duration , minDur = - 1 , maxDur = - 1 , next = None , name = "" ):
141
- self ._phases .append (Phase (duration , state , minDur , maxDur , next , name ))
144
+ def addPhase (self , state , duration , minDur = - 1 , maxDur = - 1 , next = None , name = "" , earlyTarget = "" ):
145
+ self ._phases .append (Phase (duration , state , minDur , maxDur , next , name , earlyTarget ))
146
+
147
+ def addCondition (self , id , value ):
148
+ self ._conditions [id ] = value
142
149
143
150
def toXML (self , tlsID ):
144
151
ret = ' <tlLogic id="%s" type="%s" programID="%s" offset="%s">\n ' % (
@@ -148,10 +155,13 @@ def toXML(self, tlsID):
148
155
maxDur = '' if p .maxDur < 0 else ' maxDur="%s"' % p .maxDur
149
156
name = '' if p .name == '' else ' name="%s"' % p .name
150
157
next = '' if len (p .next ) == 0 else ' next="%s"' % ' ' .join (map (str , p .next ))
151
- ret += ' <phase duration="%s" state="%s"%s%s%s%s/>\n ' % (
152
- p .duration , p .state , minDur , maxDur , name , next )
158
+ earlyTarget = '' if p .earlyTarget == '' else ' earlyTarget="%s"' % p .earlyTarget
159
+ ret += ' <phase duration="%s" state="%s"%s%s%s%s%s/>\n ' % (
160
+ p .duration , p .state , minDur , maxDur , name , next , earlyTarget )
153
161
for k , v in self ._params .items ():
154
162
ret += ' <param key="%s" value="%s"/>\n ' % (k , v )
163
+ for i , v in self ._conditions .items ():
164
+ ret += ' <condition id="%s" value="%s"/>\n ' % (i , v )
155
165
ret += ' </tlLogic>\n '
156
166
return ret
157
167
@@ -170,6 +180,17 @@ def getParam(self, key, default=None):
170
180
def getParams (self ):
171
181
return self ._params
172
182
183
+ def getStages (self ):
184
+ stages = dict ()
185
+ for idx , phase in enumerate (self .getPhases ()):
186
+ if phase not in stages .values ():
187
+ if 'G' in phase .state and 'y' not in phase .state and phase .name :
188
+ stages [idx ] = phase
189
+ return stages
190
+
191
+ def getOffset (self ):
192
+ return self ._offset
193
+
173
194
174
195
class EdgeType :
175
196
def __init__ (self , id , allow , disallow ):
0 commit comments