managedJobQueues now sort not for receiver but for thecaller of their haveToDispose method

parent 90b37ff5
......@@ -58,60 +58,33 @@ class ConditionalBuffer(QueueManagedJob):
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
# 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)
# check the length of the activeObjectQueue
# if the length is zero then no componentType or entity.type can be read
if len(activeObjectQueue)==0:
return False
#search if for one or more of the Entities the operator is available
operatedJobs=[]
haveEntityWithAvailableManager=False
for entity in activeObjectQueue:
if entity.manager:
operatedJobs.append(entity)
if entity.manager.checkIfResourceIsAvailable(thecaller):
haveEntityWithAvailableManager=True
break
# if there are operated entities then check if there are available managers
if len(operatedJobs)>0:
#if none of the Entities has an available manager return False
if not haveEntityWithAvailableManager:
return False
# # TODO: when the callerObject is not defined will receive error ass the checkIfResourceIsAvailable requests a caller
#
# #search if for one or more of the Entities the operator is available
# haveEntityWithAvailableManager=False
# for entity in [x for x in activeObjectQueue if x.manager]:
# 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
# activeObject.sortEntities()
# #if we have only one possible receiver just check if the Queue holds one or more entities
# if(callerObject==None):
# return len(activeObjectQueue)>0
#
# #return True if the Queue has Entities and the caller is in the self.next list
# return len(activeObjectQueue)>0\
# and (thecaller in activeObject.next)\
# and thecaller.isInRoute(activeObject)
#if we have only one possible receiver just check if the receiver is the caller
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
# now that the receiver is updated
activeObject.sortEntities()
return thecaller is activeObject.receiver\
and activeObject.checkCondition()
#give the entity to the possible receiver that is waiting for the most time.
#plant does not do this in every occasion!
maxTimeWaiting=0
# loop through the object in the successor list
for object in activeObject.next:
# if the object can accept
if(object.canAccept(activeObject)):
timeWaiting=now()-object.timeLastEntityLeft
# compare the time that it has been waiting with the others'
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
maxTimeWaiting=timeWaiting
# and update the receiver to the index of this object
activeObject.receiver=object
#sort the internal queue so that the Entities that have an available manager go in the front
activeObject.sortEntities()
#return True if the Queue caller is the receiver
return thecaller is activeObject.receiver\
and activeObject.checkCondition()
# and then perform the default behaviour
if QueueManagedJob.haveToDispose(self,callerObject):
return activeObject.checkCondition()
return False
# =======================================================================
# check whether the condition is True
......@@ -162,7 +135,7 @@ class ConditionalBuffer(QueueManagedJob):
entity.managerAvailable=False
if entity.manager:
managedEntities.append(entity)
if entity.manager.checkIfResourceIsAvailable(self.receiver):
if entity.manager.checkIfResourceIsAvailable(self.objectSortingFor):
entity.managerAvailable=True
# if the entities are operated
if len(managedEntities):
......
......@@ -79,6 +79,7 @@ class MouldAssemblyBuffer(QueueManagedJob):
# We suppose that only one MouldAssembly buffer is present in the topology
# and thus there is no need to check if entities of the same parentOrder
# are present in other MouldAssemblyBuffers
# TODO: has to signal ConditionalBuffer to start sending entities again
# =======================================================================
def getEntity(self):
activeObject = self.getActiveObject()
......@@ -104,6 +105,11 @@ class MouldAssemblyBuffer(QueueManagedJob):
# if all are present then basicsEnded
if allBasicsPresent:
activeEntity.order.basicsEnded = 1
# TODO: has to signal ConditionalBuffer to start sending entities again
for secondary in [x for x in activeEntity.order.secondaryComponentsList if activeEntity.order.basicsEnded]:
if secondary.currentStation.__class__.__name__=='ConditionalBuffer':
secondary.currentStation.canDispose.signal(now())
break
# for all the components that have the same parent Order as the activeEntity
activeEntity.order.componentsReadyForAssembly = 1
for entity in activeEntity.order.basicComponentsList+\
......@@ -128,18 +134,12 @@ class MouldAssemblyBuffer(QueueManagedJob):
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
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)
thecaller=callerObject
activeObject.objectSortingFor=thecaller
# check the length of the activeObjectQueue
# if the length is zero then no componentType or entity.type can be read
if len(activeObjectQueue)==0:
return False
# find out if there are entities with available managers that are ready for assembly
activeEntity=None
for entity in activeObjectQueue:
......@@ -156,38 +156,26 @@ class MouldAssemblyBuffer(QueueManagedJob):
if not activeEntity:
# return false
return False
if(len(activeObject.next)==1): #if we have only one possible receiver
activeObject.receiver=activeObject.next[0]
else: # otherwise,
maxTimeWaiting=0 #give the entity to the possible receiver that is waiting for the most time.
for object in activeObject.next: # loop through the object in the successor list
if(object.canAccept(activeObject)): # if the object can accept
timeWaiting=now()-object.timeLastEntityLeft
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# check the time that it has been waiting
maxTimeWaiting=timeWaiting
activeObject.receiver=object # and update the receiver
# if the receiverQueue cannot be read, return False
try:
receiverQueue = activeObject.receiver.getActiveObjectQueue()
except:
return False
# sort the entities now that the receiver is updated
self.sortEntities()
activeObject.sortEntities()
# update the activeEntity
activeEntity=activeObjectQueue[0]
# if no caller is defined then check if the entity to be disposed has the flag componentsReadyForAssembly raised
if not thecaller:
return activeEntity.order.componentsReadyForAssembly
# 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
if len(receiverQueue)==0:
if len(thecaller.getActiveObjectQueue())==0:
if activeEntity.type=='Mould':
return thecaller is activeObject.receiver
return thecaller.isInRoute(activeObject)
else:
return thecaller is activeObject.receiver\
return thecaller.isInRoute(activeObject)\
and activeEntity.order.componentsReadyForAssembly
# otherwise, check additionally if the receiver holds orderComponents of the same order
# TODO: should revise, this check may be redundant, as the receiver (assembler must be empty in order to start receiving
# It is therefore needed that the control is performed by the assembler's getEntity()
else:
return thecaller is activeObject.receiver\
and receiverQueue[0].order is activeObjectQueue[0].order\
return thecaller.isInRoute(activeObject)\
and thecaller.getActiveObjectQueue()[0].order is activeEntity.order\
and activeEntity.order.componentsReadyForAssembly
......@@ -73,10 +73,10 @@ class OrderDecomposition(CoreObject):
yield waitevent, self, [self.isRequested,self.canDispose]
# if the event that activated the thread is isRequested then getEntity
if self.isRequested.signalparam:
self.getEntity()
self.decompose()
# reset the isRequested signal parameter
self.isRequested.signalparam=None
self.getEntity()
self.decompose()
# if the event that activated the thread is canDispose then signalReceiver
if self.haveToDispose():
self.signalReceiver()
......@@ -84,7 +84,7 @@ class OrderDecomposition(CoreObject):
# =======================================================================
# removes an entity from the Object
# =======================================================================
def removeEntity(self, entity=None):
def removeEntity(self, entity=None):
activeObject=self.getActiveObject()
activeEntity=CoreObject.removeEntity(self, entity) #run the default method
if self.canAccept():
......
......@@ -52,8 +52,8 @@ class QueueJobShop(Queue):
activeObject=self.getActiveObject()
activeObjectQueue=activeObject.getActiveObjectQueue()
thecaller=callerObject
#return according to the state of the Queue
#check it the caller object holds an Entity that requests for current object
#return according to the state of the Queue
#check it the caller object holds an Entity that requests for current object
return len(self.getActiveObjectQueue())<activeObject.capacity\
and activeObject.isInRoute(callerObject)
......@@ -83,14 +83,10 @@ class QueueJobShop(Queue):
# Returns True only to the potential receiver
# =======================================================================
def haveToDispose(self, callerObject=None):
# print self.id, 'htd',
# if callerObject:
# print callerObject.id
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
thecaller = callerObject
#if we have only one possible receiver just check if the Queue holds one or more entities
if(callerObject==None):
return len(activeObjectQueue)>0
......
......@@ -40,6 +40,21 @@ class NoCallerError(Exception):
# ===========================================================================
class QueueManagedJob(QueueJobShop):
def __init__(self, id, name, capacity=1, isDummy=False, schedulingRule="FIFO"):
QueueJobShop.__init__(self, id=id, name=name,capacity=capacity, isDummy=isDummy, schedulingRule=schedulingRule)
# variable used by the sortEntities method
# to identify the object it will be sorting for (manager.checkIfResourceIsAvailable(self.objectSortingFor))
self.objectSortingFor=None
# =======================================================================
# set all the objects in previous and next
# =======================================================================
def initialize(self):
QueueJobShop.initialize(self) #run default behaviour
# variable used by the sortEntities method
# to identify the object it will be sorting for (manager.checkIfResourceIsAvailable(self.objectSortingFor))
self.objectSortingFor=None
# =======================================================================
# checks if the Queue can dispose an entity.
# Returns True only to the potential receiver
......@@ -48,51 +63,48 @@ class QueueManagedJob(QueueJobShop):
# get active object and its queue
activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue()
# assert that the callerObject is not None
try:
if callerObject:
thecaller = callerObject
else:
raise NoCallerError('The caller of the QueueManagedJob haveToDispose must be defined')
except NoCallerError as noCaller:
print 'No caller error: {0}'.format(noCaller)
thecaller=callerObject
# update the objectSortingFor variable to hold the value of the callerObject
activeObject.objectSortingFor=thecaller
# TODO: when the callerObject is not defined will receive error ass the checkIfResourceIsAvailable requests a caller
#search if for one or more of the Entities the operator is available
#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(thecaller):
haveEntityWithAvailableManager=True
break
else:
haveEntityWithAvailableManager=True
break
# for entity in [x for x in activeObjectQueue if x.manager]:
# if entity.manager.checkIfResourceIsAvailable(thecaller):
# haveEntityWithAvailableManager=True
# break
#if none of the Entities has an available manager return False
if not haveEntityWithAvailableManager:
return False
#if we have only one possible receiver just check if the Queue holds one or more entities
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
#give the entity to the possible receiver that is waiting for the most time.
maxTimeWaiting=0
hasFreeReceiver=False
for object in activeObject.next: # loop through the object in the successor list
if(object.canAccept(activeObject)): # if the object can accept
hasFreeReceiver=True
timeWaiting=now()-object.timeLastEntityLeft # compare the time that it has been waiting
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
# the sortEntities method needs a receiver defined to sort the entities according to the availability of the manager
# so if there is a caller define him ass receiver and after the sorting set the receiver again to None
activeObject.sortEntities()
#return True if the Queue has Entities and the caller is the receiver
return len(activeObjectQueue)>0 and (thecaller is self.receiver) and hasFreeReceiver
# and then perform the default behaviour
return QueueJobShop.haveToDispose(self,thecaller)
# #if we have only one possible receiver just check if the Queue holds one or more entities
# if(thecaller==None):
# return len(activeObjectQueue)>0
#
# #return True if the Queue has Entities and the caller is the receiver
# return len(activeObjectQueue)>0\
# and (thecaller in activeObject.next)\
# and thecaller.isInRoute(activeObject)
# =======================================================================
# override the default method so that Entities
# that have the manager available go in front
# TODO: need receiver to sort the entities
# =======================================================================
def sortEntities(self):
QueueJobShop.sortEntities(self) #do the default sorting first
......@@ -103,7 +115,7 @@ class QueueManagedJob(QueueJobShop):
# if the entity has manager assigned
if entity.manager:
# check his availability
if entity.manager.checkIfResourceIsAvailable(self.receiver):
if entity.manager.checkIfResourceIsAvailable(self.objectSortingFor):
entity.managerAvailable=True
# sort the active queue according to the availability of the managers
activeObjectQueue.sort(key=lambda x: x.managerAvailable, reverse=True)
......
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