Commit 3a1323c0 authored by Georgios Dagkakis's avatar Georgios Dagkakis

first attempt to make Operator working with shifts

parent 250e7090
......@@ -1118,6 +1118,7 @@ class Machine(CoreObject):
# find an available operator
candidateOperator=self.operatorPool.findAvailableOperator()
# append the station into its candidateStations
if candidateOperator:
candidateOperator.candidateStations.append(self)
return candidateOperator
......
......@@ -58,12 +58,13 @@ class ObjectResource(ManPyObject):
self.coreObjectIds=[]
# list with the coreObjects that the resource services
self.coreObjects=[]
self.onShift=True
# =======================================================================
# checks if the worker is available
# =======================================================================
def checkIfResourceIsAvailable(self,callerObject=None):
return len(self.Res.users)<self.capacity
return len(self.Res.users)<self.capacity and self.onShift
# =======================================================================
......
......@@ -99,7 +99,12 @@ class OperatorPool(ObjectResource):
# =======================================================================
def findAvailableOperator(self): # may need to implement different sorting of the operators
# find the free operator if any
freeOperator = next(x for x in self.operators if x.checkIfResourceIsAvailable())
# freeOperator = next(x for x in self.operators if x.checkIfResourceIsAvailable())
freeOperator = None
for operator in self.operators:
if operator.checkIfResourceIsAvailable():
freeOperator=operator
break
return freeOperator
# =======================================================================
......
......@@ -322,7 +322,7 @@ class Router(ObjectInterruption):
# find candidateOperators for each object operator
candidateOperator=object.findCandidateOperator()
# TODO: this way no sorting is performed
if not candidateOperator in self.candidateOperators:
if candidateOperator and (not candidateOperator in self.candidateOperators):
self.candidateOperators.append(candidateOperator)
# for each pendingQueue
for object in self.pendingQueues:
......@@ -357,8 +357,11 @@ class Router(ObjectInterruption):
# update the schedulingRule/multipleCriterionList of the Router
if self.sorting:
self.updateSchedulingRule()
if self.candidateOperators:
self.printTrace('router found candidate operators'+' '*3,
[(operator.id, [station.id for station in operator.candidateStations]) for operator in self.candidateOperators])
else:
self.printTrace('router', 'found NO candidate operators')
#===========================================================================
# find the candidate entities for each candidateOperator
......
......@@ -60,20 +60,29 @@ class ShiftScheduler(ObjectInterruption):
# The run method for the failure which has to served by a repairman
# =======================================================================
def run(self):
from CoreObject import CoreObject
# the victim should not be interrupted but the scheduler should wait for the processing to finish before the stations turns to off-shift mode
self.victim.totalOffShiftTime=0
self.victim.timeLastShiftEnded=self.env.now
# if in the beginning the victim is offShift set it as such
if float(self.remainingShiftPattern[0][0])!=self.env.now:
self.victim.onShift=False
self.interruptVictim() # interrupt processing operations if any
if issubclass(self.victim.__class__, CoreObject):
if not self.victim.interruptionStart.triggered:
self.interruptVictim() # interrupt the victim
else:
CoreObject.requestAllocation()
self.victim.timeLastShiftEnded=self.env.now
self.outputTrace(self.victim.name,"is off shift")
while 1:
if not self.victim.onShift:
yield self.env.timeout(float(self.remainingShiftPattern[0][0]-self.env.now)) # wait for the onShift
if issubclass(self.victim.__class__, CoreObject):
self.reactivateVictim() # re-activate the victim in case it was interrupted
else:
CoreObject.requestAllocation()
# if the victim has interruptions that measure only the on-shift time, they have to be notified
for oi in self.victim.objectInterruptions:
......@@ -116,8 +125,12 @@ class ShiftScheduler(ObjectInterruption):
oi.victimOffShift.succeed(succeedTuple)
# interrupt the victim only if it was not previously interrupted
if issubclass(self.victim.__class__, CoreObject):
if not self.victim.interruptionStart.triggered:
self.interruptVictim() # interrupt the victim
else:
CoreObject.requestAllocation()
self.victim.onShift=False # get the victim off-shift
self.victim.timeLastShiftEnded=self.env.now
self.outputTrace(self.victim.name,"is off shift")
......
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