Commit 74f8e6dc authored by Georgios Dagkakis's avatar Georgios Dagkakis

new version of algorithm copied

parent 8c8ef0db
...@@ -23,12 +23,13 @@ Created on 15 Dec 2014 ...@@ -23,12 +23,13 @@ Created on 15 Dec 2014
@author: Anna @author: Anna
''' '''
from AllocationRoutine_2 import AllocationRoutine2 from AllocationRoutine_Final2 import AllocationRoutine_Final
from AllocationRoutine_Forecast import AllocationRoutine_Forecast from AllocationRoutine_Forecast import AllocationRoutine_Forecast
from Allocation_GA import Allocation_GA from Allocation_GA import Allocation_GA
from Allocation_ACO import Allocation_ACO from Allocation_ACO import Allocation_ACO
from Globals import G from Globals import G
import tablib import tablib
from copy import deepcopy
def AllocManagement_Hybrid(): def AllocManagement_Hybrid():
...@@ -62,7 +63,7 @@ def AllocManagement_Hybrid(): ...@@ -62,7 +63,7 @@ def AllocManagement_Hybrid():
def AllocManagement_Hybrid2(): def AllocManagement_Hybrid2(bestAnt):
# allocate items based on type and priority level # allocate items based on type and priority level
...@@ -70,7 +71,7 @@ def AllocManagement_Hybrid2(): ...@@ -70,7 +71,7 @@ def AllocManagement_Hybrid2():
ACOresults = tablib.Dataset(title='ACO_'+'order'+'_'+str(priority)) ACOresults = tablib.Dataset(title='ACO_'+'order'+'_'+str(priority))
ACOresults.headers = ('Week', 'generation', 'replication', 'antID', 'excess', 'lateness', 'earliness', 'targetUtil', 'minUtil') ACOresults.headers = ('Week', 'generation', 'replication', 'antID', 'excess', 'lateness', 'earliness', 'targetUtil', 'minUtil')
resAnt = {}
# starting from first week in planning horizon, complete the allocation of all orders within the same priority group # starting from first week in planning horizon, complete the allocation of all orders within the same priority group
for week in G.WeekList: for week in G.WeekList:
...@@ -80,12 +81,25 @@ def AllocManagement_Hybrid2(): ...@@ -80,12 +81,25 @@ def AllocManagement_Hybrid2():
if G.ACOdefault: if G.ACOdefault:
G.popSize = int(0.75*len(G.sortedOrders['order'][priority][week]) - 0.75*len(G.sortedOrders['order'][priority][week])%2) G.popSize = int(0.75*len(G.sortedOrders['order'][priority][week]) - 0.75*len(G.sortedOrders['order'][priority][week])%2)
G.noGen = 20*G.popSize G.noGen = 20*G.popSize
ACOresults = Allocation_ACO(week, G.sortedOrders['order'][priority][week],'order',ACOresults) ACOresults, anting = Allocation_ACO(week, G.sortedOrders['order'][priority][week],'order',ACOresults)
z=resAnt.copy()
z.update(anting)
resAnt = deepcopy(z)
else: else:
AllocationRoutine2(week, G.sortedOrders['order'][priority][week],'order') if bestAnt!=None:
AllocationRoutine_Final(week, G.sortedOrders['order'][priority][week],'order',bestAnt)
else:
AllocationRoutine_Final(week, G.sortedOrders['order'][priority][week],'order',0)
if G.ACO: if G.ACO:
G.reportResults.add_sheet(ACOresults) G.reportResults.add_sheet(ACOresults)
return resAnt
else:
return None
def AllocManagement_Hybrid2_Forecast():
print 'start forecast allocation' print 'start forecast allocation'
for priority in G.priorityList['forecast']: for priority in G.priorityList['forecast']:
...@@ -120,6 +134,3 @@ def AllocManagement_Hybrid2(): ...@@ -120,6 +134,3 @@ def AllocManagement_Hybrid2():
AllocationRoutine_Forecast(week,orderList,'forecast',{'seq':orderIDlist}) AllocationRoutine_Forecast(week,orderList,'forecast',{'seq':orderIDlist})
if G.GA:
G.reportResults.add_sheet(GAresults)
...@@ -27,10 +27,11 @@ from Globals import G ...@@ -27,10 +27,11 @@ from Globals import G
from pulp import * from pulp import *
from os import remove from os import remove
from glob import glob from glob import glob
from time import time
def Allocation_IP(item, week, previousAss, capacity, weightFactor): def Allocation_IP(item, week, previousAss, capacity, weightFactor):
startLP = time()
MAlist = item['MAlist'] MAlist = item['MAlist']
# calculate number of units to be allocated # calculate number of units to be allocated
...@@ -55,7 +56,8 @@ def Allocation_IP(item, week, previousAss, capacity, weightFactor): ...@@ -55,7 +56,8 @@ def Allocation_IP(item, week, previousAss, capacity, weightFactor):
# first objective: max SP units allocated to a week # first objective: max SP units allocated to a week
BS = [float(G.BatchSize[ma][week]) for ma in MAlist] BS = [float(G.BatchSize[ma][week]) for ma in MAlist]
h1=[MA_var[ma]*(weightFactor[0]/min(BS)) for ma in MAlist] if weightFactor[0]:
h1=[MA_var[ma]*(weightFactor[0]*min(BS)/allQty) for ma in MAlist]
# print 'h1', h1, allQty # print 'h1', h1, allQty
#_________________________________________________ #_________________________________________________
...@@ -81,44 +83,48 @@ def Allocation_IP(item, week, previousAss, capacity, weightFactor): ...@@ -81,44 +83,48 @@ def Allocation_IP(item, week, previousAss, capacity, weightFactor):
utilisation[bottleneck] = 1.0/float(G.Capacity[bottleneck][week]['OriginalCapacity']) *capDict_obj[bottleneck] utilisation[bottleneck] = 1.0/float(G.Capacity[bottleneck][week]['OriginalCapacity']) *capDict_obj[bottleneck]
Util[bottleneck] = utilisation[bottleneck]*-1 Util[bottleneck] = utilisation[bottleneck]*-1
# delta target utilisation calculation (through definition of constraints) # delta target utilisation calculation (through definition of constraints)
prob += lpSum([(utilisation[bottleneck] - G.Capacity[bottleneck][week]['targetUtilisation'])/float(G.Capacity[bottleneck][week]['targetUtilisation'])]) >= Delta_targetUt[bottleneck] prob += lpSum([(utilisation[bottleneck] - G.Capacity[bottleneck][week]['targetUtilisation'])/float(G.Capacity[bottleneck][week]['targetUtilisation'])]) >= Delta_targetUt[bottleneck]
prob += lpSum([(G.Capacity[bottleneck][week]['targetUtilisation'] - utilisation[bottleneck])/float(G.Capacity[bottleneck][week]['targetUtilisation'])]) >= Delta_targetUt[bottleneck] prob += lpSum([(G.Capacity[bottleneck][week]['targetUtilisation'] - utilisation[bottleneck])/float(G.Capacity[bottleneck][week]['targetUtilisation'])]) >= Delta_targetUt[bottleneck]
h1.append(Util[bottleneck]*weightFactor[1] for bottleneck in G.Bottlenecks) if weightFactor[1]:
h1.append(Delta_targetUt[bottleneck]*weightFactor[2] for bottleneck in G.Bottlenecks) h1+=[Util[bottleneck]*weightFactor[1] for bottleneck in G.Bottlenecks]
if weightFactor[2]:
# third set of variables (Delta_Ut represents the delta between target utilisation h1+=[Delta_targetUt[bottleneck]*weightFactor[2] for bottleneck in G.Bottlenecks]
Delta_Ut = LpVariable.dicts("DeltaTarget",[(b1,b2) for i1, b1 in enumerate(G.Bottlenecks) for b2 in G.Bottlenecks[i1+1:]])
for i1, b1 in enumerate(G.Bottlenecks):
for b2 in G.Bottlenecks[i1+1:]:
prob += lpSum([Util[b1],-1*Util[b2]]) >= Delta_Ut[(b1,b2)]
prob += lpSum([Util[b2],-1*Util[b1]]) >= Delta_Ut[(b1,b2)]
#prob += lpSum([Delta_targetUt[b1],-1*Delta_targetUt[b2]]) >= Delta_Ut[(b1,b2)]
#prob += lpSum([Delta_targetUt[b2], -1*Delta_targetUt[b1]]) >= Delta_Ut[(b1,b2)]
# aggregate objective # aggregate objective
h1.append(Delta_Ut[(b1,b2)]*weightFactor[3] for i1, b1 in enumerate(G.Bottlenecks) for b2 in G.Bottlenecks[i1+1:]) if weightFactor[3]:
# third set of variables (Delta_Ut represents the delta between target utilisation
Delta_Ut = LpVariable.dicts("DeltaTarget",[(b1,b2) for i1, b1 in enumerate(G.Bottlenecks) for b2 in G.Bottlenecks[i1+1:]])
for i1, b1 in enumerate(G.Bottlenecks):
for b2 in G.Bottlenecks[i1+1:]:
prob += lpSum([Util[b1],-1*Util[b2]]) >= Delta_Ut[(b1,b2)]
prob += lpSum([Util[b2],-1*Util[b1]]) >= Delta_Ut[(b1,b2)]
#prob += lpSum([Delta_targetUt[b1],-1*Delta_targetUt[b2]]) >= Delta_Ut[(b1,b2)]
#prob += lpSum([Delta_targetUt[b2], -1*Delta_targetUt[b1]]) >= Delta_Ut[(b1,b2)]
h1+=[Delta_Ut[(b1,b2)]*weightFactor[3] for i1, b1 in enumerate(G.Bottlenecks) for b2 in G.Bottlenecks[i1+1:]]
#___________________________________________________________________________________ #___________________________________________________________________________________
# third objective: support proportional disaggregation of SP into corresponding MAs # third objective: support proportional disaggregation of SP into corresponding MAs
# create set of variables reporting the delta assignment across the MAs belonging to a SP if weightFactor[4]:
Delta_MA = LpVariable.dicts("SPdistribution",MAlist) # create set of variables reporting the delta assignment across the MAs belonging to a SP
Delta_MA = LpVariable.dicts("SPdistribution",MAlist)
# calculate the delta assignment of MAs corresponding to SPs (through constraints)
for ma in MAlist: # calculate the delta assignment of MAs corresponding to SPs (through constraints)
if ma in item['suggestedMA']: for ma in MAlist:
prob += lpSum((previousAss[ma] + MA_var[ma] * G.BatchSize[ma][week] - item['suggestedMA'][ma])/ item['Qty']) >= Delta_MA[ma] if ma in item['suggestedMA']:
prob += lpSum((item['suggestedMA'][ma] - previousAss[ma] - MA_var[ma] * G.BatchSize[ma][week])/ item['Qty']) >= Delta_MA[ma] prob += lpSum((previousAss[ma] + MA_var[ma] * G.BatchSize[ma][week] - item['suggestedMA'][ma])/ item['Qty']) >= Delta_MA[ma]
prob += lpSum((item['suggestedMA'][ma] - previousAss[ma] - MA_var[ma] * G.BatchSize[ma][week])/ item['Qty']) >= Delta_MA[ma]
h1+=[Delta_MA[ma]*weightFactor[4] for ma in MAlist]
#_____________________________ #_____________________________
# aggregate and set objectives # aggregate and set objectives
h1.append(Delta_MA[ma]*0.5 for ma in MAlist)
prob += lpSum(h1) prob += lpSum(h1)
...@@ -141,10 +147,15 @@ def Allocation_IP(item, week, previousAss, capacity, weightFactor): ...@@ -141,10 +147,15 @@ def Allocation_IP(item, week, previousAss, capacity, weightFactor):
prob.writeLP("IPifx.lp") prob.writeLP("IPifx.lp")
prob.solve() prob.solve()
print 'lp results', item['sp'], allQty, LpStatus[prob.status], sum(MA_var[ma].varValue* G.BatchSize[ma][week] for ma in MAlist)
allocation = {} allocation = {}
for ma in MAlist: for ma in MAlist:
allocation[ma] = MA_var[ma].varValue * G.BatchSize[ma][week] allocation[ma] = MA_var[ma].varValue * G.BatchSize[ma][week]
# print ma, MA_var[ma].varValue
if LpStatus[prob.status] != 'Optimal':
print 'WARNING: LP solution ', LpStatus[prob.status]
# remove lp files # remove lp files
files = glob('*.mps') files = glob('*.mps')
...@@ -155,4 +166,5 @@ def Allocation_IP(item, week, previousAss, capacity, weightFactor): ...@@ -155,4 +166,5 @@ def Allocation_IP(item, week, previousAss, capacity, weightFactor):
for f in files: for f in files:
remove(f) remove(f)
return allocation G.LPtime += startLP
return allocation, LpStatus[prob.status]
...@@ -25,19 +25,19 @@ Created on 28 Jan 2015 ...@@ -25,19 +25,19 @@ Created on 28 Jan 2015
from Globals import G from Globals import G
from Allocation_3 import Allocation2 from Allocation_3 import Allocation2
from UtilisationCalculation import utilisationCalc2, utilisationCalc1 from UtilisationCalculation import utilisationCalc2, utilisationCalc1, utilisationCalc3
from copy import deepcopy from copy import deepcopy
# allocates orders of a give week/priority level implementing the ant choice for MAs # allocates orders of a give week/priority level implementing the ant choice for MAs
def AllocationRoutine_ACO(initialWeek, itemList, itemType, ant): def AllocationRoutine_ACO(initialWeek, itemList, itemType, ant):
ACOexcess = 0
ACOcapacityDict = deepcopy(G.CurrentCapacityDict) ACOcapacityDict = deepcopy(G.CurrentCapacityDict)
ACOincompleteBatches = deepcopy(G.incompleteBatches) ACOincompleteBatches = deepcopy(G.incompleteBatches)
ACOearliness = 0 ACOearliness = 0
ACOlateness = 0 ACOlateness = 0
ACOtargetUtil = 0 ACOtargetUtil = 0
ACOminUtil = 0 ACOminUtil = 0
ACOexcess = 0
# repeat allocation procedure for all items in the list # repeat allocation procedure for all items in the list
for item in itemList: for item in itemList:
...@@ -97,8 +97,8 @@ def AllocationRoutine_ACO(initialWeek, itemList, itemType, ant): ...@@ -97,8 +97,8 @@ def AllocationRoutine_ACO(initialWeek, itemList, itemType, ant):
if chosenMA != None: if chosenMA != None:
ACOcapacityDict = Results[chosenMA]['remainingCap'] ACOcapacityDict = Results[chosenMA]['remainingCap']
ACOincompleteBatches = Results[chosenMA]['remUnits'] ACOincompleteBatches = Results[chosenMA]['remUnits']
ACOearliness += Results[chosenMA]['earliness']/item['Qty'] ACOearliness += float(Results[chosenMA]['earliness'])/item['Qty']
ACOlateness += Results[chosenMA]['lateness']/item['Qty'] ACOlateness += float(Results[chosenMA]['lateness'])/item['Qty']
break break
step += 1 step += 1
...@@ -109,7 +109,7 @@ def AllocationRoutine_ACO(initialWeek, itemList, itemType, ant): ...@@ -109,7 +109,7 @@ def AllocationRoutine_ACO(initialWeek, itemList, itemType, ant):
if G.minDeltaUt: if G.minDeltaUt:
ACOtargetUtil, ACOminUtil = utilisationCalc1(ACOcapacityDict, initialWeek, ind) ACOtargetUtil, ACOminUtil = utilisationCalc1(ACOcapacityDict, initialWeek, ind)
else: else:
ACOtargetUtil, ACOminUtil = utilisationCalc2(ACOcapacityDict, initialWeek, ind) ACOtargetUtil, ACOminUtil = utilisationCalc3(ACOcapacityDict, initialWeek, ind)
return {'ant':ant, 'excess':ACOexcess, 'earliness':ACOearliness, 'lateness':ACOlateness, 'targetUtil':ACOtargetUtil, 'minUtil':ACOminUtil} return {'ant':ant, 'excess':ACOexcess, 'earliness':ACOearliness, 'lateness':ACOlateness, 'targetUtil':ACOtargetUtil, 'minUtil':ACOminUtil}
......
# ===========================================================================
# Copyright 2015 Dublin City University
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 9 Dec 2014
@author: Anna
'''
from Globals import G
from Allocation_3 import Allocation2
from copy import deepcopy
def AllocationRoutine_Final(initialWeek, itemList, itemType, ant):
excess = []
# repeat allocation procedure for all items in the list
for item in itemList:
#================================================
# Allocation step 1...allocation at current Week
#================================================
Results = {}
step = 1
ind = G.WeekList.index(initialWeek)
weekList = [initialWeek]
capacity = deepcopy(G.CurrentCapacityDict)
qty = item['Qty']
Allocation = []
earliness = 0
lateness = 0
ma = ant[item['orderID']]
chosenMA = None
while step <= 3:
if step == 2:
weekList = [G.WeekList[i] for i in range(ind-1, max(-1,ind-G.maxEarliness-1), -1)]
if step == 3:
weekList = [G.WeekList[i] for i in range(ind+1, min(G.planningHorizon,ind+G.maxLateness+1))]
if len(weekList) == 0:
step+=1
continue
if step > 1:
capacity = deepcopy(Results[ma]['remainingCap'])
qty = deepcopy(Results[ma]['remainingUnits'])
Allocation = deepcopy(Results[ma]['Allocation'])
earliness = deepcopy(Results[ma]['earliness'])
lateness = deepcopy(Results[ma]['lateness'])
else:
capacity = deepcopy(G.CurrentCapacityDict)
qty = item['Qty']
Allocation = []
earliness = 0
lateness = 0
# try allocation to ma
Results[ma] = Allocation2(ma, qty, weekList, capacity, G.incompleteBatches, earliness, lateness, Allocation, initialWeek)
if Results[ma]['remainingUnits'] == 0: # if the allocation is not successful delete the record of the allocation results
chosenMA = ma
# confirm the solution
if chosenMA != None:
G.CurrentCapacityDict = Results[chosenMA]['remainingCap']
G.incompleteBatches = Results[chosenMA]['remUnits']
G.Earliness[initialWeek][chosenMA]['qty'].append(item['Qty'])
G.Earliness[initialWeek][chosenMA]['earliness'].append(float(Results[chosenMA]['earliness'])/item['Qty'])
G.Lateness[initialWeek][chosenMA]['qty'].append(item['Qty'])
G.Lateness[initialWeek][chosenMA]['lateness'].append(float(Results[chosenMA]['lateness'])/item['Qty'])
G.orders[item['orderID']]['Allocation'] = Results[chosenMA]['Allocation']
G.orders[item['orderID']]['Excess'] = False
G.orders[item['orderID']]['chosenMA'] = chosenMA
for allRep in Results[chosenMA]['Allocation']:
G.globalMAAllocation[chosenMA][allRep['week']][itemType][item['priority']] += allRep['units']
break
step += 1
if chosenMA == None:
excess.append(item)
G.Excess[item['sp']][initialWeek] += item['Qty']
G.orders[item['orderID']]['Allocation'] = []
G.orders[item['orderID']]['Excess'] = True
G.orders[item['orderID']]['chosenMA'] = None
# for orders add allocation information
if itemType == 'order':
if chosenMA == None:
G.OrderResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Customer'], item['Qty'], item['priority'], chosenMA, 'NaN', 'NaN', 'None'))
else:
G.OrderResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Customer'], item['Qty'], item['priority'], chosenMA, Results[chosenMA]['lateness'], Results[chosenMA]['earliness'], Results[chosenMA]['Allocation']))
if itemType == 'forecast':
if chosenMA == None:
G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, 'NaN', 'NaN', 'None'))
else:
G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, Results[chosenMA]['lateness'], Results[chosenMA]['earliness']/item['Qty'], Results[chosenMA]['Allocation']))
# ===========================================================================
# Copyright 2015 Dublin City University
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
''' '''
Created on 27 Nov 2014 Created on 22 Apr 2015
@author: Anna @author: Anna
''' '''
from Globals import G from Globals import G
from Allocation_3 import Allocation2 from Allocation_3 import Allocation2
from copy import deepcopy
from numpy import mean, array, absolute, std from numpy import mean, array, absolute, std
from operator import itemgetter from operator import itemgetter
from copy import deepcopy from UtilisationCalculation import utilisationCalc2, utilisationCalc1, utilisationCalc3
def AllocationRoutine2(initialWeek, itemList, itemType): def AllocationRoutine_Final(initialWeek, itemList, itemType, ant):
excess = [] excess = []
builtAnt = {}
ACOearliness = 0
ACOlateness = 0
ACOexcess = 0
# repeat allocation procedure for all items in the list # repeat allocation procedure for all items in the list
for item in itemList: for item in itemList:
# print 'item', item['orderID']
#================================================ #================================================
# Allocation step 1...allocation at current Week # Allocation step 1...allocation at current Week
#================================================ #================================================
...@@ -46,21 +30,28 @@ def AllocationRoutine2(initialWeek, itemList, itemType): ...@@ -46,21 +30,28 @@ def AllocationRoutine2(initialWeek, itemList, itemType):
step = 1 step = 1
ind = G.WeekList.index(initialWeek) ind = G.WeekList.index(initialWeek)
weekList = [initialWeek] weekList = [initialWeek]
weekListUtCalc = [initialWeek]
capacity = deepcopy(G.CurrentCapacityDict) capacity = deepcopy(G.CurrentCapacityDict)
qty = item['Qty'] qty = item['Qty']
Allocation = [] Allocation = []
earliness = 0 earliness = 0
lateness = 0 lateness = 0
#ma = ant[item['orderID']]
chosenMA = None
possibleSolutions = []
lateForecast = 0
earlyForecast = 0
while step <= 3: while step <= 3:
possibleSolutions = []
if step == 2: if step == 2:
weekList = [G.WeekList[i] for i in range(ind-1, max(-1,ind-G.maxEarliness-1), -1)] weekList = [G.WeekList[i] for i in range(ind-1, max(-1,ind-G.maxEarliness-1), -1)]
weekListUtCalc += weekList
if step == 3: if step == 3:
weekList = [G.WeekList[i] for i in range(ind+1, min(G.planningHorizon,ind+G.maxLateness+1))] weekList = [G.WeekList[i] for i in range(ind+1, min(G.planningHorizon,ind+G.maxLateness+1))]
if len(weekList) == 0: if len(weekList) == 0:
step+=1 step+=1
continue continue
...@@ -68,85 +59,122 @@ def AllocationRoutine2(initialWeek, itemList, itemType): ...@@ -68,85 +59,122 @@ def AllocationRoutine2(initialWeek, itemList, itemType):
# check different MAs # check different MAs
for ma in item['MAlist']: for ma in item['MAlist']:
if step > 1: if ma not in possibleSolutions:
capacity = deepcopy(Results[ma]['remainingCap'])
qty = deepcopy(Results[ma]['remainingUnits'])
Allocation = deepcopy(Results[ma]['Allocation'])
earliness = deepcopy(Results[ma]['earliness'])
lateness = deepcopy(Results[ma]['lateness'])
else: if step > 1:
capacity = deepcopy(G.CurrentCapacityDict) capacity = deepcopy(Results[ma]['remainingCap'])
qty = item['Qty'] qty = deepcopy(Results[ma]['remainingUnits'])
Allocation = [] Allocation = deepcopy(Results[ma]['Allocation'])
earliness = 0 earliness = deepcopy(Results[ma]['earliness'])
lateness = 0 lateness = deepcopy(Results[ma]['lateness'])
# try allocation to ma else:
Results[ma] = Allocation2(ma, qty, weekList, capacity, G.incompleteBatches, earliness, lateness, Allocation, initialWeek) capacity = deepcopy(G.CurrentCapacityDict)
if Results[ma]['remainingUnits'] == 0: # if the allocation is not successful delete the record of the allocation results qty = item['Qty']
possibleSolutions.append(ma) Allocation = []
earliness = 0
lateness = 0
# try allocation to ma
Results[ma] = Allocation2(ma, qty, weekList, capacity, G.incompleteBatches, earliness, lateness, Allocation, initialWeek)
if Results[ma]['remainingUnits'] == 0: # if the allocation is not successful delete the record of the allocation results
possibleSolutions.append(ma)
if len(possibleSolutions) == len(item['MAlist']):
break
step += 1
# chose best MA # choose best MA
if G.minDeltaUt: if G.minDeltaUt:
chosenMA = choseMA2(Results, possibleSolutions, weekList) chosenMA2, orderedMAlist = choseMA2(Results, possibleSolutions, item['MAlist'], weekListUtCalc)
else: else:
chosenMA = choseMA(Results, possibleSolutions, weekList) chosenMA2, orderedMAlist = choseMA(Results, possibleSolutions, item['MAlist'], weekListUtCalc)
# confirm the solution oMAlist2 = [ix[0] for ix in orderedMAlist]
if chosenMA != None:
G.CurrentCapacityDict = Results[chosenMA]['remainingCap'] if ant == 0:
G.incompleteBatches = Results[chosenMA]['remUnits'] chosenMA = chosenMA2
G.Earliness[initialWeek][chosenMA]['qty'].append(item['Qty'])
G.Earliness[initialWeek][chosenMA]['earliness'].append(float(Results[chosenMA]['earliness'])/item['Qty']) else:
G.Lateness[initialWeek][chosenMA]['qty'].append(item['Qty']) if ant[item['orderID']] in possibleSolutions:
G.Lateness[initialWeek][chosenMA]['lateness'].append(float(Results[chosenMA]['lateness'])/item['Qty']) chosenMA = ant[item['orderID']]
G.orders[item['orderID']]['Allocation'] = Results[chosenMA]['Allocation'] # riordinare la orderedMAlist per portare in chosenMA (da ACO) al primo posto
G.orders[item['orderID']]['Excess'] = False if oMAlist2[0] != chosenMA:
G.orders[item['orderID']]['chosenMA'] = chosenMA tempMAlist = [chosenMA]
for oMA in oMAlist2:
if oMA != chosenMA:
tempMAlist.append(oMA)
oMAlist2 = tempMAlist
builtAnt[item['orderID']]=chosenMA
# confirm the solution
if chosenMA != None:
G.CurrentCapacityDict = Results[chosenMA]['remainingCap']
G.incompleteBatches = Results[chosenMA]['remUnits']
G.Earliness[initialWeek][chosenMA]['qty'].append(item['Qty'])
G.Earliness[initialWeek][chosenMA]['earliness'].append(float(Results[chosenMA]['earliness'])/item['Qty'])
G.Lateness[initialWeek][chosenMA]['qty'].append(item['Qty'])
G.Lateness[initialWeek][chosenMA]['lateness'].append(float(Results[chosenMA]['lateness'])/item['Qty'])
G.orders[item['orderID']]['Allocation'] = Results[chosenMA]['Allocation']
G.orders[item['orderID']]['Excess'] = False
G.orders[item['orderID']]['chosenMA'] = chosenMA
G.orders[item['orderID']]['orderedList'] = oMAlist2
ACOearliness += float(Results[chosenMA]['earliness'])/item['Qty']
ACOlateness += float(Results[chosenMA]['lateness'])/item['Qty']
if Results[chosenMA]['lateness']:
G.LateMeasures['noLateOrders'] += 1
G.LateMeasures['lateness'].append(float(Results[chosenMA]['lateness'])/item['Qty'])
for allRep in Results[chosenMA]['Allocation']: if Results[chosenMA]['earliness']:
G.globalMAAllocation[chosenMA][allRep['week']][itemType][item['priority']] += allRep['units'] G.LateMeasures['noEarlyOrders'] += 1
break G.LateMeasures['earliness'].append(float(Results[chosenMA]['earliness'])/item['Qty'])
step += 1 for allRep in Results[chosenMA]['Allocation']:
G.globalMAAllocation[chosenMA][allRep['week']][itemType][item['priority']] += allRep['units']
G.globalMAAllocationIW[chosenMA][initialWeek][itemType][item['priority']] += allRep['units']
if chosenMA == None: else:
excess.append(item) excess.append(item)
G.Excess[item['sp']][initialWeek] += item['Qty'] G.Excess[item['sp']][initialWeek] += item['Qty']
G.orders[item['orderID']]['Allocation'] = [] G.orders[item['orderID']]['Allocation'] = []
G.orders[item['orderID']]['Excess'] = True G.orders[item['orderID']]['Excess'] = True
G.orders[item['orderID']]['chosenMA'] = None G.orders[item['orderID']]['chosenMA'] = None
G.orders[item['orderID']]['orderedList'] = oMAlist2
G.LateMeasures['noExcess'] += 1
G.LateMeasures['exUnits'] += item['Qty']
G.globalMAAllocationIW[item['sp']][initialWeek][itemType][item['priority']] += item['Qty']
ACOexcess += item['Qty']
# for orders add allocation information # for orders add allocation information
if itemType == 'order': if itemType == 'order':
if chosenMA == None: if chosenMA == None:
G.OrderResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Customer'], item['Qty'], item['priority'], chosenMA, 'NaN', 'NaN', 'None')) G.OrderResults.append((item['orderID'], item['sp'], item['MAlist'], item['Week'], item['Customer'], item['Qty'], item['priority'], chosenMA, oMAlist2, 'NaN', 'NaN', 'None'))
else: else:
G.OrderResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Customer'], item['Qty'], item['priority'], chosenMA, Results[chosenMA]['lateness'], Results[chosenMA]['earliness'], Results[chosenMA]['Allocation'])) G.OrderResults.append((item['orderID'], item['sp'], item['MAlist'], item['Week'], item['Customer'], item['Qty'], item['priority'], chosenMA, oMAlist2, Results[chosenMA]['lateness'], Results[chosenMA]['earliness'], Results[chosenMA]['Allocation']))
if itemType == 'forecast': if itemType == 'forecast':
if chosenMA == None: if chosenMA == None:
G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, 'NaN', 'NaN', 'None')) G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, orderedMAlist, 'NaN', 'NaN', 'None'))
else: else:
G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, Results[chosenMA]['lateness'], Results[chosenMA]['earliness']/item['Qty'], Results[chosenMA]['Allocation'])) G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, orderedMAlist, Results[chosenMA]['lateness'], Results[chosenMA]['earliness']/item['Qty'], Results[chosenMA]['Allocation']))
return excess
def choseMA(allResults, possibleSolutions, weeklist):
chosenMA = None if G.minDeltaUt:
ACOtargetUtil, ACOminUtil = utilisationCalc1(G.CurrentCapacityDict, initialWeek, ind)
else:
ACOtargetUtil, ACOminUtil = utilisationCalc2(G.CurrentCapacityDict, initialWeek, ind)
# if there is only one solution, chose the only solution available return {'ant':builtAnt, 'excess':ACOexcess, 'earliness':ACOearliness, 'lateness':ACOlateness, 'targetUtil':ACOtargetUtil, 'minUtil':ACOminUtil}
if len(possibleSolutions) == 1:
chosenMA = possibleSolutions[0] def choseMA(allResults, possibleSolutions, MAlist, weeklist):
# if there are more than one successful allocations choose between them chosenMA = None
if len(possibleSolutions) > 1:
if len(MAlist) > 1:
res = [] res = []
for ma in possibleSolutions: for ma in MAlist:
minUtil = [] minUtil = []
targetUtil = [] targetUtil = []
for week in weeklist: for week in weeklist:
...@@ -155,28 +183,34 @@ def choseMA(allResults, possibleSolutions, weeklist): ...@@ -155,28 +183,34 @@ def choseMA(allResults, possibleSolutions, weeklist):
minUtil.append(max(0, (G.Capacity[bn][week]['minUtilisation']-allResults[ma]['utilisation'][bn][week])/G.Capacity[bn][week]['minUtilisation'])) minUtil.append(max(0, (G.Capacity[bn][week]['minUtilisation']-allResults[ma]['utilisation'][bn][week])/G.Capacity[bn][week]['minUtilisation']))
targetUtil.append((G.Capacity[bn][week]['targetUtilisation']-allResults[ma]['utilisation'][bn][week])/G.Capacity[bn][week]['targetUtilisation']) targetUtil.append((G.Capacity[bn][week]['targetUtilisation']-allResults[ma]['utilisation'][bn][week])/G.Capacity[bn][week]['targetUtilisation'])
res.append([ma, allResults[ma]['lateness'], std(array(targetUtil)), std(array(minUtil)), allResults[ma]['earliness']]) res.append([ma, allResults[ma]['remainingUnits'], allResults[ma]['lateness'], std(array(targetUtil)), std(array(minUtil)), allResults[ma]['earliness']])
# order results...1st criterion: target utilisation (stdDev), 2nd criterion: min utilisation(stdDev) # order results...1st criterion: target utilisation (stdDev), 2nd criterion: min utilisation(stdDev)
sortedMA = sorted(res, key=itemgetter(1, 2, 3, 4)) sortedMA = sorted(res, key=itemgetter(1, 2, 3, 4, 5))
chosenMA = sortedMA[0][0]
return chosenMA
def choseMA2(allResults, possibleSolutions, weeklist): # more similar to ACO selection criteria
chosenMA = None
else:
sortedMA = [MAlist]
# if there is only one solution, chose the only solution available # if there is only one solution, chose the only solution available
if len(possibleSolutions) == 1: if len(possibleSolutions) == 1:
chosenMA = possibleSolutions[0] chosenMA = possibleSolutions[0]
# if there are more than one successful allocations choose between them # if there are more than one successful allocations choose between them
if len(possibleSolutions) > 1: if len(possibleSolutions) > 1:
chosenMA = sortedMA[0][0]
assert(chosenMA in possibleSolutions)
return chosenMA, sortedMA
def choseMA2(allResults, possibleSolutions, MAlist, weeklist): # more similar to ACO selection criteria
chosenMA = None
if len(MAlist) > 1:
res = [] res = []
for ma in possibleSolutions: for ma in MAlist:
minUtil = [] minUtil = []
targetUtil = [] targetUtil = []
for bottleneck in G.Bottlenecks: for bottleneck in G.Bottlenecks:
...@@ -190,10 +224,22 @@ def choseMA2(allResults, possibleSolutions, weeklist): # more similar to AC ...@@ -190,10 +224,22 @@ def choseMA2(allResults, possibleSolutions, weeklist): # more similar to AC
minUtil.append(mean(array(minU))) minUtil.append(mean(array(minU)))
targetUtil.append(mean(absolute(targetU))) targetUtil.append(mean(absolute(targetU)))
res.append([ma, allResults[ma]['lateness'], mean(array(targetUtil)), mean(array(minUtil)), allResults[ma]['earliness']]) res.append([ma, allResults[ma]['remainingUnits'], allResults[ma]['lateness'], std(array(targetUtil)), std(array(minUtil)), allResults[ma]['earliness']])
# order results...1st criterion: target utilisation (stdDev), 2nd criterion: min utilisation(stdDev) # order results...1st criterion: target utilisation (stdDev), 2nd criterion: min utilisation(stdDev)
sortedMA = sorted(res, key=itemgetter(1, 2, 3, 4)) sortedMA = sorted(res, key=itemgetter(1, 2, 3, 4, 5))
else:
sortedMA = [MAlist]
# if there is only one solution, chose the only solution available
if len(possibleSolutions) == 1:
chosenMA = possibleSolutions[0]
# if there are more than one successful allocations choose between them
if len(possibleSolutions) > 1:
chosenMA = sortedMA[0][0] chosenMA = sortedMA[0][0]
assert(chosenMA in possibleSolutions)
return chosenMA return chosenMA, sortedMA
...@@ -30,8 +30,6 @@ from Allocation_3 import Allocation2 ...@@ -30,8 +30,6 @@ from Allocation_3 import Allocation2
def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq):
EarlinessMA = {}
LatenessMA = {}
# repeat allocation procedure for all items in the list # repeat allocation procedure for all items in the list
for order in seq['seq']: for order in seq['seq']:
...@@ -39,6 +37,10 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): ...@@ -39,6 +37,10 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq):
item = itemList[order] item = itemList[order]
# print 'item', item['orderID'] # print 'item', item['orderID']
EarlinessMA = {}
LatenessMA = {}
lateForecast = 0
earlyForecast = 0
#================================================ #================================================
# Allocation step 1...allocation at current Week # Allocation step 1...allocation at current Week
#================================================ #================================================
...@@ -47,7 +49,9 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): ...@@ -47,7 +49,9 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq):
step = 1 step = 1
ind = G.WeekList.index(initialWeek) ind = G.WeekList.index(initialWeek)
weekList = [initialWeek] weekList = [initialWeek]
weekLateness = [0]
capacity = deepcopy(G.CurrentCapacityDict) capacity = deepcopy(G.CurrentCapacityDict)
incompleteBatches = deepcopy(G.incompleteBatches)
qty = item['Qty'] qty = item['Qty']
Allocation = [] Allocation = []
earliness = 0 earliness = 0
...@@ -55,31 +59,42 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): ...@@ -55,31 +59,42 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq):
previousAss = {} previousAss = {}
for ma in G.SPlist[item['sp']]: for ma in G.SPlist[item['sp']]:
previousAss[ma] = 0 previousAss[ma] = 0
previousAss[ma] = incompleteBatches[ma]
# print 'ma in', ma, incompleteBatches[ma]
qty -= incompleteBatches[ma]
# make use of incomplete batch units available
incompleteBatches[ma] = 0
# print 'order qty', qty
while step <= 3 and qty>0: while step <= 3 and qty>0:
if step == 2: if step == 2:
weekList = [G.WeekList[i] for i in range(ind-1, max(-1,ind-G.maxEarliness-1), -1)] weekList = [G.WeekList[i] for i in range(ind-1, max(-1,ind-G.maxEarliness-1), -1)]
weekLateness = [i-ind for i in range(ind-1, max(-1,ind-G.maxEarliness-1), -1)]
assert (len(weekList)==len(weekLateness))
if step == 3: if step == 3:
weekList = [G.WeekList[i] for i in range(ind+1, min(G.planningHorizon,ind+G.maxLateness+1))] weekList = [G.WeekList[i] for i in range(ind+1, min(G.planningHorizon,ind+G.maxLateness+1))]
weekLateness = [i-ind for i in range(ind+1, min(G.planningHorizon,ind+G.maxLateness+1))]
# print 'weeklist', weekList # print 'weeklist', weekList
if len(weekList) == 0: if len(weekList) == 0:
step+=1 step+=1
continue continue
# check different MAs # check different MAs
for week in weekList: for weekIndex in range(len(weekList)):
week = weekList[weekIndex]
# optimise MA allocation # optimise MA allocation
spAllocation = Allocation_IP(item, week, previousAss, capacity,G.weightFactor) spAllocation, probStatus = Allocation_IP(item, week, previousAss, capacity,G.weightFactor)
# print 'all', spAllocation # print 'all', spAllocation
# implement optimal MA solution # implement optimal MA solution
for ma in spAllocation.keys(): for ma in spAllocation.keys():
if spAllocation[ma]: if spAllocation[ma]:
Results = Allocation2(ma, spAllocation[ma], [week], capacity, G.incompleteBatches, earliness, lateness, Allocation, initialWeek) Results = Allocation2(ma, spAllocation[ma], [week], capacity, incompleteBatches, earliness, lateness, Allocation, initialWeek)
assert (Results['remainingUnits'] == 0) assert (Results['remainingUnits'] == 0)
# update variables # update variables
...@@ -91,9 +106,10 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): ...@@ -91,9 +106,10 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq):
if ma not in EarlinessMA: if ma not in EarlinessMA:
EarlinessMA[ma] = 0 EarlinessMA[ma] = 0
LatenessMA[ma] = 0 LatenessMA[ma] = 0
EarlinessMA[ma] += max([0, initialWeek - week])*spAllocation[ma]
LatenessMA[ma] += max([0, week - initialWeek])*spAllocation[ma] EarlinessMA[ma] += max([0, weekLateness[weekIndex]*(-1)])*spAllocation[ma]
LatenessMA[ma] += max([0, weekLateness[weekIndex]])*spAllocation[ma] #week - initialWeek
previousAss[ma] += spAllocation[ma] previousAss[ma] += spAllocation[ma]
if qty <= 0: if qty <= 0:
...@@ -103,14 +119,29 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): ...@@ -103,14 +119,29 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq):
# confirm results # confirm results
if qty <= 0: if qty <= 0:
minAss =item['Qty']*10
maIB = None
G.CurrentCapacityDict = Results['remainingCap'] G.CurrentCapacityDict = Results['remainingCap']
G.incompleteBatches = Results['remUnits'] G.incompleteBatches = Results['remUnits']
# print initialWeek, G.Earliness # print initialWeek, G.Earliness
for maT in EarlinessMA: for maT in EarlinessMA:
# assert(Results['remUnits'][maT]==0)
G.Earliness[initialWeek][maT]['qty'].append(item['Qty']) G.Earliness[initialWeek][maT]['qty'].append(item['Qty'])
G.Earliness[initialWeek][maT]['earliness'].append(EarlinessMA[maT]/item['Qty']) G.Earliness[initialWeek][maT]['earliness'].append(EarlinessMA[maT]/item['Qty'])
G.Lateness[initialWeek][maT]['qty'].append(item['Qty']) G.Lateness[initialWeek][maT]['qty'].append(item['Qty'])
G.Lateness[initialWeek][maT]['lateness'].append(LatenessMA[maT]/item['Qty']) G.Lateness[initialWeek][maT]['lateness'].append(LatenessMA[maT]/item['Qty'])
lateForecast += LatenessMA[maT]/item['Qty']
earlyForecast += EarlinessMA[maT]/item['Qty']
if previousAss[maT] <= minAss:
minAss = previousAss[maT]
maIB = maT
# print 'ma ib', maIB, qty, cQty, item['Qty'], previousAss, EarlinessMA , [G.incompleteBatches[ma] for ma in G.SPlist[item['sp']]]
if maIB != None:
G.incompleteBatches[maIB] -= qty
# print [G.incompleteBatches[ma] for ma in G.SPlist[item['sp']]]
G.orders[item['orderID']]['Allocation'] = Results['Allocation'] G.orders[item['orderID']]['Allocation'] = Results['Allocation']
G.orders[item['orderID']]['Excess'] = False G.orders[item['orderID']]['Excess'] = False
chosenMA = [] chosenMA = []
...@@ -119,14 +150,22 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): ...@@ -119,14 +150,22 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq):
chosenMA.append(allMA['ma']) chosenMA.append(allMA['ma'])
G.orders[item['orderID']]['chosenMA'] = chosenMA G.orders[item['orderID']]['chosenMA'] = chosenMA
if lateForecast:
G.LateMeasures['noLateOrders'] += 1
G.LateMeasures['lateness'].append(lateForecast)
if earlyForecast:
G.LateMeasures['noEarlyOrders'] += 1
G.LateMeasures['earliness'].append(earlyForecast)
for allRep in Results['Allocation']: for allRep in Results['Allocation']:
G.globalMAAllocation[allRep['ma']][allRep['week']][itemType][item['priority']] += allRep['units'] G.globalMAAllocation[allRep['ma']][allRep['week']][itemType][item['priority']] += allRep['units']
G.globalMAAllocationIW[allRep['ma']][initialWeek][itemType][item['priority']] += allRep['units']
if itemType == 'forecast': if itemType == 'forecast':
G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, Results['lateness'], Results['earliness']/item['Qty'], Results['Allocation'])) G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, Results['lateness']/item['Qty'], Results['earliness']/item['Qty'], Results['Allocation']))
else: else:
...@@ -134,5 +173,8 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): ...@@ -134,5 +173,8 @@ def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq):
G.orders[item['orderID']]['Allocation'] = [] G.orders[item['orderID']]['Allocation'] = []
G.orders[item['orderID']]['Excess'] = True G.orders[item['orderID']]['Excess'] = True
G.orders[item['orderID']]['chosenMA'] = None G.orders[item['orderID']]['chosenMA'] = None
G.globalMAAllocationIW[item['sp']][initialWeek][itemType][item['priority']] += item['Qty']
G.LateMeasures['noExcess'] += 1
G.LateMeasures['exUnits'] += item['Qty']
if itemType == 'forecast': if itemType == 'forecast':
G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], None, 'NaN', 'NaN', 'None')) G.forecastResults.append((item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], None, 'NaN', 'NaN', 'None'))
...@@ -31,12 +31,10 @@ from Globals import G ...@@ -31,12 +31,10 @@ from Globals import G
from AllocationForecast_IP import Allocation_IP from AllocationForecast_IP import Allocation_IP
from Allocation_3 import Allocation2 from Allocation_3 import Allocation2
from UtilisationCalculation import utilisationCalc1, utilisationCalc2 from UtilisationCalculation import utilisationCalc1, utilisationCalc2
from math import ceil
def AllocationRoutine_ForecastGA(initialWeek, itemList, itemType, chromo): def AllocationRoutine_ForecastGA(initialWeek, itemList, itemType, chromo):
EarlinessMA = {}
LatenessMA = {}
GAexcess = 0 GAexcess = 0
GAcapacityDict = deepcopy(G.CurrentCapacityDict) GAcapacityDict = deepcopy(G.CurrentCapacityDict)
GAincompleteBatches = deepcopy(G.incompleteBatches) GAincompleteBatches = deepcopy(G.incompleteBatches)
...@@ -50,7 +48,7 @@ def AllocationRoutine_ForecastGA(initialWeek, itemList, itemType, chromo): ...@@ -50,7 +48,7 @@ def AllocationRoutine_ForecastGA(initialWeek, itemList, itemType, chromo):
item=itemList[order] item=itemList[order]
# print 'item', item['orderID'] print 'item', item['orderID']
#================================================ #================================================
# Allocation step 1...allocation at current Week # Allocation step 1...allocation at current Week
...@@ -90,28 +88,37 @@ def AllocationRoutine_ForecastGA(initialWeek, itemList, itemType, chromo): ...@@ -90,28 +88,37 @@ def AllocationRoutine_ForecastGA(initialWeek, itemList, itemType, chromo):
for week in weekList: for week in weekList:
# optimise MA allocation at current week # optimise MA allocation at current week
spAllocation = Allocation_IP(item, week, previousAss, capacity, G.weightFactor) spAllocation, probStatus = Allocation_IP(item, week, previousAss, capacity, G.weightFactor)
# implement optimal MA solution to update temporary variables # implement optimal MA solution to update temporary variables
for ma in spAllocation.keys(): for ma in spAllocation.keys():
if probStatus == 'Optimal':
allocatedQty = spAllocation[ma]
else:
allocatedQty = ceil(spAllocation[ma])
if spAllocation[ma]: if spAllocation[ma]:
Results = Allocation2(ma, spAllocation[ma], [week], capacity, inBatches, earliness, lateness, Allocation, initialWeek)
assert (Results['remainingUnits'] == 0) #print 'spAllocation', ma, spAllocation[ma], inBatches[ma]
Results = Allocation2(ma, allocatedQty, [week], capacity, inBatches, earliness, lateness, Allocation, initialWeek)
#print 'rem units', Results['remainingUnits']
if probStatus == 'Optimal':
assert (Results['remainingUnits'] == 0)
else:
allocatedQty -= Results['remainingUnits']
# update order variables # update order variables
capacity = deepcopy(Results['remainingCap']) capacity = deepcopy(Results['remainingCap'])
inBatches = deepcopy(Results['remUnits']) inBatches = deepcopy(Results['remUnits'])
qty -= spAllocation[ma] qty -= allocatedQty
Allocation = deepcopy(Results['Allocation']) Allocation = deepcopy(Results['Allocation'])
earliness = deepcopy(Results['earliness']) earliness = deepcopy(Results['earliness'])
lateness = deepcopy(Results['lateness']) lateness = deepcopy(Results['lateness'])
if ma not in EarlinessMA:
EarlinessMA[ma] = 0
LatenessMA[ma] = 0
EarlinessMA[ma] += max([0, initialWeek - week])*spAllocation[ma]
LatenessMA[ma] += max([0, week - initialWeek])*spAllocation[ma]
previousAss[ma] += spAllocation[ma] previousAss[ma] += allocatedQty
# if order has been fully allocated update GA variables # if order has been fully allocated update GA variables
if qty <= 0: if qty <= 0:
......
...@@ -93,8 +93,10 @@ def Allocation2(currentMA, qty, weekList, capIn, inBatches, earliness, lateness, ...@@ -93,8 +93,10 @@ def Allocation2(currentMA, qty, weekList, capIn, inBatches, earliness, lateness,
currentCapacity[bottleneck][currentWeek]=remainingCapacity[bottleneck] currentCapacity[bottleneck][currentWeek]=remainingCapacity[bottleneck]
utilisation[bottleneck][currentWeek] = float(G.Capacity[bottleneck][currentWeek]['OriginalCapacity'] - currentCapacity[bottleneck][currentWeek])/G.Capacity[bottleneck][currentWeek]['OriginalCapacity'] utilisation[bottleneck][currentWeek] = float(G.Capacity[bottleneck][currentWeek]['OriginalCapacity'] - currentCapacity[bottleneck][currentWeek])/G.Capacity[bottleneck][currentWeek]['OriginalCapacity']
Allocation.append({'ma':currentMA, 'units':correctedQty, 'week':currentWeek}) Allocation.append({'ma':currentMA, 'units':correctedQty, 'week':currentWeek})
lateness += max([0, currentWeek - demandWeek])*correctedQty if currentWeek > demandWeek:
earliness += max([0, demandWeek - currentWeek])*correctedQty lateness += (step+1)*correctedQty
elif currentWeek<demandWeek:
earliness += (step+1)*correctedQty
# if there is a surplus...update remUnits # if there is a surplus...update remUnits
if surplus: if surplus:
...@@ -102,7 +104,7 @@ def Allocation2(currentMA, qty, weekList, capIn, inBatches, earliness, lateness, ...@@ -102,7 +104,7 @@ def Allocation2(currentMA, qty, weekList, capIn, inBatches, earliness, lateness,
if roundDown: if roundDown:
remUnits[currentMA] -= surplus remUnits[currentMA] -= surplus
else: else:
remUnits[currentMA] = G.BatchSize[currentMA][currentWeek] - surplus remUnits[currentMA] += G.BatchSize[currentMA][currentWeek] - surplus
surplus = 0 surplus = 0
...@@ -131,8 +133,10 @@ def Allocation2(currentMA, qty, weekList, capIn, inBatches, earliness, lateness, ...@@ -131,8 +133,10 @@ def Allocation2(currentMA, qty, weekList, capIn, inBatches, earliness, lateness,
currentCapacity[bottleneck][currentWeek]-=allocableQty*G.RouteDict[currentMA][bottleneck][currentWeek] currentCapacity[bottleneck][currentWeek]-=allocableQty*G.RouteDict[currentMA][bottleneck][currentWeek]
Allocation.append({'ma':currentMA,'units':allocableQty, 'week':currentWeek}) Allocation.append({'ma':currentMA,'units':allocableQty, 'week':currentWeek})
lateness += max([0, currentWeek - demandWeek])*allocableQty if currentWeek > demandWeek:
earliness += max([0, demandWeek - currentWeek])*allocableQty lateness += (step+1)*allocableQty
elif currentWeek < demandWeek:
earliness += (step+1)*allocableQty
if remainingUnits == 0: if remainingUnits == 0:
sufficient = True sufficient = True
......
...@@ -26,7 +26,7 @@ Created on 8 Dec 2014 ...@@ -26,7 +26,7 @@ Created on 8 Dec 2014
''' implements ACO for the allocation of orders/forecast of a certain week/priority level ''' ''' implements ACO for the allocation of orders/forecast of a certain week/priority level '''
from AllocationRoutine_ACO2 import AllocationRoutine_ACO from AllocationRoutine_ACO2 import AllocationRoutine_ACO
from AllocationRoutine_Final import AllocationRoutine_Final from AllocationRoutine_Final2 import AllocationRoutine_Final
from Globals import G from Globals import G
from random import choice from random import choice
from operator import itemgetter from operator import itemgetter
...@@ -52,71 +52,87 @@ def ranking(candidates,elg): ...@@ -52,71 +52,87 @@ def ranking(candidates,elg):
fittestLateness = sorted(finalCandidates, key=itemgetter('excess', 'lateness', 'earliness')) fittestLateness = sorted(finalCandidates, key=itemgetter('excess', 'lateness', 'earliness'))
fittestUtilisation = sorted(finalCandidates, key=itemgetter('targetUtil', 'minUtil')) fittestUtilisation = sorted(finalCandidates, key=itemgetter('targetUtil', 'minUtil'))
# select candidates that appear in the first positions in both lists...with preference on Lateness metrics # FIXME: verificare se sono tutti 0 lateness excess e earliness...in tal caso prendere direttamente da fittestUtilisation
numTop = int(ceil(len(finalCandidates)*0.2)) if fittestLateness[0]['excess']==fittestLateness[len(fittestLateness)-1]['excess'] and \
aLateness = [] fittestLateness[0]['lateness']==fittestLateness[len(fittestLateness)-1]['lateness'] and \
aUtilisation = [] fittestLateness[0]['earliness']==fittestLateness[len(fittestLateness)-1]['earliness']:
for i in range(numTop):
aLateness.append(fittestLateness[i]['orderSequence'])
aUtilisation.append(fittestUtilisation[i]['orderSequence'])
aLateness = set(aLateness)
aUtilisation = set(aUtilisation)
selection = list(aLateness.intersection(aUtilisation))
fittest = []
fitID = []
numFit = min([len(selection), elg])
for i in range(numFit):
x = 0
while x < numTop:
if fittestLateness[x]['orderSequence'] == selection[i]:
fittest.append(fittestLateness[x])
fitID.append(fittestLateness[x]['orderSequence'])
break
x += 1
# select the best solutions based on fittestUtilisation
# if there is not enough ants in selection then calculate the average ranking between the two sorted lists and fittest = []
# select the ants with highest average ranking not previously included fitID = []
# solve the ties in favour of lateness numFit = min([len(fittestUtilisation), elg])
if numFit < elg:
for i in range(numFit):
fittest.append(fittestUtilisation[i])
fitID.append(fittestUtilisation[i]['orderSequence'])
else:
# select candidates that appear in the first positions in both lists...with preference on Lateness metrics
numTop = int(ceil(len(finalCandidates)*0.2))
aLateness = []
aUtilisation = []
for i in range(numTop):
aLateness.append(fittestLateness[i]['orderSequence'])
aUtilisation.append(fittestUtilisation[i]['orderSequence'])
aLateness = set(aLateness)
aUtilisation = set(aUtilisation)
selection = list(aLateness.intersection(aUtilisation))
ultRanking = {} fittest = []
rankingList = [] fitID = []
for i in range(len(fittestLateness)): numFit = min([len(selection), elg])
ultRanking[fittestLateness[i]['orderSequence']] = {'lateness':i, 'orderSequence':fittestLateness[i]['orderSequence']}
for i in range(len(fittestUtilisation)):
ultRanking[fittestUtilisation[i]['orderSequence']]['utilisation'] = i
ultRanking[fittestUtilisation[i]['orderSequence']]['avg'] = mean([ultRanking[fittestUtilisation[i]['orderSequence']]['utilisation'], ultRanking[fittestUtilisation[i]['orderSequence']]['lateness']])
rankingList.append(ultRanking[fittestUtilisation[i]['orderSequence']])
rankingList = sorted(rankingList, key=itemgetter('avg', 'lateness')) for i in range(numFit):
x = 0
while x < numTop:
if fittestLateness[x]['orderSequence'] == selection[i]:
fittest.append(fittestLateness[x])
fitID.append(fittestLateness[x]['orderSequence'])
break
x += 1
for i in range(len(rankingList)): # if there is not enough ants in selection then calculate the average ranking between the two sorted lists and
if rankingList[i]['orderSequence'] not in fitID: # select the ants with highest average ranking not previously included
# solve the ties in favour of lateness
if numFit < elg:
ultRanking = {}
rankingList = []
for i in range(len(fittestLateness)):
ultRanking[fittestLateness[i]['orderSequence']] = {'lateness':i, 'orderSequence':fittestLateness[i]['orderSequence']}
for i in range(len(fittestUtilisation)):
ultRanking[fittestUtilisation[i]['orderSequence']]['utilisation'] = i
ultRanking[fittestUtilisation[i]['orderSequence']]['avg'] = mean([ultRanking[fittestUtilisation[i]['orderSequence']]['utilisation'], ultRanking[fittestUtilisation[i]['orderSequence']]['lateness']])
rankingList.append(ultRanking[fittestUtilisation[i]['orderSequence']])
rankingList = sorted(rankingList, key=itemgetter('avg', 'lateness'))
x = 0 for i in range(len(rankingList)):
while x < len(fittestLateness): if rankingList[i]['orderSequence'] not in fitID:
if fittestLateness[x]['orderSequence'] == rankingList[i]['orderSequence']:
fittest.append(fittestLateness[x]) x = 0
fitID.append(fittestLateness[x]['orderSequence']) while x < len(fittestLateness):
if fittestLateness[x]['orderSequence'] == rankingList[i]['orderSequence']:
fittest.append(fittestLateness[x])
fitID.append(fittestLateness[x]['orderSequence'])
break
x += 1
numFit += 1
if numFit == elg:
break break
x += 1
numFit += 1
if numFit == elg:
break
termCriterion = 0 termCriterion = 0
scores = [ant['excess'] for ant in fittest] # scores = [ant['excess'] for ant in fittest]
if max(scores) - min(scores) <= 0.001*min(scores): #Termination Criteria to check for convergence - in this case, if the current solutions are within 10% range # if max(scores) - min(scores) <= 0.001*min(scores): #Termination Criteria to check for convergence - in this case, if the current solutions are within 10% range
termCriterion += 1 # termCriterion += 1
#
scores = [ant['targetUtil'] for ant in fittest] # scores = [ant['targetUtil'] for ant in fittest]
if max(scores) - min(scores) <= 0.001*min(scores): #Termination Criteria to check for convergence - in this case, if the current solutions are within 10% range # if max(scores) - min(scores) <= 0.001*min(scores): #Termination Criteria to check for convergence - in this case, if the current solutions are within 10% range
termCriterion += 1 # termCriterion += 1
if termCriterion == 2: if termCriterion == 2:
print 'Termination Criterion Reached' print 'Termination Criterion Reached'
...@@ -180,7 +196,10 @@ def Allocation_ACO(initialWeek, itemList, itemType,ACOresults): ...@@ -180,7 +196,10 @@ def Allocation_ACO(initialWeek, itemList, itemType,ACOresults):
ACOresults.append((initialWeek, gen, rep, resultAnt['ant']['antID'],resultAnt['excess'], resultAnt['lateness'], resultAnt['earliness'], resultAnt['targetUtil'], resultAnt['minUtil'] )) ACOresults.append((initialWeek, gen, rep, resultAnt['ant']['antID'],resultAnt['excess'], resultAnt['lateness'], resultAnt['earliness'], resultAnt['targetUtil'], resultAnt['minUtil'] ))
# rank ants and select best ones # rank ants and select best ones
ants, termCond = ranking(ants,10) ants, termCond = ranking(ants,2)
for a in ants:
ACOresults.append((initialWeek, gen, rep, a['ant']['antID'],'survived', '', '', '', ''))
if termCond == 'Terminate': if termCond == 'Terminate':
break break
...@@ -197,4 +216,4 @@ def Allocation_ACO(initialWeek, itemList, itemType,ACOresults): ...@@ -197,4 +216,4 @@ def Allocation_ACO(initialWeek, itemList, itemType,ACOresults):
AllocationRoutine_Final(initialWeek, itemList, itemType, ant['ant']) AllocationRoutine_Final(initialWeek, itemList, itemType, ant['ant'])
ACOresults.append((initialWeek, gen, rep, ant['ant']['antID'], 'selected', '', '', '', '')) ACOresults.append((initialWeek, gen, rep, ant['ant']['antID'], 'selected', '', '', '', ''))
return ACOresults return ACOresults, ant['ant']
...@@ -100,18 +100,24 @@ def Allocation_GA(initialWeek, itemList, itemType,GAresults): ...@@ -100,18 +100,24 @@ def Allocation_GA(initialWeek, itemList, itemType,GAresults):
# cross-over: order2 cross-over is applied # cross-over: order2 cross-over is applied
for item in range(G.popSizeGA): for item in range(G.popSizeGA):
#print 'item', item
# apply X-over based on X-over probability # apply X-over based on X-over probability
xOver = random.random() xOver = random.random()
#print 'xOver', xOver
if item < G.popSizeGA-1 and xOver <= G.probXover: if item < G.popSizeGA-1 and xOver <= G.probXover:
#print 'in for crossOver'
chromosomes[item]['chromo']['seq'], chromosomes[item+1]['chromo']['seq'] = order2x(chromosomes[item]['chromo']['seq'], chromosomes[item+1]['chromo']['seq']) chromosomes[item]['chromo']['seq'], chromosomes[item+1]['chromo']['seq'] = order2x(chromosomes[item]['chromo']['seq'], chromosomes[item+1]['chromo']['seq'])
changeC[item] = 1 # both chromosomes have changes and they should be reassessed changeC[item] = 1 # both chromosomes have changes and they should be reassessed
changeC[item+1] = 1 changeC[item+1] = 1
mutation = random.random() mutation = random.random()
#print 'mut', mutation
# apply mutation based on mutation probability # apply mutation based on mutation probability
if mutation <= G.probMutation: if mutation <= G.probMutation:
#print 'in for mutation'
chromosomes[item]['chromo']['seq'] = displacement(chromosomes[item]['chromo']['seq']) chromosomes[item]['chromo']['seq'] = displacement(chromosomes[item]['chromo']['seq'])
changeC[item] = 1 changeC[item] = 1
......
...@@ -23,6 +23,7 @@ Created on 5 Sep 2013 ...@@ -23,6 +23,7 @@ Created on 5 Sep 2013
@author: Anna @author: Anna
''' '''
import tablib import tablib
from copy import deepcopy
class G: class G:
Capacity = {} Capacity = {}
...@@ -32,13 +33,16 @@ class G: ...@@ -32,13 +33,16 @@ class G:
planningHorizon =0 # for future demand purposes planningHorizon =0 # for future demand purposes
# demandFile = None # demandFile = None
CurrentCapacityDict = {} CurrentCapacityDict = {}
CurrentCapacityDictOrig = {}
Bottlenecks = [] Bottlenecks = []
SPlist = {} SPlist = {}
SPs = [] SPs = []
BatchSize = {} BatchSize = {}
orders = {} orders = {}
sortedOrders = {} sortedOrders = {}
forecast = {} ordersOrig = {}
sortedOrdersOrig = {}
#forecast = {}
incompleteBatches = {} incompleteBatches = {}
items ={} items ={}
WeekList=[] WeekList=[]
...@@ -46,8 +50,10 @@ class G: ...@@ -46,8 +50,10 @@ class G:
Earliness = {} Earliness = {}
Lateness = {} Lateness = {}
Excess = {} Excess = {}
LateMeasures = {'noLateOrders':0, 'lateness':[], 'noEarlyOrders':0, 'earliness':[], 'noExcess':0, 'exUnits':0}
Summary = {}
weightFactor = [10.0,1.0,0,2,0.5] weightFactor = [10.0,1.0,0,2,0.5]
Utilisation={}
# ACO parameters # ACO parameters
ACO = 1 ACO = 1
...@@ -67,19 +73,88 @@ class G: ...@@ -67,19 +73,88 @@ class G:
# utilisation calculation # utilisation calculation
minDeltaUt = 0 minDeltaUt = 0
acoRange = []
minRange = {}
# output variables # output variables
reportResults = tablib.Databook() reportResults = tablib.Databook()
OrderResults = tablib.Dataset(title='OrderSummary') OrderResults = tablib.Dataset(title='OrderSummary')
OrderResults.headers = ('PPOS', 'SP_NUMBER', 'MA_LIST', 'REQUEST_DATE', 'DFSELLER', 'ORDERQTY', 'PRIORITY', 'CHOSEN_MA', 'LATENESS', 'EARLINESS', 'ALLOCATION') OrderResults.headers = ('OrderID', 'SP_NUMBER', 'MA_LIST', 'REQUEST_DATE', 'DFSELLER', 'ORDERQTY', 'PRIORITY', 'CHOSEN_MA','ORDERED_MA_LIST', 'LATENESS', 'EARLINESS', 'ALLOCATION')
forecastResults = tablib.Dataset(title='ForecastSummary') forecastResults = tablib.Dataset(title='ForecastSummary')
forecastResults.headers = ('PPOS', 'SP_NUMBER', 'MA_LIST', 'REQUEST_DATE', 'ORDERQTY', 'PRIORITY', 'CHOSEN_MA', 'LATENESS', 'EARLINESS', 'ALLOCATION') forecastResults.headers = ('PPOS', 'SP_NUMBER', 'MA_LIST', 'REQUEST_DATE', 'ORDERQTY', 'PRIORITY', 'CHOSEN_MA', 'LATENESS', 'EARLINESS', 'ALLOCATION')
globalMAAllocation = {} globalMAAllocation = {}
globalMAAllocationIW = {}
spForecastOrder = [] spForecastOrder = []
CapacityResults = None
CapacityResults = tablib.Dataset(title = 'BN_Capa') CapacityResults = tablib.Dataset(title = 'BN_Capa')
allocationResults = tablib.Dataset(title = 'Demand_coverage') allocationResults = tablib.Dataset(title = 'Demand_coverage')
Utilisation = {}
Butilisation = {}
LPtime = 0
capRep = None
# filterItem = 0 # filterItem = 0
# filterWeek = 0 # filterWeek = 0
\ No newline at end of file def initialiseVar():
G.CurrentCapacityDict = deepcopy(G.CurrentCapacityDictOrig)
G.orders = deepcopy(G.ordersOrig)
G.sortedOrders = deepcopy(G.sortedOrdersOrig)
#G.forecast = {}
# G.items ={}
# set lateness and earliness results
for week in G.WeekList:
G.Lateness[week] = {}
G.Earliness[week] = {}
for sp in G.SPlist.keys():
for ma in G.SPlist[sp]:
G.Lateness[week][ma] = {'qty':[], 'lateness':[]}
G.Earliness[week][ma] = {'qty':[], 'earliness':[]}
# set excess results
for sp in G.SPlist.keys():
G.Excess[sp] = {}
for week in G.WeekList:
G.Excess[sp][week] = 0
for ma in G.SPlist[sp]:
G.incompleteBatches[ma] = 0
# set
for sp in G.SPlist.keys():
G.globalMAAllocationIW[sp] = {}
for week in G.WeekList:
G.globalMAAllocationIW[sp][week] = {'order':{}, 'forecast':{}}
for priority in G.priorityList['order']:
G.globalMAAllocationIW[sp][week]['order'][priority] = 0
for priority in G.priorityList['forecast']:
G.globalMAAllocationIW[sp][week]['forecast'][priority] = 0
for ma in G.SPlist[sp]:
G.globalMAAllocation[ma] = {}
G.globalMAAllocationIW[ma] = {}
for week in G.WeekList:
G.globalMAAllocation[ma][week] = {'order':{}}
G.globalMAAllocationIW[ma][week] = {'order':{}}
for priority in G.priorityList['order']:
G.globalMAAllocation[ma][week]['order'][priority] = 0
G.globalMAAllocationIW[ma][week]['order'][priority] = 0
G.globalMAAllocation[ma][week]['forecast'] = {}
G.globalMAAllocationIW[ma][week]['forecast'] = {}
for priority in G.priorityList['forecast']:
G.globalMAAllocation[ma][week]['forecast'][priority] = 0
G.globalMAAllocationIW[ma][week]['forecast'][priority] = 0
G.LateMeasures = {'noLateOrders':0, 'lateness':[], 'noEarlyOrders':0, 'earliness':[], 'noExcess':0, 'exUnits':0}
# output variables
G.reportResults = tablib.Databook()
G.OrderResults = tablib.Dataset(title='OrderSummary')
G.OrderResults.headers = ('OrderID', 'SP_NUMBER', 'MA_LIST', 'REQUEST_DATE', 'DFSELLER', 'ORDERQTY', 'PRIORITY', 'CHOSEN_MA','ORDERED_MA_LIST', 'LATENESS', 'EARLINESS', 'ALLOCATION')
G.forecastResults = tablib.Dataset(title='ForecastSummary')
G.forecastResults.headers = ('PPOS', 'SP_NUMBER', 'MA_LIST', 'REQUEST_DATE', 'ORDERQTY', 'PRIORITY', 'CHOSEN_MA', 'LATENESS', 'EARLINESS', 'ALLOCATION')
G.CapacityResults = None
G.CapacityResults = tablib.Dataset(title = 'BN_Capa')
G.allocationResults = tablib.Dataset(title = 'Demand_coverage')
G.Utilisation = {}
G.Butilisation = {}
\ No newline at end of file
...@@ -135,8 +135,8 @@ def rankingElitist(candidates,elg): ...@@ -135,8 +135,8 @@ def rankingElitist(candidates,elg):
# assuming a linear ranking parameter equal to 2, complete the probability list...see matlab files as reference # assuming a linear ranking parameter equal to 2, complete the probability list...see matlab files as reference
for i in range(numCand-2,-1,-1): for i in range(numCand-2,-1,-1):
s[i] = s[i+1] + (2.0/numCand)*float(numCand-1-i)/(numCand-1) s[i] = s[i+1] + (1.0/numCand)*(0.2+1.6*float(numCand-1-i)/(numCand-1)) #(2.0/numCand)*float(numCand-1-i)/(numCand-1)
for i in range(numCand-elg): for i in range(numCand-elg):
# randomly generate probability of selection # randomly generate probability of selection
probSel = random.random()*float(s[0]) probSel = random.random()*float(s[0])
......
...@@ -56,7 +56,7 @@ def utilisationCalc1(ACOcapacityDict, initialWeek, ind): ...@@ -56,7 +56,7 @@ def utilisationCalc1(ACOcapacityDict, initialWeek, ind):
minUtil.append(mean(array(minU))) minUtil.append(mean(array(minU)))
targetUtil.append(mean(absolute(targetU))) targetUtil.append(mean(absolute(targetU)))
ACOtargetUtil = mean(array(targetUtil)) ACOtargetUtil = std(array(targetUtil)) #mean(array(targetUtil)) #FIXME: potrebbe essere std(array(targetUtil))
ACOminUtil = mean(array(minUtil))*-1 ACOminUtil = mean(array(minUtil))*-1
return ACOtargetUtil, ACOminUtil return ACOtargetUtil, ACOminUtil
...@@ -83,3 +83,29 @@ def utilisationCalc2(ACOcapacityDict, initialWeek, ind): ...@@ -83,3 +83,29 @@ def utilisationCalc2(ACOcapacityDict, initialWeek, ind):
return ACOtargetUtil, ACOminUtil return ACOtargetUtil, ACOminUtil
def utilisationCalc3(ACOcapacityDict, initialWeek, ind):
#==============================================
# calculate min and target utilisation metrics
#==============================================
# targetUtil = max avg utilisation
# minUtil = avgUtilisation
minUtil = []
targetUtil = []
for bottleneck in G.Bottlenecks:
weekList = [initialWeek] #+ [G.WeekList[i] for i in range(ind-1, max(-1,ind-G.maxEarliness-1), -1)]
minU = []
targetU = []
for week in weekList:
utilisation = float(G.Capacity[bottleneck][week]['OriginalCapacity']-ACOcapacityDict[bottleneck][week])/G.Capacity[bottleneck][week]['OriginalCapacity']
minU.append(utilisation)
targetU.append(float(utilisation - G.Capacity[bottleneck][week]['targetUtilisation'])/G.Capacity[bottleneck][week]['targetUtilisation'])
minUtil.append(mean(array(minU)))
targetUtil.append(mean(array(max(minU))))
ACOtargetUtil = max(targetUtil)
ACOminUtil = mean(array(minUtil)) #FIXME: considerare piu settimane in weeklist e std(targetUtil)
return ACOtargetUtil, ACOminUtil
# ===========================================================================
# Copyright 2015 Dublin City University
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 27 Nov 2014
@author: Anna
'''
from AllocManagement_Hybrid import AllocManagement_Hybrid2
from ImportInput import ImportInput
from outputResults import outputResults
def main(input, algorithmAttributes):
assert input, 'no input is provided, the algorithm cannot run'
ImportInput(input, algorithmAttributes)
AllocManagement_Hybrid2()
outputResults()
# ===========================================================================
# Copyright 2015 Dublin City University
#
# This file is part of DREAM.
#
# DREAM is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DREAM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================
'''
Created on 22 Jun 2015
@author: Anna
'''
from AllocManagement_Hybrid import AllocManagement_Hybrid2, AllocManagement_Hybrid2_Forecast
from ImportInput import ImportInput
from outputResults import outputResults
from Globals import G, initialiseVar
import time
from numpy import mean, std, array
from operator import itemgetter
def main():
startTime = time.time()
ImportInput()
if G.ACO == "all":
G.acoRange = [0,1]
G.minRange = {0:[0,1],1:[0,1]}
elif G.ACO == "1":
G.acoRange = [0,1]
G.minRange = {0:[0,1],1:[G.minDeltaUt]}
else:
G.acoRange = [0]
G.minRange = {0:[G.minDeltaUt]}
for j in G.acoRange:
for i in G.minRange[j]:
initialiseVar()
G.minDeltaUt = i
G.ACO = j
print 'start ACO', G.ACO, 'minDelta', G.minDeltaUt
bestAnt = AllocManagement_Hybrid2(None)
# salvare risultati
G.Summary[(G.ACO,G.minDeltaUt)] = {'scenario':(G.ACO,G.minDeltaUt)}
for key in G.LateMeasures.keys():
if key == 'lateness' or key == 'earliness':
if len(G.LateMeasures[key]):
G.Summary[(G.ACO,G.minDeltaUt)][key] = mean(G.LateMeasures[key])
else:
G.Summary[(G.ACO,G.minDeltaUt)][key] = 0
else:
G.Summary[(G.ACO,G.minDeltaUt)][key] = G.LateMeasures[key]
utilisation = []
targetUt = []
for bottleneck in G.Bottlenecks:
for week in G.WeekList:
utilisation.append(float(G.Capacity[bottleneck][week]['OriginalCapacity']-G.CurrentCapacityDict[bottleneck][week])/G.Capacity[bottleneck][week]['OriginalCapacity'])
targetUt.append((G.Capacity[bottleneck][week]['targetUtilisation']-float(G.Capacity[bottleneck][week]['OriginalCapacity']-G.CurrentCapacityDict[bottleneck][week])/G.Capacity[bottleneck][week]['OriginalCapacity'])/G.Capacity[bottleneck][week]['targetUtilisation'])
G.Summary[(G.ACO,G.minDeltaUt)]['utilisation'] = mean(array(utilisation))
G.Summary[(G.ACO,G.minDeltaUt)]['targetM'] = mean(array(targetUt))
G.Summary[(G.ACO,G.minDeltaUt)]['targetStd'] = std(array(targetUt))
if G.ACO:
G.Summary[(G.ACO,G.minDeltaUt)]['ant'] = bestAnt
else:
G.Summary[(G.ACO,G.minDeltaUt)]['ant'] = None
# selection
listSummary = [G.Summary[item] for item in G.Summary.keys()]
print 'list summary', listSummary
listSummary = sorted(listSummary, key=itemgetter('exUnits', 'lateness', 'targetStd', 'utilisation','targetM', 'earliness'))
bestScenario = listSummary[0]['scenario']
aco = bestScenario[0]
minDelta = bestScenario[1]
G.Summary['orderedScenario'] = {}
for i in range(len(listSummary)):
G.Summary['orderedScenario'][listSummary[i]['scenario']] = i+1
G.Summary['bestScenario'] = bestScenario
if aco != G.ACO or minDelta != G.minDeltaUt:
initialiseVar()
G.ACO = 0 # forces the simulation of the best ant (even though the best scenario is ACO
G.minDeltaUt = minDelta
AllocManagement_Hybrid2(G.Summary[(aco,minDelta)]['ant'])
AllocManagement_Hybrid2_Forecast()
outputResults()
print 'calculation time', time.time()-startTime
if __name__ == '__main__':
main()
\ No newline at end of file
...@@ -24,10 +24,41 @@ Created on 8 Dec 2014 ...@@ -24,10 +24,41 @@ Created on 8 Dec 2014
''' '''
from Globals import G from Globals import G
import tablib import tablib
from numpy import mean
def outputResults(): def outputResults():
import os import os
if not os.path.exists('Results'): os.makedirs('Results') if not os.path.exists('Results'): os.makedirs('Results')
# report multi-analysis results
# head = (['', 'Heur0', 'Heur1', 'ACO0', 'ACO1'])
dictHead = {0:'Heur',1:'ACO'}
head = ['', ]
for aco in G.acoRange:
for minDelta in G.minRange[aco]:
head.append(dictHead[aco]+str(minDelta))
resultsOverview = tablib.Dataset(title='Overview')
resultsOverview.headers = (head)
print G.Summary.keys(), G.acoRange[0], G.minRange[G.acoRange[0]]
oMetric = ['noExcess', 'exUnits', 'noLateOrders', 'lateness', 'noEarlyOrders', 'earliness', 'targetM', 'targetStd', 'utilisation']
for metric in oMetric:
if metric!='scenario' and metric != 'ant':
r = []
for aco in G.acoRange:
for minDelta in G.minRange[aco]:
r.append(G.Summary[(aco,minDelta)][metric])
resultsOverview.append([metric]+r)
resultsOverview.append(['' for i in range(len(head))])
r = []
for aco in G.acoRange:
for minDelta in G.minRange[aco]:
r.append(G.Summary['orderedScenario'][(aco,minDelta)])
resultsOverview.append(['ordered scenarios']+r)
resultsOverview.append(['selected scenario', G.Summary['bestScenario']]+['' for i in range(len(head)-2)])
G.reportResults.add_sheet(resultsOverview)
G.reportResults.add_sheet(G.OrderResults) G.reportResults.add_sheet(G.OrderResults)
G.reportResults.add_sheet(G.forecastResults) G.reportResults.add_sheet(G.forecastResults)
...@@ -40,10 +71,13 @@ def outputResults(): ...@@ -40,10 +71,13 @@ def outputResults():
G.CapacityResults.append([bottleneck, 'Capa Pegging Resource Capacity (UoM)',]+initialCap) G.CapacityResults.append([bottleneck, 'Capa Pegging Resource Capacity (UoM)',]+initialCap)
G.CapacityResults.append(['', 'Capa Pegging Resource Total Load (UoM)',]+[G.Capacity[bottleneck][week]['OriginalCapacity']-G.CurrentCapacityDict[bottleneck][week] for week in G.WeekList]) G.CapacityResults.append(['', 'Capa Pegging Resource Total Load (UoM)',]+[G.Capacity[bottleneck][week]['OriginalCapacity']-G.CurrentCapacityDict[bottleneck][week] for week in G.WeekList])
G.CapacityResults.append(['', 'Capa Pegging Resource Total Util (Percent)',]+[float(G.Capacity[bottleneck][week]['OriginalCapacity']-G.CurrentCapacityDict[bottleneck][week])/G.Capacity[bottleneck][week]['OriginalCapacity']*100 for week in G.WeekList]) G.CapacityResults.append(['', 'Capa Pegging Resource Total Util (Percent)',]+[float(G.Capacity[bottleneck][week]['OriginalCapacity']-G.CurrentCapacityDict[bottleneck][week])/G.Capacity[bottleneck][week]['OriginalCapacity']*100 for week in G.WeekList])
G.CapacityResults.append(['', 'Capa Pegging Resource Min Util (Percent)',]+[G.Capacity[bottleneck][week]['minUtilisation']*100 for week in G.WeekList])
G.CapacityResults.append(['', 'Capa Pegging Resource Target Util (Percent)',]+[G.Capacity[bottleneck][week]['targetUtilisation']*100 for week in G.WeekList])
# utilisation results # utilisation results
for bottleneck in G.Bottlenecks: for bottleneck in G.Bottlenecks:
G.Utilisation[bottleneck] = {} G.Utilisation[bottleneck] = {}
G.Butilisation[bottleneck] = {}
for week in G.WeekList: for week in G.WeekList:
G.Utilisation[bottleneck][week] = {} G.Utilisation[bottleneck][week] = {}
G.Utilisation[bottleneck][week]['averageUtilization'] = float(G.Capacity[bottleneck][week]['OriginalCapacity']-G.CurrentCapacityDict[bottleneck][week])/G.Capacity[bottleneck][week]['OriginalCapacity'] G.Utilisation[bottleneck][week]['averageUtilization'] = float(G.Capacity[bottleneck][week]['OriginalCapacity']-G.CurrentCapacityDict[bottleneck][week])/G.Capacity[bottleneck][week]['OriginalCapacity']
...@@ -54,23 +88,30 @@ def outputResults(): ...@@ -54,23 +88,30 @@ def outputResults():
# report allocation results # report allocation results
head = ['PPOS', 'Demand_Items_Product_DCBNO - SP', 'Demand_Items_Product_DCBNO - MA', 'Demand_Type - Group', 'Priority','Values'] + G.WeekList head = ['PPOS', 'Demand_Items_Product_DCBNO - SP', 'Demand_Items_Product_DCBNO - MA', 'Demand_Type - Group', 'Priority','Values'] + G.WeekList
G.allocationResults.headers = head G.allocationResults.headers = head
spReqQty = {}
spPlannedQty = {}
maReqQty = {}
for sp in G.SPs: for sp in G.SPs:
newSp = sp newSp = sp
spReqQty = {} spReqQty[sp] = {}
spPlannedQty = {} spPlannedQty[sp] = {}
countedForecastSP = {} countedForecastSP = {}
for week in G.WeekList: for week in G.WeekList:
spReqQty[week] = 0 spReqQty[sp][week] = 0
spPlannedQty[week] = 0 spPlannedQty[sp][week] = 0
countedForecastSP[week] = [] countedForecastSP[week] = []
for ma in G.SPlist[sp]: for ma in G.SPlist[sp]:
maReqQty = {} maReqQty[ma] = {}
maPlannedQty = {} maPlannedQty = {}
for week in G.WeekList: for week in G.WeekList:
maReqQty[week] = 0 maReqQty[ma][week] = 0
maPlannedQty[week] = 0 maPlannedQty[week] = 0
for bot in G.Bottlenecks:
G.Butilisation[bot][ma] = {}
for week in G.WeekList:
G.Butilisation[bot][ma][week] = 0
# add orders results # add orders results
...@@ -85,14 +126,18 @@ def outputResults(): ...@@ -85,14 +126,18 @@ def outputResults():
temp+=G.sortedOrders['order'][priority][week][i]['Qty'] temp+=G.sortedOrders['order'][priority][week][i]['Qty']
orderMA.append(temp) orderMA.append(temp)
maReqQty[week] += temp maReqQty[ma][week] += temp
spReqQty[week] += temp spReqQty[sp][week] += temp
for bot in G.RouteDict[ma]:
G.Butilisation[bot][ma][week] += G.RouteDict[ma][bot][week]*G.globalMAAllocation[ma][week]['order'][priority]/G.Capacity[bot][week]['OriginalCapacity']*100
if newSp != None: if newSp != None:
G.allocationResults.append(['', sp, ma, 'ORDERS', priority, 'Demand Request Qty'] + orderMA ) G.allocationResults.append(['', sp, ma, 'ORDERS', priority, 'Demand Request Qty'] + orderMA )
newSp = None newSp = None
else: else:
G.allocationResults.append(['', '', ma, 'ORDERS', priority, 'Demand Request Qty'] + orderMA ) G.allocationResults.append(['', '', ma, 'ORDERS', priority, 'Demand Request Qty'] + orderMA )
G.allocationResults.append(['', '', '', '', priority, 'Demand Planned Qty'] + [G.globalMAAllocation[ma][week]['order'][priority] for week in G.WeekList]) G.allocationResults.append(['', '', '', 'ORDERS', priority, 'Demand Planned Qty'] + [G.globalMAAllocation[ma][week]['order'][priority] for week in G.WeekList])
if len(G.priorityList['order']) == 0: if len(G.priorityList['order']) == 0:
if newSp != None: if newSp != None:
...@@ -100,12 +145,12 @@ def outputResults(): ...@@ -100,12 +145,12 @@ def outputResults():
newSp = None newSp = None
else: else:
G.allocationResults.append(['', '', ma, 'ORDERS', 0, 'Demand Request Qty'] + [0 for i in range(len(G.WeekList))] ) G.allocationResults.append(['', '', ma, 'ORDERS', 0, 'Demand Request Qty'] + [0 for i in range(len(G.WeekList))] )
G.allocationResults.append(['', '', '', '', 0, 'Demand Planned Qty'] + [0 for i in range(len(G.WeekList))]) G.allocationResults.append(['', '', '', 'ORDERS', 0, 'Demand Planned Qty'] + [0 for i in range(len(G.WeekList))])
# add forecast results # add forecast results
if len(G.priorityList['forecast']) == 0: if len(G.priorityList['forecast']) == 0:
G.allocationResults.append(['', '', '', 'FORECAST', 0, 'Demand Request Qty'] + [0 for i in range(len(G.WeekList))] ) G.allocationResults.append(['', '', '', 'FORECAST', 0, 'Demand Request Qty'] + [0 for i in range(len(G.WeekList))] )
G.allocationResults.append(['', '', '', '', 0, 'Demand Planned Qty'] +[0 for i in range(len(G.WeekList))]) G.allocationResults.append(['', '', '', 'FORECAST', 0, 'Demand Planned Qty'] +[0 for i in range(len(G.WeekList))])
for priority in G.priorityList['forecast']: for priority in G.priorityList['forecast']:
orderMA = [] orderMA = []
...@@ -117,25 +162,28 @@ def outputResults(): ...@@ -117,25 +162,28 @@ def outputResults():
if ma in G.orders[G.sortedOrders['forecast'][priority][week][i]['orderID']]['suggestedMA']: if ma in G.orders[G.sortedOrders['forecast'][priority][week][i]['orderID']]['suggestedMA']:
temp+=G.orders[G.sortedOrders['forecast'][priority][week][i]['orderID']]['suggestedMA'][ma] temp+=G.orders[G.sortedOrders['forecast'][priority][week][i]['orderID']]['suggestedMA'][ma]
if G.orders[G.sortedOrders['forecast'][priority][week][i]['orderID']]['sp'] == sp and G.sortedOrders['forecast'][priority][week][i]['orderID'] not in countedForecastSP[week]: if G.orders[G.sortedOrders['forecast'][priority][week][i]['orderID']]['sp'] == sp and G.sortedOrders['forecast'][priority][week][i]['orderID'] not in countedForecastSP[week]:
spReqQty[week] += G.orders[G.sortedOrders['forecast'][priority][week][i]['orderID']]['Qty'] spReqQty[sp][week] += G.orders[G.sortedOrders['forecast'][priority][week][i]['orderID']]['Qty']
countedForecastSP[week].append(G.sortedOrders['forecast'][priority][week][i]['orderID']) countedForecastSP[week].append(G.sortedOrders['forecast'][priority][week][i]['orderID'])
orderMA.append(temp) orderMA.append(temp)
maReqQty[week] += temp maReqQty[ma][week] += temp
for bot in G.RouteDict[ma]:
G.Butilisation[bot][ma][week] += G.RouteDict[ma][bot][week]*G.globalMAAllocation[ma][week]['order'][priority]/G.Capacity[bot][week]['OriginalCapacity']*100
G.allocationResults.append(['', '', '', 'FORECAST', priority, 'Demand Request Qty'] + orderMA ) G.allocationResults.append(['', '', '', 'FORECAST', priority, 'Demand Request Qty'] + orderMA )
G.allocationResults.append(['', '', '', '', priority, 'Demand Planned Qty'] + [G.globalMAAllocation[ma][week]['forecast'][priority] for week in G.WeekList]) G.allocationResults.append(['', '', '', 'FORECAST', priority, 'Demand Planned Qty'] + [G.globalMAAllocation[ma][week]['forecast'][priority] for week in G.WeekList])
orderMA = [] orderMA = []
plannedMA = [] plannedMA = []
for week in G.WeekList: for week in G.WeekList:
orderMA.append(maReqQty[week]) orderMA.append(maReqQty[ma][week])
for orderType in ['order', 'forecast']: for orderType in ['order', 'forecast']:
for priority in G.priorityList[orderType]: for priority in G.priorityList[orderType]:
maPlannedQty[week] += G.globalMAAllocation[ma][week][orderType][priority] maPlannedQty[week] += G.globalMAAllocation[ma][week][orderType][priority]
plannedMA.append(maPlannedQty[week]) plannedMA.append(maPlannedQty[week])
spPlannedQty[week] += maPlannedQty[week] spPlannedQty[sp][week] += maPlannedQty[week]
G.allocationResults.append(['', '', ma+'Demand Request Qty', '', '', ''] + orderMA ) G.allocationResults.append(['', '', ma+'Demand Request Qty', '', '', ''] + orderMA )
G.allocationResults.append(['', '', ma+'Demand Planned Qty', '', '', ''] + plannedMA) G.allocationResults.append(['', '', ma+'Demand Planned Qty', '', '', ''] + plannedMA)
...@@ -143,8 +191,8 @@ def outputResults(): ...@@ -143,8 +191,8 @@ def outputResults():
orderSP = [] orderSP = []
plannedSP = [] plannedSP = []
for week in G.WeekList: for week in G.WeekList:
plannedSP.append(spPlannedQty[week]) plannedSP.append(spPlannedQty[sp][week])
orderSP.append(spReqQty[week]) orderSP.append(spReqQty[sp][week])
G.allocationResults.append(['', sp+'Demand Request Qty', '', '', '', ''] + orderSP ) G.allocationResults.append(['', sp+'Demand Request Qty', '', '', '', ''] + orderSP )
G.allocationResults.append(['', sp+'Demand Planned Qty', '', '', '', ''] + plannedSP) G.allocationResults.append(['', sp+'Demand Planned Qty', '', '', '', ''] + plannedSP)
...@@ -159,6 +207,123 @@ def outputResults(): ...@@ -159,6 +207,123 @@ def outputResults():
latenessResults.headers = (head) latenessResults.headers = (head)
weightedLateSP = {} weightedLateSP = {}
qtyRif = {}
for week in G.WeekList:
weightedLateSP[week] = {}
qtyRif[week]={}
for sp in G.SPlist.keys():
qtyRif[week][sp] = {'tot':0}
for typeOrder in ['order','forecast']:
for priority in G.priorityList[typeOrder]:
qtyRif[week][sp]['tot'] += G.globalMAAllocationIW[sp][week][typeOrder][priority]
weightedLateSP[week][sp] = 0
for ma in G.SPlist[sp]:
qtyRif[week][sp][ma] = 0
if len(G.Lateness[week][ma]['qty']):
G.Lateness[week][ma]['result'] = sum(G.Lateness[week][ma]['lateness'])*100
else:
G.Lateness[week][ma]['result'] = 0
for typeOrder in ['order','forecast']:
for priority in G.priorityList[typeOrder]:
qtyRif[week][sp]['tot'] += G.globalMAAllocationIW[ma][week][typeOrder][priority]
qtyRif[week][sp][ma] += G.globalMAAllocationIW[ma][week][typeOrder][priority]
for ma in G.SPlist[sp]:
if qtyRif[week][sp]['tot']:
weightedLateSP[week][sp] += (G.Lateness[week][ma]['result']*float(qtyRif[week][sp][ma]))/qtyRif[week][sp]['tot']
for sp in G.SPs:
latenessResults.append([sp]+[weightedLateSP[week][sp] for week in G.WeekList])
for ma in G.SPlist[sp]:
latenessResults.append([ma]+[G.Lateness[week][ma]['result'] for week in G.WeekList])
latenessResults.append(['' for i in range(len(G.WeekList)+1)])
G.reportResults.add_sheet(latenessResults)
# report earliness results
earlinessResults = tablib.Dataset(title='Earliness')
head = tuple(['Demand Request Days Early Weighted'] + G.WeekList)
earlinessResults.headers = (head)
weightedEarlySP = {}
for week in G.WeekList:
weightedEarlySP[week] = {}
for sp in G.SPlist.keys():
weightedEarlySP[week][sp] = 0
for ma in G.SPlist[sp]:
if len(G.Earliness[week][ma]['qty']):
G.Earliness[week][ma]['result'] = sum(G.Earliness[week][ma]['earliness'])*100
else:
G.Earliness[week][ma]['result'] = 0
for ma in G.SPlist[sp]:
if qtyRif[week][sp]['tot']:
weightedEarlySP[week][sp] += (G.Earliness[week][ma]['result']*float(qtyRif[week][sp][ma]))/qtyRif[week][sp]['tot']
for sp in G.SPs:
earlinessResults.append([sp]+[weightedEarlySP[week][sp] for week in G.WeekList])
for ma in G.SPlist[sp]:
earlinessResults.append([ma]+[G.Earliness[week][ma]['result'] for week in G.WeekList])
earlinessResults.append(['' for i in range(len(G.WeekList)+1)])
G.reportResults.add_sheet(earlinessResults)
excessResults = tablib.Dataset(title='Excess')
head = tuple(['Demand Request Excess'] + G.WeekList)
excessResults.headers = (head)
for sp in G.SPs:
excessResults.append([sp]+[G.Excess[sp][week] for week in G.WeekList])
G.reportResults.add_sheet(excessResults)
excessStats = tablib.Dataset(title='Stats')
head = tuple(['','no Orders', 'avg Value [%]'])
excessStats.headers = (head)
excessStats.append(['Lateness',G.LateMeasures['noLateOrders'],mean(G.LateMeasures['lateness'])*100])
excessStats.append(['Earliness',G.LateMeasures['noEarlyOrders'],mean(G.LateMeasures['earliness'])*100])
excessStats.append(['Excess',G.LateMeasures['noExcess'],G.LateMeasures['exUnits']])
G.reportResults.add_sheet(excessStats)
incomBatches = tablib.Dataset(title='InBatch')
for sp in G.SPs:
for ma in G.SPlist[sp]:
incomBatches.append([ma,G.incompleteBatches[ma]])
G.reportResults.add_sheet(incomBatches)
# report bottleneck utilisation results ordered per MA
c = 1
for bottleneck in G.Bottlenecks:
BottUtilisation = tablib.Dataset(title = 'B'+str(c))
head = ['Full Name Bottleneck','MA']+G.WeekList
BottUtilisation.headers = (head)
# BottUtilisation.append([bottleneck,'']+['' for i in G.WeekList])
new = 1
for sp in G.SPs:
for ma in G.SPlist[sp]:
if new:
BottUtilisation.append([bottleneck,ma]+[G.Butilisation[bottleneck][ma][week] for week in G.WeekList])
new = 0
else:
BottUtilisation.append(['',ma]+[G.Butilisation[bottleneck][ma][week] for week in G.WeekList])
G.reportResults.add_sheet(BottUtilisation)
c += 1
with open('Results\\rTable.html', 'wb') as h: #completion time, cycle time and delay info in html format
h.write(G.reportResults.html)
if G.capRep == None:
with open('Results\\allocation.xlsx', 'wb') as f: #time level schedule info
f.write(G.reportResults.xlsx)
else:
with open('Results\\allocation.xlsx', 'wb') as f: #time level schedule info
f.write(G.reportResults.xlsx)
''' weightedLateSP = {}
for week in G.WeekList: for week in G.WeekList:
weightedLateSP[week] = {} weightedLateSP[week] = {}
for sp in G.SPlist.keys(): for sp in G.SPlist.keys():
...@@ -184,15 +349,8 @@ def outputResults(): ...@@ -184,15 +349,8 @@ def outputResults():
for ma in G.SPlist[sp]: for ma in G.SPlist[sp]:
latenessResults.append([ma]+[G.Lateness[week][ma]['result'] for week in G.WeekList]) latenessResults.append([ma]+[G.Lateness[week][ma]['result'] for week in G.WeekList])
latenessResults.append(['' for i in range(len(G.WeekList)+1)]) latenessResults.append(['' for i in range(len(G.WeekList)+1)])
G.reportResults.add_sheet(latenessResults) weightedEarlySP = {}
# report earliness results
earlinessResults = tablib.Dataset(title='Earliness')
head = tuple(['Demand Request Days Early Weighted'] + G.WeekList)
earlinessResults.headers = (head)
weightedLateSP = {}
for week in G.WeekList: for week in G.WeekList:
weightedLateSP[week] = {} weightedLateSP[week] = {}
for sp in G.SPlist.keys(): for sp in G.SPlist.keys():
...@@ -212,26 +370,5 @@ def outputResults(): ...@@ -212,26 +370,5 @@ def outputResults():
weightedLateSP[week][sp]['result'] = sum([weightedLateSP[week][sp]['qty'][i]*weightedLateSP[week][sp]['earliness'][i] for i in range(len(weightedLateSP[week][sp]['qty']))])/qtySP weightedLateSP[week][sp]['result'] = sum([weightedLateSP[week][sp]['qty'][i]*weightedLateSP[week][sp]['earliness'][i] for i in range(len(weightedLateSP[week][sp]['qty']))])/qtySP
else: else:
weightedLateSP[week][sp]['result'] = 0 weightedLateSP[week][sp]['result'] = 0
'''
for sp in G.SPs:
earlinessResults.append([sp]+[weightedLateSP[week][sp]['result'] for week in G.WeekList])
for ma in G.SPlist[sp]:
earlinessResults.append([ma]+[G.Earliness[week][ma]['result'] for week in G.WeekList])
earlinessResults.append(['' for i in range(len(G.WeekList)+1)])
G.reportResults.add_sheet(earlinessResults)
excessResults = tablib.Dataset(title='Excess')
head = tuple(['Demand Request Excess'] + G.WeekList)
excessResults.headers = (head)
for sp in G.SPs:
excessResults.append([sp]+[G.Excess[sp][week] for week in G.WeekList])
G.reportResults.add_sheet(excessResults)
with open(os.path.join('Results', 'rTable.html'), 'wb') as h: #completion time, cycle time and delay info in html format
h.write(G.reportResults.html)
with open(os.path.join('Results', 'allocation.xlsx'), 'wb') as f: #time level schedule info
f.write(G.reportResults.xlsx)
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