99
1010# constants
1111DEFAULT_ACTOR_EXECUTION_TIME = 1.0
12+ EXECUTION_TIME_SPEC_KEY = 'executionTime'
13+ CONS_RATE_SPEC_KEY = 'consRate'
14+ PROD_RATE_SPEC_KEY = 'prodRate'
15+ INITIAL_TOKENS_SPEC_KEY = 'initialTokens'
1216
1317def _splitMatrix (M , n ):
1418 A = []
@@ -78,14 +82,14 @@ def inputSignals(self):
7882
7983 def consumptionRate (self , ch ):
8084 if ch in self ._channelSpecs :
81- if 'consRate' in self ._channelSpecs [ch ]:
82- return self ._channelSpecs [ch ]['consRate' ]
85+ if CONS_RATE_SPEC_KEY in self ._channelSpecs [ch ]:
86+ return self ._channelSpecs [ch ][CONS_RATE_SPEC_KEY ]
8387 return 1
8488
8589 def productionRate (self , ch ):
8690 if ch in self ._channelSpecs :
87- if 'prodRate' in self ._channelSpecs [ch ]:
88- return self ._channelSpecs [ch ]['prodRate' ]
91+ if PROD_RATE_SPEC_KEY in self ._channelSpecs [ch ]:
92+ return self ._channelSpecs [ch ][PROD_RATE_SPEC_KEY ]
8993 return 1
9094
9195 def repetitions (self , actor ):
@@ -149,17 +153,18 @@ def addInputPort(self, i):
149153 self ._repetitionVector = None
150154 # input ports should be in actors
151155 if not i in self ._actors :
152- self .addActor (i , dict () )
156+ self .addActor (i , { EXECUTION_TIME_SPEC_KEY : 0.0 } )
153157 self ._inputs .append (i )
154158
155159 def addOutputPort (self , o ):
156160 self ._repetitionVector = None
157161 # output ports should be in actors
158162 if not o in self ._actors :
159- self .addActor (o , dict () )
163+ self .addActor (o , { EXECUTION_TIME_SPEC_KEY : 0.0 } )
160164 self ._outputs .append (o )
161165
162166 def addInputSignal (self , n , s ):
167+ self ._repetitionVector = None
163168 self ._inputSignals [n ] = s
164169
165170 def _newChannelName (self ):
@@ -170,15 +175,15 @@ def _newChannelName(self):
170175 return fname (k )
171176
172177 def executionTimeOfActor (self , a ):
173- if not 'executionTime' in self ._actorSpecs [a ]:
178+ if not EXECUTION_TIME_SPEC_KEY in self ._actorSpecs [a ]:
174179 return DEFAULT_ACTOR_EXECUTION_TIME
175- return self ._actorSpecs [a ]['executionTime' ]
180+ return self ._actorSpecs [a ][EXECUTION_TIME_SPEC_KEY ]
176181
177182
178183 def numberOfInitialTokensOfChannel (self , ch ):
179- if not 'initialTokens' in self ._channelSpecs [ch ]:
184+ if not INITIAL_TOKENS_SPEC_KEY in self ._channelSpecs [ch ]:
180185 return 0
181- return self ._channelSpecs [ch ]['initialTokens' ]
186+ return self ._channelSpecs [ch ][INITIAL_TOKENS_SPEC_KEY ]
182187
183188 def numberOfInitialTokens (self ):
184189 return reduce (lambda sum , ch : sum + self .numberOfInitialTokensOfChannel (ch ), self ._channels , 0 )
@@ -508,11 +513,11 @@ def generalizedLatency(self, mu):
508513 def isSingleRate (self ):
509514 for ch in self ._channels :
510515 if ch in self ._channelSpecs :
511- if 'prodRate' in self ._channelSpecs [ch ]:
512- if self ._channelSpecs [ch ]['prodRate' ] > 1 :
516+ if PROD_RATE_SPEC_KEY in self ._channelSpecs [ch ]:
517+ if self ._channelSpecs [ch ][PROD_RATE_SPEC_KEY ] > 1 :
513518 return False
514- if 'consRate' in self ._channelSpecs [ch ]:
515- if self ._channelSpecs [ch ]['consRate' ] > 1 :
519+ if CONS_RATE_SPEC_KEY in self ._channelSpecs [ch ]:
520+ if self ._channelSpecs [ch ][CONS_RATE_SPEC_KEY ] > 1 :
516521 return False
517522 return True
518523
@@ -530,7 +535,7 @@ def _addChannel(res, pa, ca, it):
530535 return
531536 specs = dict ()
532537 if it > 0 :
533- specs ['initialTokens' ] = it
538+ specs [INITIAL_TOKENS_SPEC_KEY ] = it
534539 res .addChannel (pa , ca , specs )
535540
536541
@@ -640,19 +645,19 @@ def _actorSpecs(a, actorsWithSpec):
640645 actorsWithSpec .add (a )
641646 if not a in self ._actorSpecs :
642647 return ''
643- if not 'executionTime' in self ._actorSpecs [a ]:
648+ if not EXECUTION_TIME_SPEC_KEY in self ._actorSpecs [a ]:
644649 return ''
645- return '[{}]' .format (self ._actorSpecs [a ]['executionTime' ])
650+ return '[{}]' .format (self ._actorSpecs [a ][EXECUTION_TIME_SPEC_KEY ])
646651
647652 def _channelSpecs (ch ):
648653 specs = list ()
649654 if ch in self ._channelSpecs :
650- if 'consRate' in self ._channelSpecs [ch ]:
651- specs .append (' consumption rate: {} ' .format (self ._channelSpecs [ch ]['consRate' ]))
652- if 'prodRate' in self ._channelSpecs [ch ]:
653- specs .append (' production rate: {} ' .format (self ._channelSpecs [ch ]['prodRate' ]))
654- if 'initialTokens' in self ._channelSpecs [ch ]:
655- specs .append (' initial tokens: {} ' .format (self ._channelSpecs [ch ]['initialTokens' ]))
655+ if CONS_RATE_SPEC_KEY in self ._channelSpecs [ch ]:
656+ specs .append (' consumption rate: {} ' .format (self ._channelSpecs [ch ][CONS_RATE_SPEC_KEY ]))
657+ if PROD_RATE_SPEC_KEY in self ._channelSpecs [ch ]:
658+ specs .append (' production rate: {} ' .format (self ._channelSpecs [ch ][PROD_RATE_SPEC_KEY ]))
659+ if INITIAL_TOKENS_SPEC_KEY in self ._channelSpecs [ch ]:
660+ specs .append (' initial tokens: {} ' .format (self ._channelSpecs [ch ][INITIAL_TOKENS_SPEC_KEY ]))
656661 return ';' .join (specs )
657662
658663
0 commit comments