Commit e019a227 authored by Ioannis Papagiannopoulos's avatar Ioannis Papagiannopoulos Committed by Georgios Dagkakis

clean-up in OperatorManagedJob

parent a5a2e52b
......@@ -120,245 +120,4 @@ class OperatorManagedJob(Operator):
if not candidateEntity:
candidateEntity=next(x for x in self.candidateEntities)
router.conflictingEntities.append(candidateEntity)
return candidateEntity
# =======================================================================
# sorts the candidateEntities of the Operator according to the scheduling rule
# TODO: maybe the argument is not needed. the candidate entities is a variable of the object
# =======================================================================
def sortCandidateEntities(self):
# TODO: have to consider what happens in case of a critical order
#if we have sorting according to multiple criteria we have to call the sorter many times
if self.schedulingRule=="MC":
for criterion in reversed(self.multipleCriterionList):
self.activeCandidateQSorter(criterion=criterion)
#else we just use the default scheduling rule
else:
self.activeCandidateQSorter(self.schedulingRule)
# =======================================================================
# 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 activeCandidateQSorter(self, criterion=None):
activeObjectQ=self.candidateEntities
if not activeObjectQ:
assert False, "empty candidate list"
if criterion==None:
criterion=self.schedulingRule
#if the schedulingRule is first in first out
if criterion=="FIFO":
# FIFO sorting has no meaning when sorting candidateEntities
self.activeCandidateQSorter('WT')
# added for testing
# print 'there is no point of using FIFO scheduling rule for operators candidateEntities,\
# WT scheduling rule used instead'
#if the schedulingRule is based on a pre-defined priority
elif criterion=="Priority":
activeObjectQ.sort(key=lambda x: x.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':
activeObjectQ.sort(key=lambda x: x.schedule[-1][1])
#if the schedulingRule is earliest due date
elif criterion=="EDD":
activeObjectQ.sort(key=lambda x: x.dueDate)
#if the schedulingRule is earliest order date
elif criterion=="EOD":
activeObjectQ.sort(key=lambda x: x.orderDate)
#if the schedulingRule is to sort Entities according to the stations they have to visit
elif criterion=="NumStages":
activeObjectQ.sort(key=lambda x: len(x.remainingRoute), reverse=True)
#if the schedulingRule is to sort Entities according to the their remaining processing time in the system
elif criterion=="RPC":
for entity in activeObjectQ:
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.remainingProcessingTime, reverse=True)
#if the schedulingRule is to sort Entities according to longest processing time first in the next station
elif criterion=="LPT":
for entity in activeObjectQ:
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.processingTimeInNextStation, reverse=True)
#if the schedulingRule is to sort Entities according to shortest processing time first in the next station
elif criterion=="SPT":
for entity in activeObjectQ:
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.processingTimeInNextStation)
#if the schedulingRule is to sort Entities based on the minimum slackness
elif criterion=="MS":
for entity in activeObjectQ:
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.dueDate-x.remainingProcessingTime))
#if the schedulingRule is to sort Entities based on the length of the following Queue
elif criterion=="WINQ":
from Globals import G
for entity in activeObjectQ:
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.nextQueueLength)
else:
assert False, "Unknown scheduling criterion %r" % (criterion, )
# # =======================================================================
# # 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 activeCallerQSorter(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)
# # TODO: the entities should be also sort according to their waiting time in case the priority is the same
# 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)
# # TODO: the entities should be also sort according to their waiting time in case the EDD is the same
# 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)
# # TODO: the entities should be also sort according to their waiting time in case the EOD is the same
# 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)
# # TODO: the entities should be also sort according to their waiting time in case the NumStages are the same
# 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
# # TODO: the entities should be also sort according to their waiting time in case the remainingProcTime is the same
# 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
# # TODO: the entities should be also sort according to their waiting time in case the ProcessingTimeInNextStation is the same
# 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
# # TODO: the entities should be also sort according to their waiting time in case the procTimeInNextStation is the same
# 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:
# 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
# # TODO: the entities should be also sort according to their waiting time in case the minimum slackness are the same
# 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())
# # TODO: the entities should be also sort according to their waiting time in case length of the following queues are the same
# activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].nextQueueLength)
# else:
# assert False, "Unknown scheduling criterion %r" % (criterion, )
\ No newline at end of file
return candidateEntity
\ No newline at end of file
......@@ -295,7 +295,7 @@ class RouterManaged(Router):
# and as the operators chooses the sorting of the queue (if they do reside in the same queue is not taken into account)
# sort the candidateEntities list of each operator according to its schedulingRule
for operator in [x for x in self.candidateOperators if x.candidateEntities]:
operator.sortCandidateEntities()
operator.sortEntities()
self.printTrace('candidateEntities for each operator',\
[(str(operator.id),[str(x.id) for x in operator.candidateEntities])
......
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