Commit 0fb94fd1 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Jérome Perrin

update sortEntities() method of ConditionalBuffer and MouldAssemlyBuffer

parent 41f8415a
...@@ -22,7 +22,7 @@ Created on 15 Jan 2014 ...@@ -22,7 +22,7 @@ Created on 15 Jan 2014
@author: Ioannis @author: Ioannis
''' '''
''' '''
Inherits from QueuePreemptive. Checks the condition of (a) component(s) before in can dispose of them/it Inherits from QueuePreemptive. Checks the condition of (a) component(s) before it can dispose them/it
''' '''
from QueuePreemptive import QueuePreemptive from QueuePreemptive import QueuePreemptive
...@@ -39,13 +39,6 @@ class NoCallerError(Exception): ...@@ -39,13 +39,6 @@ class NoCallerError(Exception):
# the QueuePreemptive object # the QueuePreemptive object
# =========================================================================== # ===========================================================================
class ConditionalBuffer(QueuePreemptive): class ConditionalBuffer(QueuePreemptive):
# ===========================================================================
# the __init__ function
# ===========================================================================
def __init__(self, id, name, capacity=-1, dummy=False, schedulingRule="CB"):
# run the default method, change the schedulingRule to CB
# for description, check activeQSorter function of Queue coreObject
QueuePreemptive.__init__(self, id, name, capacity, dummy, schedulingRule)
# ======================================================================= # =======================================================================
# checks if the Buffer can dispose an entity. # checks if the Buffer can dispose an entity.
...@@ -108,4 +101,21 @@ class ConditionalBuffer(QueuePreemptive): ...@@ -108,4 +101,21 @@ class ConditionalBuffer(QueuePreemptive):
return activeEntity.componentType=='Secondary'\ return activeEntity.componentType=='Secondary'\
and (activeEntity.order.basicsEnded) and (activeEntity.order.basicsEnded)
# =======================================================================
# sort the entities of the activeQ
# bring to the front the entities of componentType Basic
# and the entities of componentType Secondary that
# have the flag basicsEnded set
# =======================================================================
def sortEntities(self):
activeObject = self.getActiveObject()
# run the default sorting of the Queue first
QueuePreemptive.sortEntities(self)
# and in the end sort according to the ConditionalBuffer sorting rule
activeObjectQueue = activeObject.getActiveObjectQueue()
# if the componentType of the entities in the activeQueue is Basic then don't move it to the end of the activeQ
# else if the componentType is Secondary and it's basics are not ended then move it to the back
activeObjectQueue.sort(key=lambda x: not ((x.componentType=='Basic')\
or ((x.order.basicsEnded)\
and (x.componentType=='Secondary'))))
\ No newline at end of file
...@@ -40,14 +40,23 @@ class NoCallerError(Exception): ...@@ -40,14 +40,23 @@ class NoCallerError(Exception):
# the MouldAssemblyBuffer object # the MouldAssemblyBuffer object
# =========================================================================== # ===========================================================================
class MouldAssemblyBuffer(QueuePreemptive): class MouldAssemblyBuffer(QueuePreemptive):
# =======================================================================
# Sort the entities of the activeQ
# bring the entities that are ready for assembly to the front
# ======================================================================= # =======================================================================
# the __init__ function def sortEntities(self):
# ======================================================================= activeObject = self.getActiveObject()
def __init__(self, id, name, capacity=-1, dummy=False, schedulingRule="MAB"): # run the default sorting of the Queue first
# run the default method, change the schedulingRule to 'MAB' QueuePreemptive.sortEntities(self)
# for description, check activeQSorter function of Queue coreObject # and in the end sort according to the ConditionalBuffer sorting rule
QueuePreemptive.__init__(self, id, name, capacity, dummy, schedulingRule) activeObjectQueue = activeObject.getActiveObjectQueue()
# if all the components of the same mould are present then move them to the front of the activeQ
activeObjectQueue.sort(key=lambda x: x.order.componentsReadyForAssembly, reverse=True)
# keep the first entity of the activeQ
activeEntity = activeObjectQueue[0]
# bring the entities that have the same parentOrder as the first entity to the front
activeObjectQueue.sort(key=lambda x: not x.order.name == activeEntity.order.name)
# ======================================================================= # =======================================================================
# extend he default so that it sets order.basicsEnded to 1 # extend he default so that it sets order.basicsEnded to 1
......
...@@ -288,20 +288,6 @@ class Queue(CoreObject): ...@@ -288,20 +288,6 @@ class Queue(CoreObject):
nextObject=obj nextObject=obj
entity.nextQueueLength=len(nextObject.getActiveObjectQueue()) entity.nextQueueLength=len(nextObject.getActiveObjectQueue())
activeObjectQ.sort(key=lambda x: x.nextQueueLength) activeObjectQ.sort(key=lambda x: x.nextQueueLength)
#if the schedulingRule is set to ConditionalBuffer scheduling rule "CB" where orderComponents of type "Secondary"
#are moved to the end of the queue if their parent order.basicsEnded property is set to False
elif criterion=='CB':
# if the componentType is Basic then don't move it to the end of the activeQ
# 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')\
or ((x.order.basicsEnded)\
and (x.componentType=='Secondary'))))
#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.componentsReadyForAssembly)
else: else:
assert False, "Unknown scheduling criterion %r" % (criterion, ) assert False, "Unknown scheduling criterion %r" % (criterion, )
......
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