batch objects follow the expectedSignals paradeigm

parent 1302a0f6
...@@ -74,6 +74,10 @@ class BatchDecomposition(CoreObject): ...@@ -74,6 +74,10 @@ class BatchDecomposition(CoreObject):
CoreObject.initialize(self) # using the default CoreObject Functionality CoreObject.initialize(self) # using the default CoreObject Functionality
self.Res=simpy.Resource(self.env, self.numberOfSubBatches) # initialize the Internal resource (Queue) functionality self.Res=simpy.Resource(self.env, self.numberOfSubBatches) # initialize the Internal resource (Queue) functionality
self.expectedSignals['isRequested']=1
self.expectedSignals['interruptionStart']=1
self.expectedSignals['initialWIP']=1
# ======================================================================= # =======================================================================
# the run method of the BatchDecomposition # the run method of the BatchDecomposition
# ======================================================================= # =======================================================================
...@@ -82,6 +86,11 @@ class BatchDecomposition(CoreObject): ...@@ -82,6 +86,11 @@ class BatchDecomposition(CoreObject):
self.initialSignalReceiver() self.initialSignalReceiver()
while 1: while 1:
# wait for an event or an interruption # wait for an event or an interruption
self.expectedSignals['isRequested']=1
self.expectedSignals['interruptionStart']=1
self.expectedSignals['initialWIP']=1
while 1: while 1:
receivedEvent=yield self.env.any_of([self.isRequested , self.interruptionStart , self.initialWIP]) receivedEvent=yield self.env.any_of([self.isRequested , self.interruptionStart , self.initialWIP])
# if an interruption has occurred # if an interruption has occurred
...@@ -90,7 +99,13 @@ class BatchDecomposition(CoreObject): ...@@ -90,7 +99,13 @@ class BatchDecomposition(CoreObject):
assert eventTime==self.env.now, 'the interruption received by batchDecomposition was created earlier' assert eventTime==self.env.now, 'the interruption received by batchDecomposition was created earlier'
self.interruptionStart=self.env.event() self.interruptionStart=self.env.event()
# wait till it is over # wait till it is over
self.expectedSignals['interruptionEnd']=1
yield self.interruptionEnd yield self.interruptionEnd
self.expectedSignals['interruptionEnd']=0
transmitter, eventTime=self.interruptionEnd.value transmitter, eventTime=self.interruptionEnd.value
assert self==transmitter, 'the victim of the failure is not the object that received the interruptionEnd event' assert self==transmitter, 'the victim of the failure is not the object that received the interruptionEnd event'
self.interruptionEnd=self.env.event() self.interruptionEnd=self.env.event()
...@@ -110,6 +125,10 @@ class BatchDecomposition(CoreObject): ...@@ -110,6 +125,10 @@ class BatchDecomposition(CoreObject):
self.isRequested=self.env.event() self.isRequested=self.env.event()
break break
self.expectedSignals['isRequested']=0
self.expectedSignals['interruptionStart']=0
self.expectedSignals['initialWIP']=0
if not self.isProcessingInitialWIP: # if we are in the state of having initial wip no need to take an Entity if not self.isProcessingInitialWIP: # if we are in the state of having initial wip no need to take an Entity
self.currentEntity=self.getEntity() self.currentEntity=self.getEntity()
...@@ -126,6 +145,8 @@ class BatchDecomposition(CoreObject): ...@@ -126,6 +145,8 @@ class BatchDecomposition(CoreObject):
# reset the variable # reset the variable
self.isProcessingInitialWIP=False self.isProcessingInitialWIP=False
self.expectedSignals['canDispose']=1
# TODO: add failure control # TODO: add failure control
# as long as there are sub-Batches in the internal Resource # as long as there are sub-Batches in the internal Resource
numberOfSubBatches=int(len(self.getActiveObjectQueue())) numberOfSubBatches=int(len(self.getActiveObjectQueue()))
...@@ -146,7 +167,13 @@ class BatchDecomposition(CoreObject): ...@@ -146,7 +167,13 @@ class BatchDecomposition(CoreObject):
# signal the receiver again and break # signal the receiver again and break
if self.signalReceiver(): if self.signalReceiver():
self.waitEntityRemoval=True self.waitEntityRemoval=True
self.expectedSignals['entityRemoved']=1
yield self.entityRemoved yield self.entityRemoved
self.expectedSignals['entityRemoved']=0
transmitter, eventTime=self.entityRemoved.value transmitter, eventTime=self.entityRemoved.value
self.waitEntityRemoval=False self.waitEntityRemoval=False
break break
...@@ -161,13 +188,21 @@ class BatchDecomposition(CoreObject): ...@@ -161,13 +188,21 @@ class BatchDecomposition(CoreObject):
signaling=self.signalReceiver() signaling=self.signalReceiver()
if signaling: if signaling:
self.waitEntityRemoval=True self.waitEntityRemoval=True
self.expectedSignals['entityRemoved']=1
yield self.entityRemoved yield self.entityRemoved
self.expectedSignals['entityRemoved']=0
transmitter, eventTime=self.entityRemoved.value transmitter, eventTime=self.entityRemoved.value
self.waitEntityRemoval=False self.waitEntityRemoval=False
break break
self.entityRemoved=self.env.event() self.entityRemoved=self.env.event()
self.expectedSignals['canDispose']=0
# ======================================================================= # =======================================================================
# removes an entity from the Machine # removes an entity from the Machine
# ======================================================================= # =======================================================================
......
...@@ -70,6 +70,10 @@ class BatchReassembly(CoreObject): ...@@ -70,6 +70,10 @@ class BatchReassembly(CoreObject):
CoreObject.initialize(self) # using the default CoreObject Functionality CoreObject.initialize(self) # using the default CoreObject Functionality
self.Res=simpy.Resource(self.env, self.numberOfSubBatches) # initialize the Internal resource (Queue) functionality self.Res=simpy.Resource(self.env, self.numberOfSubBatches) # initialize the Internal resource (Queue) functionality
self.expectedSignals['isRequested']=1
self.expectedSignals['interruptionStart']=1
self.expectedSignals['initialWIP']=1
# ======================================================================= # =======================================================================
# the main method of the object # the main method of the object
# ======================================================================= # =======================================================================
...@@ -78,13 +82,24 @@ class BatchReassembly(CoreObject): ...@@ -78,13 +82,24 @@ class BatchReassembly(CoreObject):
# check if there is WIP and signal receiver # check if there is WIP and signal receiver
self.initialSignalReceiver() self.initialSignalReceiver()
while 1: while 1:
self.expectedSignals['isRequested']=1
self.expectedSignals['interruptionStart']=1
self.expectedSignals['initialWIP']=1
while 1: while 1:
receivedEvent=yield self.env.any_of([self.isRequested , self.interruptionStart , self.initialWIP]) receivedEvent=yield self.env.any_of([self.isRequested , self.interruptionStart , self.initialWIP])
if self.interruptionStart in receivedEvent: if self.interruptionStart in receivedEvent:
transmitter, eventTime=self.interruptionStart.value transmitter, eventTime=self.interruptionStart.value
assert eventTime==self.env.now, 'the interruptionStart received by BatchReassembly later than created' assert eventTime==self.env.now, 'the interruptionStart received by BatchReassembly later than created'
self.interruptionStart=self.env.event() self.interruptionStart=self.env.event()
self.expectedSignals['interruptionEnd']=1
yield self.interruptionEnd yield self.interruptionEnd
self.expectedSignals['interruptionEnd']=0
transmitter, eventTime=self.interruptionEnd.value transmitter, eventTime=self.interruptionEnd.value
assert self==transmitter, 'the victim of the failure is not the object that received the interruptionEnd event' assert self==transmitter, 'the victim of the failure is not the object that received the interruptionEnd event'
self.interruptionEnd=self.env.event() self.interruptionEnd=self.env.event()
...@@ -105,6 +120,10 @@ class BatchReassembly(CoreObject): ...@@ -105,6 +120,10 @@ class BatchReassembly(CoreObject):
self.isProcessingInitialWIP=False self.isProcessingInitialWIP=False
break break
self.expectedSignals['isRequested']=0
self.expectedSignals['interruptionStart']=0
self.expectedSignals['initialWIP']=0
if not self.isProcessingInitialWIP: # if we are in the state of having initial wip no need to take an Entity if not self.isProcessingInitialWIP: # if we are in the state of having initial wip no need to take an Entity
self.currentEntity=self.getEntity() self.currentEntity=self.getEntity()
...@@ -121,6 +140,10 @@ class BatchReassembly(CoreObject): ...@@ -121,6 +140,10 @@ class BatchReassembly(CoreObject):
self.reassemble() self.reassemble()
self.isProcessingInitialWIP=False self.isProcessingInitialWIP=False
# signal the receiver that the activeObject has something to dispose of # signal the receiver that the activeObject has something to dispose of
self.expectedSignals['interruptionStart']=1
self.expectedSignals['canDispose']=1
if not self.signalReceiver(): if not self.signalReceiver():
# if there was no available receiver, get into blocking control # if there was no available receiver, get into blocking control
while 1: while 1:
...@@ -138,7 +161,13 @@ class BatchReassembly(CoreObject): ...@@ -138,7 +161,13 @@ class BatchReassembly(CoreObject):
self.interruptionActions() # execute interruption actions self.interruptionActions() # execute interruption actions
# loop until we reach at a state that there is no interruption # loop until we reach at a state that there is no interruption
while 1: while 1:
self.expectedSignals['interruptionEnd']=1
yield self.interruptionEnd # interruptionEnd to be triggered by ObjectInterruption yield self.interruptionEnd # interruptionEnd to be triggered by ObjectInterruption
self.expectedSignals['interruptionEnd']=0
transmitter, eventTime=self.interruptionEnd.value transmitter, eventTime=self.interruptionEnd.value
assert eventTime==self.env.now, 'the victim of the failure is not the object that received it' assert eventTime==self.env.now, 'the victim of the failure is not the object that received it'
self.interruptionEnd=self.env.event() self.interruptionEnd=self.env.event()
...@@ -170,7 +199,13 @@ class BatchReassembly(CoreObject): ...@@ -170,7 +199,13 @@ class BatchReassembly(CoreObject):
break break
self.waitEntityRemoval=True self.waitEntityRemoval=True
self.printTrace(self.id, waitEvent='(entityRemoved)') self.printTrace(self.id, waitEvent='(entityRemoved)')
self.expectedSignals['entityRemoved']=1
yield self.entityRemoved yield self.entityRemoved
self.expectedSignals['entityRemoved']=0
transmitter, eventTime=self.entityRemoved.value transmitter, eventTime=self.entityRemoved.value
self.printTrace(self.id, entityRemoved=eventTime) self.printTrace(self.id, entityRemoved=eventTime)
assert eventTime==self.env.now,'entityRemoved event activated earlier than received' assert eventTime==self.env.now,'entityRemoved event activated earlier than received'
...@@ -180,6 +215,9 @@ class BatchReassembly(CoreObject): ...@@ -180,6 +215,9 @@ class BatchReassembly(CoreObject):
if not self.haveToDispose(): if not self.haveToDispose():
break break
self.expectedSignals['interruptionStart']=0
self.expectedSignals['canDispose']=0
# ======================================================================= # =======================================================================
# removes an entity from the Machine # removes an entity from the Machine
# ======================================================================= # =======================================================================
......
...@@ -80,6 +80,7 @@ class NonStarvingEntry(Queue): ...@@ -80,6 +80,7 @@ class NonStarvingEntry(Queue):
Globals.setWIP([E]) Globals.setWIP([E])
G.numberOfEntities+=1 G.numberOfEntities+=1
if not self.canDispose.triggered: if not self.canDispose.triggered:
if self.expectedSignals['canDispose']:
succeedTuple=(self, self.env.now) succeedTuple=(self, self.env.now)
self.canDispose.succeed(succeedTuple) self.canDispose.succeed(succeedTuple)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment