Commit b92b8b78 authored by Georgios Dagkakis's avatar Georgios Dagkakis

FIXUPS: Batches: implementation of where-to (max WIP) rule

parent 3bc88530
...@@ -216,16 +216,25 @@ class SkilledRouter(Router): ...@@ -216,16 +216,25 @@ class SkilledRouter(Router):
import time import time
startLP=time.time() startLP=time.time()
if LPFlag: if LPFlag:
# XXX if the solution is empty, how do we allocate?
if self.whereToMaxWIP and self.previousSolution: if self.whereToMaxWIP and self.previousSolution:
self.logger.info('------> %s' % self.env.now) self.logger.info('---> ' + str(self.env.now))
solution={} solution={}
maxWIP=-1 maxWIP=-1
minWIP=float('inf') minWIP=float('inf')
machineWithMaxWIP=None machineWithMaxWIP=None
operatorToMove=None operatorToMove=None
# Sort so that the ones closer to end win in ties
sorted_station_id_list = sorted(
self.availableStationsDict.keys(),
key=lambda x: int(x[0]), reverse=True
)
# first, find the machine with max wip # first, find the machine with max wip
for stationId, stationDict in self.availableStationsDict.iteritems(): for stationId in sorted_station_id_list:
stationDict = self.availableStationsDict.get(stationId, None)
self.logger.info(stationDict)
if not stationDict:
continue
wip = stationDict['WIP'] wip = stationDict['WIP']
assignedOperatorList=[ assignedOperatorList=[
x for x in self.previousSolution \ x for x in self.previousSolution \
...@@ -233,14 +242,18 @@ class SkilledRouter(Router): ...@@ -233,14 +242,18 @@ class SkilledRouter(Router):
and x in self.availableOperatorList and x in self.availableOperatorList
] ]
assert len(assignedOperatorList) in (0, 1), assignedOperatorList assert len(assignedOperatorList) in (0, 1), assignedOperatorList
if not assignedOperatorList:
self.logger.info('%s has no operator' % stationId)
if wip > maxWIP and not assignedOperatorList: if wip > maxWIP and not assignedOperatorList:
machineWithMaxWIP=stationId machineWithMaxWIP=stationId
maxWIP = wip
self.logger.info(machineWithMaxWIP)
solution={} solution={}
# First, search for an operator that was not # First, search for an operator that was not
# previously assigned, and can handle the maxWIP station # previously assigned, and can handle the maxWIP station
for operatorId in self.availableOperatorList: for operatorId in self.availableOperatorList:
if operatorId not in self.previousSolution \ if operatorId not in self.previousSolution \
and self.availableStationsDict[machineWithMaxWIP]['stationID'] in self.operators.get('operatorId', []): and self.availableStationsDict[machineWithMaxWIP]['stationID'] in self.operators.get(operatorId, []):
operatorToMove = operatorId operatorToMove = operatorId
# Then, search for the machine with Min WIP that has skill for # Then, search for the machine with Min WIP that has skill for
# maxWIP station # maxWIP station
...@@ -252,18 +265,23 @@ class SkilledRouter(Router): ...@@ -252,18 +265,23 @@ class SkilledRouter(Router):
if self.previousSolution[x] == stationId \ if self.previousSolution[x] == stationId \
and x in self.availableOperatorList and x in self.availableOperatorList
] ]
assert len(assignedOperatorList) in (0, 1), assignedOperatorList
if wip < minWIP and assignedOperatorList \ if wip < minWIP and assignedOperatorList \
and self.availableStationsDict[machineWithMaxWIP]['stationID']: and self.availableStationsDict[machineWithMaxWIP]['stationID'] in self.operators.get(assignedOperatorList[0], []):
operatorToMove=assignedOperatorList[0] operatorToMove=assignedOperatorList[0]
minWIP = wip
# Copy previous solution for available operators # Copy previous solution for available operators
for operatorId, stationId in self.previousSolution.iteritems(): for operatorId, stationId in self.previousSolution.iteritems():
if operatorId in self.availableOperatorList: if operatorId in self.availableOperatorList:
solution[operatorId]=self.previousSolution[operatorId] solution[operatorId]=self.previousSolution[operatorId]
# move the operator that was identified to be moved to maxWIP # move the operator that was identified to be moved to maxWIP
if operatorToMove and machineWithMaxWIP: if operatorToMove and machineWithMaxWIP and maxWIP >= minWIP:
solution[operatorToMove]=machineWithMaxWIP solution[operatorToMove]=machineWithMaxWIP
self.logger.info('moved %s to %s' % (operatorToMove, machineWithMaxWIP)) self.logger.info('moved %s from %s to %s' % (
self.logger.info(solution) operatorToMove,
self.previousSolution.get(operatorToMove, 'idle'),
machineWithMaxWIP
))
else: else:
if self.twoPhaseSearch: if self.twoPhaseSearch:
# remove all the blocked machines from the available stations # remove all the blocked machines from the available stations
......
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