Skip to content

Commit 798122f

Browse files
committed
updated TLSProgram in sumolib
1 parent b1c9fe3 commit 798122f

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

tools/sumolib/net/__init__.py

+32-4
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,13 @@ def __init__(self, id, offset, type):
162162
self._offset = offset
163163
self._phases = []
164164
self._params = {}
165+
self._conditions = {}
165166

166-
def addPhase(self, state, duration, minDur=-1, maxDur=-1, next=None, name=""):
167-
self._phases.append(Phase(duration, state, minDur, maxDur, next, name))
167+
def addPhase(self, state, duration, minDur=-1, maxDur=-1, next=None, name="",earlyTarget=""):
168+
self._phases.append(Phase(duration, state, minDur, maxDur, next, name, earlyTarget))
169+
170+
def addCondition(self,id,value):
171+
self._conditions[id] = value
168172

169173
def toXML(self, tlsID):
170174
ret = ' <tlLogic id="%s" type="%s" programID="%s" offset="%s">\n' % (
@@ -174,10 +178,13 @@ def toXML(self, tlsID):
174178
maxDur = '' if p.maxDur < 0 else ' maxDur="%s"' % p.maxDur
175179
name = '' if p.name == '' else ' name="%s"' % p.name
176180
next = '' if len(p.next) == 0 else ' next="%s"' % ' '.join(map(str, p.next))
177-
ret += ' <phase duration="%s" state="%s"%s%s%s%s/>\n' % (
178-
p.duration, p.state, minDur, maxDur, name, next)
181+
earlyTarget = '' if p.earlyTarget == '' else ' earlyTarget="%s"' % p.earlyTarget
182+
ret += ' <phase duration="%s" state="%s"%s%s%s%s%s/>\n' % (
183+
p.duration, p.state, minDur, maxDur, name, next, earlyTarget)
179184
for k, v in self._params.items():
180185
ret += ' <param key="%s" value="%s"/>\n' % (k, v)
186+
for i, j in self._conditions.items():
187+
ret += f'<condition id="{i}" value="{j}" /> \n'
181188
ret += ' </tlLogic>\n'
182189
return ret
183190

@@ -196,6 +203,27 @@ def getParam(self, key, default=None):
196203
def getParams(self):
197204
return self._params
198205

206+
def getPhasesWithIndex(self):
207+
return{key:value for key,value in enumerate(self.getPhases())}
208+
209+
def numPhases(self):
210+
return len(self._phases)
211+
212+
def getPhaseByIndex(self,idx):
213+
ret = {key:value for key,value in enumerate(self.getPhases())}
214+
return ret[idx]
215+
216+
def getStages(self):
217+
stages = dict()
218+
for idx,phase in enumerate(self.getPhases()):
219+
if phase not in stages.values():
220+
if 'G' in list(phase.state) and 'y' not in list(phase.state) and len(phase.name)>0:
221+
stages[idx]= phase
222+
return stages
223+
224+
def getOffset(self):
225+
return self._offset
226+
199227

200228
class EdgeType:
201229
def __init__(self, id, allow, disallow):

0 commit comments

Comments
 (0)