Commit 8486f6f2 authored by Georgios Dagkakis's avatar Georgios Dagkakis

SkilledOperatorRouter to be able to wait for machines to end and then force...

SkilledOperatorRouter to be able to wait for machines to end and then force assignment. First implementation
parent d3c8b1aa
...@@ -1172,13 +1172,23 @@ class Machine(CoreObject): ...@@ -1172,13 +1172,23 @@ class Machine(CoreObject):
if not self.currentOperator.onShift: if not self.currentOperator.onShift:
operator.timeLastShiftEnded=self.env.now operator.timeLastShiftEnded=self.env.now
operator.unAssign() # set the flag operatorAssignedTo to None operator.unAssign() # set the flag operatorAssignedTo to None
operator.workingStation=None
self.outputTrace(operator.name, "released from "+ self.objName) self.outputTrace(operator.name, "released from "+ self.objName)
# XXX in case of skilled operators which stay at the same station should that change # XXX in case of skilled operators which stay at the same station should that change
elif not self.checkForDedicatedOperators(): elif not operator.operatorDedicatedTo==self:
operator.unAssign() # set the flag operatorAssignedTo to None operator.unAssign() # set the flag operatorAssignedTo to None
self.outputTrace(operator.objName, "released from "+ self.objName) operator.workingStation=None
self.outputTrace(operator.name, "released from "+ self.objName)
# if the Router is expecting for signal send it
from Globals import G
from SkilledOperatorRouter import SkilledRouter
if G.Router.__class__ is SkilledRouter:
if G.Router.expectedFinishSignals:
if self.id in G.Router.expectedFinishSignalsDict:
signal=G.Router.expectedFinishSignalsDict[self.id]
self.sendSignal(receiver=G.Router, signal=signal)
else: else:
self.outputTrace(operator.objName, "ended a process in "+ self.objName) self.outputTrace(operator.name, "ended a process in "+ self.objName)
operator.totalWorkingTime+=self.env.now-operator.timeLastOperationStarted operator.totalWorkingTime+=self.env.now-operator.timeLastOperationStarted
self.broker.invoke() self.broker.invoke()
self.toBeOperated = False self.toBeOperated = False
......
...@@ -64,6 +64,8 @@ class Operator(ObjectResource): ...@@ -64,6 +64,8 @@ class Operator(ObjectResource):
# the station that the operator is assigned to # the station that the operator is assigned to
self.operatorAssignedTo=None self.operatorAssignedTo=None
# the station that the operator is dedicated to
self.operatorDedicatedTo=None
# the station the operator currently operating # the station the operator currently operating
self.workingStation=None self.workingStation=None
......
...@@ -59,6 +59,7 @@ class SkilledRouter(Router): ...@@ -59,6 +59,7 @@ class SkilledRouter(Router):
self.pendingQueues=[] self.pendingQueues=[]
self.pendingMachines=[] self.pendingMachines=[]
self.pendingObjects=[] self.pendingObjects=[]
self.previousSolution={}
# ======================================================================= # =======================================================================
# the run method # the run method
...@@ -194,7 +195,10 @@ class SkilledRouter(Router): ...@@ -194,7 +195,10 @@ class SkilledRouter(Router):
# TODO: a constant integer must be added to all WIP before provided to the opAss_LP # TODO: a constant integer must be added to all WIP before provided to the opAss_LP
# as it doesn't support zero WIP levels # as it doesn't support zero WIP levels
#=================================================================== #===================================================================
solution=opAss_LP(self.availableStationsDict, self.availableOperatorList, self.operators) solution=opAss_LP(self.availableStationsDict, self.availableOperatorList,
self.operators)
# print '-------'
# print self.env.now, solution
# XXX assign the operators to operatorPools # XXX assign the operators to operatorPools
# pendingStations/ available stations not yet given operator # pendingStations/ available stations not yet given operator
self.pendingStations=[] self.pendingStations=[]
...@@ -205,31 +209,60 @@ class SkilledRouter(Router): ...@@ -205,31 +209,60 @@ class SkilledRouter(Router):
# obtain the operator and the station # obtain the operator and the station
operator=findObjectById(operatorID) operator=findObjectById(operatorID)
station=findObjectById(solution[operatorID]) station=findObjectById(solution[operatorID])
if operatorID in self.previousSolution:
# if the solution returned the operator that is already in the station
# then no signal is needed
if not self.previousSolution[operatorID] == solution[operatorID]:
self.toBeSignalled.append(station)
else:
self.toBeSignalled.append(station)
# update the operatorPool of the station # update the operatorPool of the station
station.operatorPool.operators=[operator] station.operatorPool.operators=[operator]
# assign the operator to the station # assign the operator to the station
operator.assignTo(station) operator.assignTo(station)
# append the station to the ones that are to be signalled # set that the operator is dedicated to the station
self.toBeSignalled.append(station) operator.operatorDedicatedTo=station
# set in every station the operator that it is to get
station.operatorToGet=operator
# remove the operator id from availableOperatorList # remove the operator id from availableOperatorList
self.availableOperatorList.remove(operatorID) self.availableOperatorList.remove(operatorID)
#=================================================================== #===================================================================
# # XXX signal the stations that the assignment is complete # # XXX signal the stations that the assignment is complete
#=================================================================== #===================================================================
# the stations that
stationsProcessingLast=[]
for station in self.toBeSignalled: for station in self.toBeSignalled:
if station.broker.waitForOperator: # check if the operator that the station waits for is free
# signal this station's broker that the resource is available operator=station.operatorToGet
if station.broker.expectedSignals['resourceAvailable']: if operator.workingStation:
self.sendSignal(receiver=station.broker, signal=station.broker.resourceAvailable) if operator.workingStation.isProcessing:
self.printTrace('router', 'signalling broker of'+' '*50+station.id) stationsProcessingLast.append(operator.workingStation)
else: continue
# signal the queue proceeding the station # signal the station so that it gets the operator
if station.canAccept()\ self.signalStation(station, operator)
and any(type=='Load' for type in station.multOperationTypeList):
if station.expectedSignals['loadOperatorAvailable']: self.expectedFinishSignalsDict={}
self.sendSignal(receiver=station, signal=station.loadOperatorAvailable) self.expectedFinishSignals=[]
self.printTrace('router', 'signalling'+' '*50+station.id) for station in stationsProcessingLast:
signal=self.env.event()
self.expectedFinishSignalsDict[station.id]=signal
self.expectedFinishSignals.append(signal)
while self.expectedFinishSignals:
receivedEvent = yield self.env.any_of(self.expectedFinishSignals)
for signal in self.expectedFinishSignals:
if signal in receivedEvent:
transmitter, eventTime=signal.value
assert eventTime==self.env.now, 'the station finished signal must be received on the time of request'
self.expectedFinishSignals.remove(signal)
del self.expectedFinishSignalsDict[station.id]
for id in solution.keys():
operator=findObjectById(id)
station=findObjectById(solution[id])
operator.totalWorkingTime+=self.env.now-operator.timeLastOperationStarted
# signal the station so that it gets the operator
self.signalStation(station, operator)
#=================================================================== #===================================================================
# default behaviour # default behaviour
...@@ -264,10 +297,31 @@ class SkilledRouter(Router): ...@@ -264,10 +297,31 @@ class SkilledRouter(Router):
# signal the stations that ought to be signalled # signal the stations that ought to be signalled
self.signalOperatedStations() self.signalOperatedStations()
self.previousSolution=solution
self.printTrace('', 'router exiting') self.printTrace('', 'router exiting')
self.printTrace('','=-'*20) self.printTrace('','=-'*20)
self.exit() self.exit()
# =======================================================================
# signal the station or the Queue to impose the assignment
# =======================================================================
def signalStation(self, station, operator):
# signal this station's broker that the resource is available
if station.broker.waitForOperator:
if station.broker.expectedSignals['resourceAvailable']:
self.sendSignal(receiver=station.broker, signal=station.broker.resourceAvailable)
self.printTrace('router', 'signalling broker of'+' '*50+station.id)
self.toBeSignalled.remove(station)
# signal the queue proceeding the station
else:
if station.canAccept()\
and any(type=='Load' for type in station.multOperationTypeList):
if station.expectedSignals['loadOperatorAvailable']:
self.sendSignal(receiver=station, signal=station.loadOperatorAvailable)
self.printTrace('router', 'signalling'+' '*50+station.id)
self.toBeSignalled.remove(station)
# ======================================================================= # =======================================================================
# return control to the Machine.run # return control to the Machine.run
# ======================================================================= # =======================================================================
......
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