Commit e893b799 authored by Georgios Dagkakis's avatar Georgios Dagkakis

comments and cleanup

parent fb9351f3
...@@ -1118,7 +1118,7 @@ class Machine(CoreObject): ...@@ -1118,7 +1118,7 @@ class Machine(CoreObject):
# find an available operator # find an available operator
candidateOperator=self.operatorPool.findAvailableOperator() candidateOperator=self.operatorPool.findAvailableOperator()
# append the station into its candidateStations # append the station into its candidateStations
if candidateOperator: if candidateOperator: # if there was an operator found append the Machine on his candidateStations
candidateOperator.candidateStations.append(self) candidateOperator.candidateStations.append(self)
return candidateOperator return candidateOperator
......
...@@ -58,12 +58,14 @@ class ObjectResource(ManPyObject): ...@@ -58,12 +58,14 @@ class ObjectResource(ManPyObject):
self.coreObjectIds=[] self.coreObjectIds=[]
# list with the coreObjects that the resource services # list with the coreObjects that the resource services
self.coreObjects=[] self.coreObjects=[]
# flag that shows if the resourse is on shift
self.onShift=True self.onShift=True
# ======================================================================= # =======================================================================
# checks if the worker is available # checks if the worker is available
# ======================================================================= # =======================================================================
def checkIfResourceIsAvailable(self,callerObject=None): def checkIfResourceIsAvailable(self,callerObject=None):
# return true if the operator is idle and on shift
return len(self.Res.users)<self.capacity and self.onShift return len(self.Res.users)<self.capacity and self.onShift
......
...@@ -99,7 +99,6 @@ class OperatorPool(ObjectResource): ...@@ -99,7 +99,6 @@ class OperatorPool(ObjectResource):
# ======================================================================= # =======================================================================
def findAvailableOperator(self): # may need to implement different sorting of the operators def findAvailableOperator(self): # may need to implement different sorting of the operators
# find the free operator if any # find the free operator if any
# freeOperator = next(x for x in self.operators if x.checkIfResourceIsAvailable())
freeOperator = None freeOperator = None
for operator in self.operators: for operator in self.operators:
if operator.checkIfResourceIsAvailable(): if operator.checkIfResourceIsAvailable():
......
...@@ -321,6 +321,7 @@ class Router(ObjectInterruption): ...@@ -321,6 +321,7 @@ class Router(ObjectInterruption):
for object in self.pendingMachines: for object in self.pendingMachines:
# find candidateOperators for each object operator # find candidateOperators for each object operator
candidateOperator=object.findCandidateOperator() candidateOperator=object.findCandidateOperator()
# if there is candidateOperator that is not already in self.candidateOperators add him
# TODO: this way no sorting is performed # TODO: this way no sorting is performed
if candidateOperator and (not candidateOperator in self.candidateOperators): if candidateOperator and (not candidateOperator in self.candidateOperators):
self.candidateOperators.append(candidateOperator) self.candidateOperators.append(candidateOperator)
...@@ -357,6 +358,7 @@ class Router(ObjectInterruption): ...@@ -357,6 +358,7 @@ class Router(ObjectInterruption):
# update the schedulingRule/multipleCriterionList of the Router # update the schedulingRule/multipleCriterionList of the Router
if self.sorting: if self.sorting:
self.updateSchedulingRule() self.updateSchedulingRule()
# if there are candidate operators
if self.candidateOperators: if self.candidateOperators:
self.printTrace('router found candidate operators'+' '*3, self.printTrace('router found candidate operators'+' '*3,
[(operator.id, [station.id for station in operator.candidateStations]) for operator in self.candidateOperators]) [(operator.id, [station.id for station in operator.candidateStations]) for operator in self.candidateOperators])
......
...@@ -67,7 +67,10 @@ class ShiftScheduler(ObjectInterruption): ...@@ -67,7 +67,10 @@ class ShiftScheduler(ObjectInterruption):
# if in the beginning the victim is offShift set it as such # if in the beginning the victim is offShift set it as such
if float(self.remainingShiftPattern[0][0])!=self.env.now: if float(self.remainingShiftPattern[0][0])!=self.env.now:
self.victim.onShift=False self.victim.onShift=False
# if the victim is CoreObject interrupt it. Else ask the router for allocation of operators
# TODO more generic implementation
if issubclass(self.victim.__class__, CoreObject): if issubclass(self.victim.__class__, CoreObject):
# interrupt the victim only if it was not previously interrupted
if not self.victim.interruptionStart.triggered: if not self.victim.interruptionStart.triggered:
self.interruptVictim() # interrupt the victim self.interruptVictim() # interrupt the victim
else: else:
...@@ -79,6 +82,8 @@ class ShiftScheduler(ObjectInterruption): ...@@ -79,6 +82,8 @@ class ShiftScheduler(ObjectInterruption):
while 1: while 1:
if not self.victim.onShift: if not self.victim.onShift:
yield self.env.timeout(float(self.remainingShiftPattern[0][0]-self.env.now)) # wait for the onShift yield self.env.timeout(float(self.remainingShiftPattern[0][0]-self.env.now)) # wait for the onShift
# if the victim is CoreObject reactivate it. Else ask the router for allocation of operators
# TODO more generic implementation
if issubclass(self.victim.__class__, CoreObject): if issubclass(self.victim.__class__, CoreObject):
self.reactivateVictim() # re-activate the victim in case it was interrupted self.reactivateVictim() # re-activate the victim in case it was interrupted
else: else:
...@@ -124,8 +129,10 @@ class ShiftScheduler(ObjectInterruption): ...@@ -124,8 +129,10 @@ class ShiftScheduler(ObjectInterruption):
succeedTuple=(self, self.env.now) succeedTuple=(self, self.env.now)
oi.victimOffShift.succeed(succeedTuple) oi.victimOffShift.succeed(succeedTuple)
# interrupt the victim only if it was not previously interrupted # if the victim is CoreObject interrupt it. Else ask the router for allocation of operators
# TODO more generic implementation
if issubclass(self.victim.__class__, CoreObject): if issubclass(self.victim.__class__, CoreObject):
# interrupt the victim only if it was not previously interrupted
if not self.victim.interruptionStart.triggered: if not self.victim.interruptionStart.triggered:
self.interruptVictim() # interrupt the victim self.interruptVictim() # interrupt the victim
else: else:
......
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