QueueManagedJob and MouldAssemblyBuffer corrections according to the new...

QueueManagedJob and MouldAssemblyBuffer corrections according to the new OperatorManagedJob resource requirments
parent cd7acd21
......@@ -133,8 +133,8 @@ class MouldAssemblyBuffer(QueueManagedJob):
# if the length is zero then no componentType or entity.type can be read
if len(activeObjectQueue)==0:
return False
# read the entity to be disposed
index = 0
# find out if there are entities with available managers that are ready for assembly
activeEntity=None
for entity in activeObjectQueue:
if entity.order.componentsReadyForAssembly:
......@@ -143,14 +143,13 @@ class MouldAssemblyBuffer(QueueManagedJob):
activeEntity=entity
break
# otherwise, if the manager of the entity is available
elif entity.manager.checkIfResourceIsAvailable:
elif entity.manager.checkIfResourceIsAvailable(thecaller):
activeEntity=entity
break
# if there is no entity in the activeQ that its parentOrder has the flag componentsReadyForAssembly set
if not activeEntity:
# return false
return False
# activeEntity = activeObjectQueue[0]
if(len(activeObject.next)==1): #if we have only one possible receiver
activeObject.receiver=activeObject.next[0]
else: # otherwise,
......@@ -166,9 +165,13 @@ class MouldAssemblyBuffer(QueueManagedJob):
receiverQueue = activeObject.receiver.getActiveObjectQueue()
except:
return False
# sort the entities now that the receiver is updated
self.sortEntities()
# update the activeEntity
activeEntity=activeObjectQueue[0]
# if the successors (MouldAssembly) internal queue is empty then proceed with checking weather
# the caller is the receiver
# TODO the activeEntity is already checked for the flag componentsReadyForAssembly
# TODO: the activeEntity is already checked for the flag componentsReadyForAssembly
if len(receiverQueue)==0:
if activeEntity.type=='Mould':
return thecaller is activeObject.receiver
......
......@@ -28,6 +28,13 @@ checks if he is available before it disposed it
from SimPy.Simulation import now
from QueueJobShop import QueueJobShop
# ===========================================================================
# Error in the setting up of the WIP
# ===========================================================================
class NoCallerError(Exception):
def __init__(self, callerError):
Exception.__init__(self, callerError)
# ===========================================================================
# the QueueManagedJob object
# ===========================================================================
......@@ -41,26 +48,30 @@ class QueueManagedJob(QueueJobShop):
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
thecaller = callerObject
# assert that the callerObject is not None
try:
if callerObject:
thecaller = callerObject
else:
raise NoCallerError('The caller of the MouldAssemblyBuffer must be defined')
except NoCallerError as noCaller:
print 'No caller error: {0}'.format(noCaller)
#search if for one or more of the Entities the operator is available
haveEntityWithAvailableManager=False
for entity in activeObjectQueue:
if entity.manager:
if entity.manager.checkIfResourceIsAvailable:
if entity.manager.checkIfResourceIsAvailable(thecaller):
haveEntityWithAvailableManager=True
break
#if none of the Entities has an available manager return False
if not haveEntityWithAvailableManager:
return False
#sort the internal queue so that the Entities that have an available manager go in the front
self.sortEntities()
#if we have only one possible receiver just check if the Queue holds one or more entities
if(len(activeObject.next)==1 or callerObject==None):
if(len(activeObject.next)==1):
activeObject.receiver=activeObject.next[0]
#sort the internal queue so that the Entities that have an available manager go in the front
activeObject.sortEntities()
return len(activeObjectQueue)>0\
and thecaller==activeObject.receiver
......@@ -72,18 +83,27 @@ class QueueManagedJob(QueueJobShop):
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# with the others'
maxTimeWaiting=timeWaiting
self.receiver=object # and update the receiver
#sort the internal queue so that the Entities that have an available manager go in the front
activeObject.sortEntities()
#return True if the Queue has Entities and the caller is the receiver
return len(activeObjectQueue)>0 and (thecaller is self.receiver)
#override the default method so that Entities that have the manager available go in front
# =======================================================================
# override the default method so that Entities
# that have the manager available go in front
# =======================================================================
def sortEntities(self):
QueueJobShop.sortEntities(self) #do the default sorting first
activeObjectQueue=self.getActiveObjectQueue()
# search for the entities in the activeObjectQueue that have available manager
for entity in activeObjectQueue:
entity.managerAvailable=False
if entity.manager:
if entity.manager.checkIfResourceIsAvailable:
# if the entity has manager assigned
if entity.manager:
# check his availability
if entity.manager.checkIfResourceIsAvailable(self.receiver):
entity.managerAvailable=True
# sort the active queue according to the availability of the managers
activeObjectQueue.sort(key=lambda x: x.managerAvailable, reverse=True)
\ 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