comments and TODOs added

parent 0b9d4fa0
...@@ -61,6 +61,8 @@ class Operator(Repairman): # XXX isn't it the other way around ? ...@@ -61,6 +61,8 @@ class Operator(Repairman): # XXX isn't it the other way around ?
# ======================================================================= # =======================================================================
# sorts the candidateEntities of the Operator according to the scheduling rule # sorts the candidateEntities of the Operator according to the scheduling rule
# TODO: clean the comments
# TODO: maybe the argument is not needed. the candidate entities is a variable of the object
# ======================================================================= # =======================================================================
def sortCandidateEntities(self, candidateEntities=[]): def sortCandidateEntities(self, candidateEntities=[]):
pass pass
...@@ -78,6 +80,7 @@ class Operator(Repairman): # XXX isn't it the other way around ? ...@@ -78,6 +80,7 @@ class Operator(Repairman): # XXX isn't it the other way around ?
# ======================================================================= # =======================================================================
# sorts the activeCallerrs of the Operator according to the scheduling rule # sorts the activeCallerrs of the Operator according to the scheduling rule
# TODO: change the name of the class (they are not entities)
# ======================================================================= # =======================================================================
def sortEntities(self): def sortEntities(self):
#if we have sorting according to multiple criteria we have to call the sorter many times #if we have sorting according to multiple criteria we have to call the sorter many times
......
...@@ -69,6 +69,7 @@ class OperatorManagedJob(Operator): ...@@ -69,6 +69,7 @@ class OperatorManagedJob(Operator):
# ======================================================================= # =======================================================================
# sorts the candidateEntities of the Operator according to the scheduling rule # 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, candidateEntities=[]): def sortCandidateEntities(self, candidateEntities=[]):
# TODO: have to consider what happens in case of a critical order # TODO: have to consider what happens in case of a critical order
...@@ -209,21 +210,21 @@ class OperatorManagedJob(Operator): ...@@ -209,21 +210,21 @@ class OperatorManagedJob(Operator):
for object in activeObjectQ: for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self) 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) activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].dueDate)
#if the schedulingRule is earliest order date #if the schedulingRule is earliest order date
elif criterion=="EOD": elif criterion=="EOD":
for object in activeObjectQ: for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self) 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) 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 #if the schedulingRule is to sort Entities according to the stations they have to visit
elif criterion=="NumStages": elif criterion=="NumStages":
for object in activeObjectQ: for object in activeObjectQ:
object.giver.sortEntitiesForOperator(self) 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) 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 #if the schedulingRule is to sort Entities according to the their remaining processing time in the system
elif criterion=="RPC": elif criterion=="RPC":
...@@ -239,6 +240,7 @@ class OperatorManagedJob(Operator): ...@@ -239,6 +240,7 @@ class OperatorManagedJob(Operator):
if processingTime: if processingTime:
RPT+=float(processingTime.get('mean',0)) RPT+=float(processingTime.get('mean',0))
entity.remainingProcessingTime=RPT 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) 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 #if the schedulingRule is to sort Entities according to longest processing time first in the next station
elif criterion=="LPT": elif criterion=="LPT":
...@@ -254,6 +256,7 @@ class OperatorManagedJob(Operator): ...@@ -254,6 +256,7 @@ class OperatorManagedJob(Operator):
entity.processingTimeInNextStation=float(processingTime.get('mean',0)) entity.processingTimeInNextStation=float(processingTime.get('mean',0))
else: else:
entity.processingTimeInNextStation=0 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) 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 #if the schedulingRule is to sort Entities according to shortest processing time first in the next station
elif criterion=="SPT": elif criterion=="SPT":
...@@ -268,6 +271,7 @@ class OperatorManagedJob(Operator): ...@@ -268,6 +271,7 @@ class OperatorManagedJob(Operator):
entity.processingTimeInNextStation=float(processingTime.get('mean',0)) entity.processingTimeInNextStation=float(processingTime.get('mean',0))
else: else:
entity.processingTimeInNextStation=0 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) activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].processingTimeInNextStation)
#if the schedulingRule is to sort Entities based on the minimum slackness #if the schedulingRule is to sort Entities based on the minimum slackness
elif criterion=="MS": elif criterion=="MS":
...@@ -283,6 +287,7 @@ class OperatorManagedJob(Operator): ...@@ -283,6 +287,7 @@ class OperatorManagedJob(Operator):
if processingTime: if processingTime:
RPT+=float(processingTime.get('mean',0)) RPT+=float(processingTime.get('mean',0))
entity.remainingProcessingTime=RPT 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)) 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 #if the schedulingRule is to sort Entities based on the length of the following Queue
elif criterion=="WINQ": elif criterion=="WINQ":
...@@ -298,6 +303,7 @@ class OperatorManagedJob(Operator): ...@@ -298,6 +303,7 @@ class OperatorManagedJob(Operator):
if obj.id in nextObjIds: if obj.id in nextObjIds:
nextObject=obj nextObject=obj
entity.nextQueueLength=len(nextObject.getActiveObjectQueue()) 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) activeObjectQ.sort(key=lambda x: x.giver.getActiveObjectQueue()[0].nextQueueLength)
else: else:
assert False, "Unknown scheduling criterion %r" % (criterion, ) assert False, "Unknown scheduling criterion %r" % (criterion, )
\ No newline at end of file
...@@ -102,6 +102,7 @@ class Router(ObjectInterruption): ...@@ -102,6 +102,7 @@ class Router(ObjectInterruption):
# # TESTING # # TESTING
# print ' {} the candidateOperators ', # print ' {} the candidateOperators ',
# print [str(op.id) for op in self.candidateOperators] # print [str(op.id) for op in self.candidateOperators]
# print [str(entity.id) for entity in G.pendingEntities]
#=================================================================== #===================================================================
# sort the pendingEntities list # sort the pendingEntities list
...@@ -109,6 +110,7 @@ class Router(ObjectInterruption): ...@@ -109,6 +110,7 @@ class Router(ObjectInterruption):
#=================================================================== #===================================================================
# # TESTING # # TESTING
# print [str(entity.id) for entity in G.pendingEntities]
# if G.pendingEntities: # if G.pendingEntities:
# print ' {} the pending entities that can proceed are: ', # print ' {} the pending entities that can proceed are: ',
# print [str(entity.id) for entity in G.pendingEntities if entity.canProceed] # print [str(entity.id) for entity in G.pendingEntities if entity.canProceed]
...@@ -161,10 +163,12 @@ class Router(ObjectInterruption): ...@@ -161,10 +163,12 @@ class Router(ObjectInterruption):
# sort the activeCallersList of the operator # sort the activeCallersList of the operator
operator.sortEntities() operator.sortEntities()
# find the activeCaller that has priority # find the activeCaller that has priority
priorityObject=next(x for x in operator.activeCallersList if x in self.pendingObjects) priorityObject=next(x for x in operator.activeCallersList if x in self.pendingObjects)
#=========================================================== #===========================================================
# # TESTING # # TESTING
# print [str(caller.id) for caller in operator.activeCallersList]
# print ' the PRIORITY object is', priorityObject.id # print ' the PRIORITY object is', priorityObject.id
#=========================================================== #===========================================================
...@@ -281,6 +285,11 @@ class Router(ObjectInterruption): ...@@ -281,6 +285,11 @@ class Router(ObjectInterruption):
#======================================================================= #=======================================================================
def sortPendingEntities(self): def sortPendingEntities(self):
# TODO: to be used for sorting of operators # TODO: to be used for sorting of operators
# there must be also a schedulingRule property for the Router
# there must also be a way to have multiple criteria for the operators (eg MC-Priority-WT)
# WT may be needed to be applied everywhere
# TODO: move that piece of code elsewhere, it doesn't look nice here. and there is not point in doing it here
# maybe it's better in findCandidateOperators method
if self.candidateOperators: if self.candidateOperators:
for operator in self.candidateOperators: for operator in self.candidateOperators:
if operator.multipleCriterionList: if operator.multipleCriterionList:
...@@ -396,9 +405,10 @@ class Router(ObjectInterruption): ...@@ -396,9 +405,10 @@ class Router(ObjectInterruption):
# finally we have to sort before giving the entities to the operators # finally we have to sort before giving the entities to the operators
# If there is an entity which must have priority then it should be assigned first # If there is an entity which must have priority then it should be assigned first
#local method that finds a candidate entity for an operator
def findCandidateEntity(): def findCandidateEntity():
return next(x for x in operator.candidateEntities if not x in entitiesWithOccupiedReceivers) return next(x for x in operator.candidateEntities if not x in entitiesWithOccupiedReceivers)
#local method that finds a receiver for a candidate entity
def findCandidateReceiver(): def findCandidateReceiver():
# initiate the local list variable available receivers # initiate the local list variable available receivers
availableReceivers=[x for x in operator.candidateEntity.candidateReceivers\ availableReceivers=[x for x in operator.candidateEntity.candidateReceivers\
...@@ -458,8 +468,10 @@ class Router(ObjectInterruption): ...@@ -458,8 +468,10 @@ class Router(ObjectInterruption):
#======================================================================= #=======================================================================
# Sort Givers # Sort Givers
# TODO: the method currently checks only the first operator of the candidateOperators list # TODO: the queues of the candidate givers are sorted only if their receiver is not in activeCallersList
# consider populating the controls # if an operator is called the control returns to the generator of the Router (run())
# the next objects are not checked
# They must be control
#======================================================================= #=======================================================================
def sortGiverQueue(self): def sortGiverQueue(self):
# for those operators that do have candidateEntity # for those operators that do have candidateEntity
...@@ -479,6 +491,7 @@ class Router(ObjectInterruption): ...@@ -479,6 +491,7 @@ class Router(ObjectInterruption):
# ======================================================================= # =======================================================================
# sorts the Entities of the Queue according to the scheduling rule # sorts the Entities of the Queue according to the scheduling rule
# TODO: refine the criteria
# ======================================================================= # =======================================================================
def activePendingQSorter(self, criterion=None): def activePendingQSorter(self, criterion=None):
from Globals import G from Globals import G
...@@ -489,7 +502,7 @@ class Router(ObjectInterruption): ...@@ -489,7 +502,7 @@ class Router(ObjectInterruption):
criterion=self.schedulingRule criterion=self.schedulingRule
#if the schedulingRule is first in first out #if the schedulingRule is first in first out
if criterion=="FIFO": if criterion=="FIFO":
# FIFO sorting has no meaning when sorting candidateEntities # TODO: FIFO sorting has no meaning when sorting candidateEntities
self.activePendingQSorter('WT') self.activePendingQSorter('WT')
# added for testing # added for testing
# print 'there is no point of using FIFO scheduling rule for operators candidateEntities,\ # print 'there is no point of using FIFO scheduling rule for operators 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