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):
# self.interruptionStart=SimEvent('interruptionStart')
self.interruptionStart=self.env.event()
self.entityRemoved=self.env.event()
def initialize(self):
# XXX why call super.__init__ outside of __init__ ?
# Process.__init__(self)
......@@ -149,6 +151,8 @@ class CoreObject(object):
# self.interruptionStart=SimEvent('interruptionStart')
self.interruptionStart=self.env.event()
self.entityRemoved=self.env.event()
# =======================================================================
# the main process of the core object
# this is dummy, every object must have its own implementation
......@@ -192,6 +196,10 @@ class CoreObject(object):
# update wipStatList
if self.gatherWipStat:
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
#===========================================================================
......@@ -431,7 +439,7 @@ class CoreObject(object):
@staticmethod
def findGiversFor(activeObject):
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):
givers.append(object)
return givers
......
......@@ -121,12 +121,12 @@ class Dismantle(CoreObject):
# check if there is WIP and signal receiver
self.initialSignalReceiver()
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
yield self.isRequested #[self.isRequested,self.canDispose, self.loadOperatorAvailable]
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
self.isRequested=self.env.event()
......@@ -144,6 +144,7 @@ class Dismantle(CoreObject):
self.waitToDispose=True
self.waitToDisposePart=True #Dismantle is in state to dispose a part
# while the object still holds the frame
flag=False
while not self.isEmpty():
# try and signal the receiver
if not self.signalReceiver():
......@@ -154,8 +155,10 @@ class Dismantle(CoreObject):
if not self.signalReceiver():
continue
# if the receiver was not responsive, release the control to let him remove the entity
yield self.env.timeout(0)
# if all the parts are removed but not the frame, then set the flag waitToDisposeFrame
yield self.entityRemoved
self.entityRemoved=self.env.event()
# yield self.env.timeout(0)#(0.000000000000005)
if self.frameIsEmpty() and not self.waitToDisposeFrame:
self.waitToDisposePart=False
self.waitToDisposeFrame=True
......@@ -220,8 +223,9 @@ class Dismantle(CoreObject):
#===========================================================================
# find possible receivers
#===========================================================================
def findReceivers(self):
activeObject=self.getActiveObject()
@staticmethod
def findReceiversFor(activeObject):
# activeObject=self.getActiveObject()
next=[]
receivers=[]
# 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