Commit 2b18a52c authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

new object MouldAssemblyBuffer added. Corresponding scheduling rules added to Queue

parent 33f02e01
...@@ -57,15 +57,15 @@ class MouldAssemblyBuffer(QueuePreemptive): ...@@ -57,15 +57,15 @@ class MouldAssemblyBuffer(QueuePreemptive):
# to check weather they are present in activeObjectQueue # to check weather they are present in activeObjectQueue
if activeEntity.componentType=='Basic': if activeEntity.componentType=='Basic':
# local variable to notify when all the basics are received # local variable to notify when all the basics are received
allpresent = True allBasicsPresent = True
# run through all the basicComponentsList # run through all the basicComponentsList
for entity in activeEntity.order.basicComponentsList: for entity in activeEntity.order.basicComponentsList:
# if a basic is not present then set the local variable False and break # if a basic is not present then set the local variable False and break
if not (entity in activeObjectQueue): if not (entity in activeObjectQueue):
allPresent = False allBasicsPresent = False
break break
# if all are present then basicsEnded # if all are present then basicsEnded
if allPresent: if allBasicsPresent:
activeEntity.order.basicsEnded = 1 activeEntity.order.basicsEnded = 1
# ======================================================================= # =======================================================================
...@@ -79,44 +79,69 @@ class MouldAssemblyBuffer(QueuePreemptive): ...@@ -79,44 +79,69 @@ class MouldAssemblyBuffer(QueuePreemptive):
activeObject=self.getActiveObject() activeObject=self.getActiveObject()
activeObjectQueue=self.getActiveObjectQueue() activeObjectQueue=self.getActiveObjectQueue()
thecaller = callerObject thecaller = callerObject
# assert that the callerObject is not None
assert thecaller!=None, 'the caller object of the MouldAssemblyBuffer should not be None'
thecallerQueue = callerObject.getActiveObjectQueue() thecallerQueue = callerObject.getActiveObjectQueue()
# -------------------------------------------------------------------
# check the length of the activeObjectQueue # check the length of the activeObjectQueue
# if the length is zero then no componentType or entity.type can be read # if the length is zero then no componentType or entity.type can be read
if len(activeObjectQueue)==0: if len(activeObjectQueue)==0:
return False return False
activeEntity = activeObjectQueue[0] # read the entity to be disposed # read the entity to be disposed
activeEntity = activeObjectQueue[0]
# assert that the entity.type is OrderComponent # assert that the entity.type is OrderComponent
assert activeEntity.type=='OrderComponent',\ assert activeEntity.type=='OrderComponent',\
"the entity to be disposed is not of type OrderComponent" "the entity to be disposed is not of type OrderComponent"
# assert that the entity.componentType is Basic or Secondary # assert that the entity.componentType is Basic or Secondary
assert activeEntity.componetType=='Secondary' or 'Basic',\ assert activeEntity.componetType=='Secondary' or 'Basic',\
"the entity to be disposed is not Basic or Secondary component" "the entity to be disposed is not Basic or Secondary component"
# -------------------------------------------------------------------
# check if the basics of the same parent order are already processed before disposing them to the next object # check if the basics of the same parent order are already processed before disposing them to the next object
# for all the components that have the same parent Order as the activeEntity # for all the components that have the same parent Order as the activeEntity
for entity in activeEntity.order.basicComponentsList+\ for entity in activeEntity.order.basicComponentsList+\
activeEntity.order.secondaryComponentsList: activeEntity.order.secondaryComponentsList:
# if one of them is not present in the activeObjectQueue or the caller's activeObjectQueue, return false # if one of them is not present in the activeObjectQueue or the caller's activeObjectQueue, return false
if not (entity in activeObjectQueue+thecallerQueue): if not (entity in activeObjectQueue+thecallerQueue):
return False return False
# if the previous check is passed and all the needed components are present and ready for the MouldAssembly
# then set the flag componentsReadyForAssembly to True (1)
activeEntity.order.componentsReadyForAssembly = 1
# -------------------------------------------------------------------
#if we have only one possible receiver just check if the caller is the receiver #if we have only one possible receiver just check if the caller is the receiver
if(len(activeObject.next)==1 or callerObject==None): if(len(activeObject.next)==1 or callerObject==None):
activeObject.receiver=activeObject.next[0] activeObject.receiver=activeObject.next[0]
return len(activeObjectQueue)>0\ # get the internal queue of the receiver
and thecaller==activeObject.receiver receiverQueue = activeObject.receiver.getActiveObjectQueue()
# if the successors (MouldAssembly) internal queue is empty then proceed with checking weather
# the caller is the receiver
if len(receiverQueue)==0:
return thecaller==activeObject.receiver
# otherwise, check additionally if the receiver holds orderComponents of the same order
else:
return thecaller==activeObject.receiver\
and receiverQueue[0].order==activeObjectQueue[0].order
# -------------------------------------------------------------------
#give the entity to the possible receiver that is waiting for the most time. #give the entity to the possible receiver that is waiting for the most time.
#plant does not do this in every occasion! #plant does not do this in every occasion!
maxTimeWaiting=0 maxTimeWaiting=0
# loop through the object in the successor list # loop through the object in the successor list
for object in activeObject.next: for object in activeObject.next:
if(object.canAccept(activeObject)): # if the object can accept # if the object can accept
timeWaiting=now()-object.timeLastEntityLeft # compare the time that it has been waiting if(object.canAccept(activeObject)):
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):# with the others' timeWaiting=now()-object.timeLastEntityLeft
# compare the time that it has been waiting with the others'
if(timeWaiting>maxTimeWaiting or maxTimeWaiting==0):
maxTimeWaiting=timeWaiting maxTimeWaiting=timeWaiting
self.receiver=object # and update the receiver to the index of this object # and update the receiver to the index of this object
activeObject.receiver=object
#return True if the Queue caller is the receiver # get the internal queue of the receiver
return (thecaller is self.receiver) receiverQueue = activeObject.receiver.getActiveObjectQueue()
\ No newline at end of file # if the successors (MouldAssembly) internal queue is empty then proceed with checking weather
# the caller is the receiver
if len(receiverQueue)==0:
return thecaller==activeObject.receiver
# otherwise, check additionally if the receiver holds orderComponents of the same order
else:
return thecaller==activeObject.receiver\
and receiverQueue[0].order==activeObjectQueue[0].order
\ No newline at end of file
...@@ -35,7 +35,7 @@ class Order(Job): ...@@ -35,7 +35,7 @@ class Order(Job):
type="Order" type="Order"
def __init__(self, id=None, name=None, route=[], priority=0, dueDate=None, orderDate=None, isCritical=False, def __init__(self, id=None, name=None, route=[], priority=0, dueDate=None, orderDate=None, isCritical=False,
componentsList=[], manager=None, basicsEnded=0, extraPropertyDict=None): componentsList=[], manager=None, basicsEnded=0, componentsReadyForAssembly=0, extraPropertyDict=None):
Job. __init__(self, id=id, name=name, route=route, priority=priority, dueDate=dueDate, orderDate=orderDate, Job. __init__(self, id=id, name=name, route=route, priority=priority, dueDate=dueDate, orderDate=orderDate,
extraPropertyDict=extraPropertyDict) extraPropertyDict=extraPropertyDict)
self.isCritical=isCritical # flag to inform weather the order is critical -> preemption self.isCritical=isCritical # flag to inform weather the order is critical -> preemption
...@@ -45,6 +45,8 @@ class Order(Job): ...@@ -45,6 +45,8 @@ class Order(Job):
self.auxiliaryComponentsList = [] # list of the auxiliary components of the order self.auxiliaryComponentsList = [] # list of the auxiliary components of the order
self.manager=manager # the manager responsible to handle the order self.manager=manager # the manager responsible to handle the order
self.basicsEnded=basicsEnded # flag that informs that the basic components of the order are finished self.basicsEnded=basicsEnded # flag that informs that the basic components of the order are finished
# flag that informs weather the components needed for the assembly are present in the Assembly Buffer
self.componentsReadForAssembly = componentsReadyForAssembly
...@@ -284,4 +284,10 @@ class Queue(CoreObject): ...@@ -284,4 +284,10 @@ class Queue(CoreObject):
# else if the componentType is Secondary and it's basics are not ended then move it to the back # else if the componentType is Secondary and it's basics are not ended then move it to the back
activeObjectQ.sort(key=lambda x: not ((x.componentType=='Basic')\ activeObjectQ.sort(key=lambda x: not ((x.componentType=='Basic')\
or ((x.order.basicsEnded)\ or ((x.order.basicsEnded)\
and (x.componentType=='Secondary')))) and (x.componentType=='Secondary'))))
\ No newline at end of file #if the schedulingRule is set to MouldAssemblyBuffer scheduling rule "MAB" where orderComponents of the same order,
#whose components are all present in the activeQ of the activeObject or its successor,
#are moved to the beginning of the queue
elif criterion=='MAB':
# if all the components of the same mould are present then move them to the front of the activeQ
activeObjectQ.sort(key=lambda x: x.order.componentsReadForAssembly)
\ 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