new activeQSorter for OperatorManagedJob

parent f7b761c8
...@@ -67,3 +67,128 @@ class OperatorManagedJob(Operator): ...@@ -67,3 +67,128 @@ class OperatorManagedJob(Operator):
# return False # return False
return len(self.Res.activeQ)<self.capacity return len(self.Res.activeQ)<self.capacity
# =======================================================================
# sorts the Entities of the Queue according to the scheduling rule
# =======================================================================
# TODO: entityToGet is not updated for all stations, consider using it for all stations or withdraw the idea
def activeQSorter(self, criterion=None):
activeObjectQ=self.activeCallersList
if criterion==None:
criterion=self.schedulingRule
#if the schedulingRule is first in first out
if criterion=="FIFO":
pass
#if the schedulingRule is based on a pre-defined priority
elif criterion=="Priority":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].priority)
#if the scheduling rule is time waiting (time waiting of machine
# TODO: consider that the timeLastEntityEnded is not a
# indicative identifier of how long the station was waiting
elif criterion=='WT':
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].schedule[-1][1])
#if the schedulingRule is earliest due date
elif criterion=="EDD":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].dueDate)
#if the schedulingRule is earliest order date
elif criterion=="EOD":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].orderDate)
#if the schedulingRule is to sort Entities according to the stations they have to visit
elif criterion=="NumStages":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
activeObjectQ.sort(key=lambda x: len(x.giver.getActiveObjectQueue()[0].remainingRoute), reverse=True)
#if the schedulingRule is to sort Entities according to the their remaining processing time in the system
elif criterion=="RPC":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
for object in activeObjectQ:
entity=object.giver.getActiveObjectQueue()[0]
RPT=0
for step in entity.remainingRoute:
processingTime=step.get('processingTime',None)
if processingTime:
RPT+=float(processingTime.get('mean',0))
entity.remainingProcessingTime=RPT
activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].remainingProcessingTime, reverse=True)
#if the schedulingRule is to sort Entities according to longest processing time first in the next station
elif criterion=="LPT":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
for object in activeObjectQ:
entity=object.giver.getActiveObjectQueue()[0]
processingTime = entity.remainingRoute[0].get('processingTime',None)
entity.processingTimeInNextStation=float(processingTime.get('mean',0))
if processingTime:
entity.processingTimeInNextStation=float(processingTime.get('mean',0))
else:
entity.processingTimeInNextStation=0
activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].processingTimeInNextStation, reverse=True)
#if the schedulingRule is to sort Entities according to shortest processing time first in the next station
elif criterion=="SPT":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
for object in activeObjectQ:
entity=object.giver.getActiveObjectQueue()[0]
processingTime = entity.remainingRoute[0].get('processingTime',None)
if processingTime:
entity.processingTimeInNextStation=float(processingTime.get('mean',0))
else:
entity.processingTimeInNextStation=0
activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].processingTimeInNextStation)
#if the schedulingRule is to sort Entities based on the minimum slackness
elif criterion=="MS":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
for object in activeObjectQ:
object.giver.getActiveObjectQueue()[0]
RPT=0
for step in entity.remainingRoute:
processingTime=step.get('processingTime',None)
if processingTime:
RPT+=float(processingTime.get('mean',0))
entity.remainingProcessingTime=RPT
activeObjectQ.sort(key=lambda x: (x.giver.getActiveObjectQueue()[0].dueDate-x.giver.getActiveObjectQueue()[0].remainingProcessingTime))
#if the schedulingRule is to sort Entities based on the length of the following Queue
elif criterion=="WINQ":
for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self)
from Globals import G
for object in activeObjectQ:
entity=object.giver.getActiveObjectQueue()[0]
nextObjIds=entity.remainingRoute[1].get('stationIdsList',[])
for obj in G.ObjList:
if obj.id in nextObjIds:
nextObject=obj
entity.nextQueueLength=len(nextObject.getActiveObjectQueue())
activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].nextQueueLength)
else:
assert False, "Unknown scheduling criterion %r" % (criterion, )
\ 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