new event entityRemoved added to handle inconsistency of timeout(0) while waiting to dispose a unit

parent 9bf41014
...@@ -66,6 +66,8 @@ class CoreObject(object): ...@@ -66,6 +66,8 @@ class CoreObject(object):
# self.interruptionStart=SimEvent('interruptionStart') # self.interruptionStart=SimEvent('interruptionStart')
self.interruptionStart=self.env.event() self.interruptionStart=self.env.event()
self.entityRemoved=self.env.event()
def initialize(self): def initialize(self):
# XXX why call super.__init__ outside of __init__ ? # XXX why call super.__init__ outside of __init__ ?
# Process.__init__(self) # Process.__init__(self)
...@@ -149,6 +151,8 @@ class CoreObject(object): ...@@ -149,6 +151,8 @@ class CoreObject(object):
# self.interruptionStart=SimEvent('interruptionStart') # self.interruptionStart=SimEvent('interruptionStart')
self.interruptionStart=self.env.event() self.interruptionStart=self.env.event()
self.entityRemoved=self.env.event()
# ======================================================================= # =======================================================================
# the main process of the core object # the main process of the core object
# this is dummy, every object must have its own implementation # this is dummy, every object must have its own implementation
...@@ -192,6 +196,10 @@ class CoreObject(object): ...@@ -192,6 +196,10 @@ class CoreObject(object):
# update wipStatList # update wipStatList
if self.gatherWipStat: if self.gatherWipStat:
self.wipStatList.append([self.env.now, len(activeObjectQueue)]) self.wipStatList.append([self.env.now, len(activeObjectQueue)])
if not self.entityRemoved.triggered:
self.printTrace(self.id, signal='(removedEntity)')
self.entityRemoved.succeed(self.env.now)
return entity return entity
#=========================================================================== #===========================================================================
...@@ -431,7 +439,7 @@ class CoreObject(object): ...@@ -431,7 +439,7 @@ class CoreObject(object):
@staticmethod @staticmethod
def findGiversFor(activeObject): def findGiversFor(activeObject):
givers=[] givers=[]
for object in [x for x in activeObject.previous if(not x is activeObject)]:# and not x.canDispose.triggered]: for object in [x for x in activeObject.previous if(not x is activeObject) and not x.canDispose.triggered]:
if object.haveToDispose(activeObject): if object.haveToDispose(activeObject):
givers.append(object) givers.append(object)
return givers return givers
......
...@@ -121,12 +121,12 @@ class Dismantle(CoreObject): ...@@ -121,12 +121,12 @@ class Dismantle(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.printTrace(self.id, waitEvent='(frame)') # self.printTrace(self.id, waitEvent='(frame)')
# wait until the Queue can accept an entity and one predecessor requests it # wait until the Queue can accept an entity and one predecessor requests it
yield self.isRequested #[self.isRequested,self.canDispose, self.loadOperatorAvailable] yield self.isRequested #[self.isRequested,self.canDispose, self.loadOperatorAvailable]
if self.isRequested.value: if self.isRequested.value:
self.printTrace(self.id, isRequested=self.isRequested.value.id) # self.printTrace(self.id, isRequested=self.isRequested.value.id)
# reset the isRequested signal parameter # reset the isRequested signal parameter
self.isRequested=self.env.event() self.isRequested=self.env.event()
...@@ -144,6 +144,7 @@ class Dismantle(CoreObject): ...@@ -144,6 +144,7 @@ class Dismantle(CoreObject):
self.waitToDispose=True self.waitToDispose=True
self.waitToDisposePart=True #Dismantle is in state to dispose a part self.waitToDisposePart=True #Dismantle is in state to dispose a part
# while the object still holds the frame # while the object still holds the frame
flag=False
while not self.isEmpty(): while not self.isEmpty():
# try and signal the receiver # try and signal the receiver
if not self.signalReceiver(): if not self.signalReceiver():
...@@ -154,8 +155,10 @@ class Dismantle(CoreObject): ...@@ -154,8 +155,10 @@ class Dismantle(CoreObject):
if not self.signalReceiver(): if not self.signalReceiver():
continue continue
# if the receiver was not responsive, release the control to let him remove the entity # if the receiver was not responsive, release the control to let him remove the entity
yield self.env.timeout(0) yield self.entityRemoved
# if all the parts are removed but not the frame, then set the flag waitToDisposeFrame self.entityRemoved=self.env.event()
# yield self.env.timeout(0)#(0.000000000000005)
if self.frameIsEmpty() and not self.waitToDisposeFrame: if self.frameIsEmpty() and not self.waitToDisposeFrame:
self.waitToDisposePart=False self.waitToDisposePart=False
self.waitToDisposeFrame=True self.waitToDisposeFrame=True
...@@ -220,8 +223,9 @@ class Dismantle(CoreObject): ...@@ -220,8 +223,9 @@ class Dismantle(CoreObject):
#=========================================================================== #===========================================================================
# find possible receivers # find possible receivers
#=========================================================================== #===========================================================================
def findReceivers(self): @staticmethod
activeObject=self.getActiveObject() def findReceiversFor(activeObject):
# activeObject=self.getActiveObject()
next=[] next=[]
receivers=[] receivers=[]
# if the parts are not yet disposed # if the parts are not yet disposed
......
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