Example #1
0
    def preempt(self):
        activeObject=self.getActiveObject()
        activeEntity=self.getActiveObjectQueue()[0] #get the active Entity
        #calculate the remaining processing time
        #if it is reset then set it as the original processing time
        if self.resetOnPreemption:
            remainingProcessingTime=self.procTime
        #else subtract the time that passed since the entity entered
        #(may need also failure time if there was. TO BE MELIORATED)
        else:
            remainingProcessingTime=self.procTime-(now()-self.timeLastEntityEntered)
        #update the remaining route of activeEntity
        activeEntity.remainingRoute.insert(0, {'stationIdsList':[str(self.id)],\
                                               'processingTime':\
                                                    {'distributionType':'Fixed',\
                                                     'mean':str(remainingProcessingTime)}})
#         activeEntity.remainingRoute.insert(0, [self.id, remainingProcessingTime])
        activeEntity.remainingRoute.insert(0, {'stationIdsList':[str(self.lastGiver.id)],\
                                               'processingTime':\
                                                    {'distributionType':'Fixed',\
                                                     'mean':'0'}})
#         activeEntity.remainingRoute.insert(0, [self.lastGiver.id, 0])        
        #set the receiver  as the object where the active entity was preempted from 
        self.receiver=self.lastGiver
        self.next=[self.receiver]
        self.waitToDispose=True                     #set that I have to dispose
        self.receiver.timeLastEntityEnded=now()     #required to count blockage correctly in the preemptied station
        reactivate(self)
Example #2
0
 def operate(self, repairduration, triplength):  # PEM
     tripleft = triplength  # time needed to finish trip
     while tripleft > 0:
         yield hold, self, tripleft  # try to finish the trip
         if self.interrupted():  # if another breakdown occurs
             print('%s at %s' % (self.interruptCause.name, now()))
             tripleft = self.interruptLeft  # time to finish the trip
             self.interruptReset()  # end interrupt state
             reactivate(br, delay=repairduration)  # restart breakdown br
             yield hold, self, repairduration  # delay for repairs
             print('Bus repaired at %s' % now())
         else:
             break  # no more breakdowns, bus finished trip
     print('Bus has arrived at %s' % now())
 def execute(self, arrival_rate, pathname, delay, period, amplitude, phase, offset, profile, rate):
     service_time_distribution = Sources.random_stream_from_data(pathname)
     yield hold, self, delay
     if profile:
         for i in itertools.count():
             yield hold, self, random.expovariate(Sources.profile_rate_modifier(now(), profile))
             j = Job("Job%d" % i, service_time_distribution.next())
             Server.queue.append(j)
             if Server.idle:
                 reactivate(random.choice(Server.idle))
     else:
         for i in itertools.count():
             yield hold, self, random.expovariate(Sources.sinusoidal_rate_modifier(arrival_rate, now(), period, amplitude, phase, offset))
             j = Job("Job%d" % i, service_time_distribution.next())
             Server.queue.append(j)
             if Server.idle:
                 reactivate(random.choice(Server.idle))
Example #4
0
 def _RUN_HALT(self, fsm, *args, **kwargs):
     """Internal SEM to halt execution of `FSM`."""
     fsm.cancel(self)
     self.goto(self.HALT, *args, **kwargs)
     reactivate(self)
     yield hold, fsm, 0
Example #5
0
 def reactivateVictim(self):
     reactivate(self.victim)  
Example #6
0
 def entangle(cls, *a, **kw):
     func(cls, *a, **kw)
     reactivate(cls)
Example #7
0
 def signal(self, name, value=None):
     self._signals[name] = value
     reactivate(self)