Commit 14bb3fc6 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Georgios Dagkakis

batch objects follow the expectedSignals paradeigm

parent 7323512c
......@@ -73,6 +73,10 @@ class BatchDecomposition(CoreObject):
G.BatchWaitingList = [] # batches waiting to be reassembled
CoreObject.initialize(self) # using the default CoreObject 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
......@@ -82,6 +86,11 @@ class BatchDecomposition(CoreObject):
self.initialSignalReceiver()
while 1:
# wait for an event or an interruption
self.expectedSignals['isRequested']=1
self.expectedSignals['interruptionStart']=1
self.expectedSignals['initialWIP']=1
while 1:
receivedEvent=yield self.env.any_of([self.isRequested , self.interruptionStart , self.initialWIP])
# if an interruption has occurred
......@@ -90,7 +99,13 @@ class BatchDecomposition(CoreObject):
assert eventTime==self.env.now, 'the interruption received by batchDecomposition was created earlier'
self.interruptionStart=self.env.event()
# wait till it is over
self.expectedSignals['interruptionEnd']=1
yield self.interruptionEnd
self.expectedSignals['interruptionEnd']=0
transmitter, eventTime=self.interruptionEnd.value
assert self==transmitter, 'the victim of the failure is not the object that received the interruptionEnd event'
self.interruptionEnd=self.env.event()
......@@ -109,6 +124,10 @@ class BatchDecomposition(CoreObject):
assert requestingObject==self.giver, 'the giver is not the requestingObject'
self.isRequested=self.env.event()
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
self.currentEntity=self.getEntity()
......@@ -126,6 +145,8 @@ class BatchDecomposition(CoreObject):
# reset the variable
self.isProcessingInitialWIP=False
self.expectedSignals['canDispose']=1
# TODO: add failure control
# as long as there are sub-Batches in the internal Resource
numberOfSubBatches=int(len(self.getActiveObjectQueue()))
......@@ -146,7 +167,13 @@ class BatchDecomposition(CoreObject):
# signal the receiver again and break
if self.signalReceiver():
self.waitEntityRemoval=True
self.expectedSignals['entityRemoved']=1
yield self.entityRemoved
self.expectedSignals['entityRemoved']=0
transmitter, eventTime=self.entityRemoved.value
self.waitEntityRemoval=False
break
......@@ -161,13 +188,21 @@ class BatchDecomposition(CoreObject):
signaling=self.signalReceiver()
if signaling:
self.waitEntityRemoval=True
self.expectedSignals['entityRemoved']=1
yield self.entityRemoved
self.expectedSignals['entityRemoved']=0
transmitter, eventTime=self.entityRemoved.value
self.waitEntityRemoval=False
break
self.entityRemoved=self.env.event()
self.expectedSignals['canDispose']=0
# =======================================================================
# removes an entity from the Machine
# =======================================================================
......
......@@ -69,6 +69,10 @@ class BatchReassembly(CoreObject):
def initialize(self):
CoreObject.initialize(self) # using the default CoreObject 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
......@@ -78,13 +82,24 @@ class BatchReassembly(CoreObject):
# check if there is WIP and signal receiver
self.initialSignalReceiver()
while 1:
self.expectedSignals['isRequested']=1
self.expectedSignals['interruptionStart']=1
self.expectedSignals['initialWIP']=1
while 1:
receivedEvent=yield self.env.any_of([self.isRequested , self.interruptionStart , self.initialWIP])
if self.interruptionStart in receivedEvent:
transmitter, eventTime=self.interruptionStart.value
assert eventTime==self.env.now, 'the interruptionStart received by BatchReassembly later than created'
self.interruptionStart=self.env.event()
self.expectedSignals['interruptionEnd']=1
yield self.interruptionEnd
self.expectedSignals['interruptionEnd']=0
transmitter, eventTime=self.interruptionEnd.value
assert self==transmitter, 'the victim of the failure is not the object that received the interruptionEnd event'
self.interruptionEnd=self.env.event()
......@@ -105,6 +120,10 @@ class BatchReassembly(CoreObject):
self.isProcessingInitialWIP=False
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
self.currentEntity=self.getEntity()
......@@ -121,6 +140,10 @@ class BatchReassembly(CoreObject):
self.reassemble()
self.isProcessingInitialWIP=False
# signal the receiver that the activeObject has something to dispose of
self.expectedSignals['interruptionStart']=1
self.expectedSignals['canDispose']=1
if not self.signalReceiver():
# if there was no available receiver, get into blocking control
while 1:
......@@ -138,7 +161,13 @@ class BatchReassembly(CoreObject):
self.interruptionActions() # execute interruption actions
# loop until we reach at a state that there is no interruption
while 1:
self.expectedSignals['interruptionEnd']=1
yield self.interruptionEnd # interruptionEnd to be triggered by ObjectInterruption
self.expectedSignals['interruptionEnd']=0
transmitter, eventTime=self.interruptionEnd.value
assert eventTime==self.env.now, 'the victim of the failure is not the object that received it'
self.interruptionEnd=self.env.event()
......@@ -170,7 +199,13 @@ class BatchReassembly(CoreObject):
break
self.waitEntityRemoval=True
self.printTrace(self.id, waitEvent='(entityRemoved)')
self.expectedSignals['entityRemoved']=1
yield self.entityRemoved
self.expectedSignals['entityRemoved']=0
transmitter, eventTime=self.entityRemoved.value
self.printTrace(self.id, entityRemoved=eventTime)
assert eventTime==self.env.now,'entityRemoved event activated earlier than received'
......@@ -179,7 +214,10 @@ class BatchReassembly(CoreObject):
# if while waiting (for a canDispose event) became free as the machines that follows emptied it, then proceed
if not self.haveToDispose():
break
self.expectedSignals['interruptionStart']=0
self.expectedSignals['canDispose']=0
# =======================================================================
# removes an entity from the Machine
# =======================================================================
......
......@@ -80,6 +80,7 @@ class NonStarvingEntry(Queue):
Globals.setWIP([E])
G.numberOfEntities+=1
if not self.canDispose.triggered:
succeedTuple=(self, self.env.now)
self.canDispose.succeed(succeedTuple)
if self.expectedSignals['canDispose']:
succeedTuple=(self, self.env.now)
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