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']))
def AllocationRoutine_ForecastGA(initialWeek, itemList, itemType, chromo): GAexcess = 0 GAcapacityDict = deepcopy(G.CurrentCapacityDict) GAincompleteBatches = deepcopy(G.incompleteBatches) GAearliness = 0 GAlateness = 0 GAtargetUtil = 0 GAminUtil = 0 # repeat allocation procedure for all items in the list for order in chromo['seq']: item = itemList[order] print 'item', item['orderID'] #================================================ # Allocation step 1...allocation at current Week #================================================ # variables created for one specific order # will be confirmed in the GA variables provided that there is enough capacity to allocate the entire order (possibly across different weeks) Results = {} step = 1 ind = G.WeekList.index(initialWeek) weekList = [initialWeek] capacity = deepcopy(GAcapacityDict) inBatches = deepcopy(GAincompleteBatches) qty = item['Qty'] Allocation = [] earliness = 0 lateness = 0 previousAss = {} for ma in G.SPlist[item['sp']]: previousAss[ma] = 0 while step <= 3 and qty > 0: 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)) ] # print 'weeklist', weekList if len(weekList) == 0: step += 1 continue # allocate requested qty for week in weekList: # optimise MA allocation at current week spAllocation, probStatus = Allocation_IP( item, week, previousAss, capacity, G.weightFactor) # implement optimal MA solution to update temporary variables for ma in spAllocation.keys(): if probStatus == 'Optimal': allocatedQty = spAllocation[ma] else: allocatedQty = ceil(spAllocation[ma]) if spAllocation[ma]: #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 capacity = deepcopy(Results['remainingCap']) inBatches = deepcopy(Results['remUnits']) qty -= allocatedQty Allocation = deepcopy(Results['Allocation']) earliness = deepcopy(Results['earliness']) lateness = deepcopy(Results['lateness']) previousAss[ma] += allocatedQty # if order has been fully allocated update GA variables if qty <= 0: GAcapacityDict = deepcopy(capacity) GAincompleteBatches = inBatches GAearliness += earliness / item['Qty'] GAlateness += lateness / item['Qty'] break step += 1 # if order can not been confirmed then update the GA excess variable if qty > 0: GAexcess += item['Qty'] if G.minDeltaUt: GAtargetUtil, GAminUtil = utilisationCalc1(GAcapacityDict, initialWeek, ind) else: GAtargetUtil, GAminUtil = utilisationCalc2(GAcapacityDict, initialWeek, ind) return { 'chromo': chromo, 'excess': GAexcess, 'earliness': GAearliness, 'lateness': GAlateness, 'targetUtil': GAtargetUtil, 'minUtil': GAminUtil }
def AllocationRoutine_Final(initialWeek, itemList, itemType, ant): excess = [] builtAnt = {} ACOearliness = 0 ACOlateness = 0 ACOexcess = 0 # 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] weekListUtCalc = [initialWeek] capacity = deepcopy(G.CurrentCapacityDict) qty = item['Qty'] Allocation = [] earliness = 0 lateness = 0 #ma = ant[item['orderID']] chosenMA = None possibleSolutions = [] lateForecast = 0 earlyForecast = 0 while step <= 3: if step == 2: weekList = [ G.WeekList[i] for i in range(ind - 1, max(-1, ind - G.maxEarliness - 1), -1) ] weekListUtCalc += weekList 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 # check different MAs for ma in item['MAlist']: if ma not in possibleSolutions: 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 possibleSolutions.append(ma) if len(possibleSolutions) == len(item['MAlist']): break step += 1 # choose best MA if G.minDeltaUt: chosenMA2, orderedMAlist = choseMA2(Results, possibleSolutions, item['MAlist'], weekListUtCalc) else: chosenMA2, orderedMAlist = choseMA(Results, possibleSolutions, item['MAlist'], weekListUtCalc) oMAlist2 = [ix[0] for ix in orderedMAlist] if ant == 0: chosenMA = chosenMA2 else: if ant[item['orderID']] in possibleSolutions: chosenMA = ant[item['orderID']] # riordinare la orderedMAlist per portare in chosenMA (da ACO) al primo posto if oMAlist2[0] != 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']) if Results[chosenMA]['earliness']: G.LateMeasures['noEarlyOrders'] += 1 G.LateMeasures['earliness'].append( float(Results[chosenMA]['earliness']) / item['Qty']) 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'] else: 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 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 if itemType == 'order': if chosenMA == None: G.OrderResults.append( (item['orderID'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, oMAlist2, 'NaN', 'NaN', 'None')) mList = '' for i in range(len(oMAlist2)): if i > 0: mList += ', ' mList += oMAlist2[i] G.OrderResultsShort.append((item['orderID'], mList)) else: G.OrderResults.append( (item['orderID'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, oMAlist2, Results[chosenMA]['lateness'], Results[chosenMA]['earliness'], Results[chosenMA]['Allocation'])) mList = '' for i in range(len(oMAlist2)): if i > 0: mList += ', ' mList += oMAlist2[i] G.OrderResultsShort.append((item['orderID'], mList)) if itemType == 'forecast': if chosenMA == None: G.forecastResults.append( (item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], chosenMA, orderedMAlist, 'NaN', 'NaN', 'None')) else: 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'])) if G.minDeltaUt: ACOtargetUtil, ACOminUtil = utilisationCalc1(G.CurrentCapacityDict, initialWeek, ind) else: ACOtargetUtil, ACOminUtil = utilisationCalc2(G.CurrentCapacityDict, initialWeek, ind) return { 'ant': builtAnt, 'excess': ACOexcess, 'earliness': ACOearliness, 'lateness': ACOlateness, 'targetUtil': ACOtargetUtil, 'minUtil': ACOminUtil }
def AllocationRoutine_ACO(initialWeek, itemList, itemType, ant): ACOcapacityDict = deepcopy(G.CurrentCapacityDict) ACOincompleteBatches = deepcopy(G.incompleteBatches) ACOearliness = 0 ACOlateness = 0 ACOtargetUtil = 0 ACOminUtil = 0 ACOexcess = 0 # 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(ACOcapacityDict) qty = item['Qty'] Allocation = [] earliness = 0 lateness = 0 # FIXME: ma 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 # check different MAs if step > 1: capacity = deepcopy(Results[ma]['remainingCap']) inBatches = deepcopy(Results[ma]['remUnits']) qty = deepcopy(Results[ma]['remainingUnits']) Allocation = deepcopy(Results[ma]['Allocation']) earliness = deepcopy(Results[ma]['earliness']) lateness = deepcopy(Results[ma]['lateness']) else: capacity = deepcopy(ACOcapacityDict) inBatches = deepcopy(ACOincompleteBatches) qty = item['Qty'] Allocation = [] earliness = 0 lateness = 0 # try allocation to ma Results[ma] = Allocation2(ma, qty, weekList, capacity, inBatches, 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: ACOcapacityDict = Results[chosenMA]['remainingCap'] ACOincompleteBatches = Results[chosenMA]['remUnits'] ACOearliness += float( Results[chosenMA]['earliness']) / item['Qty'] ACOlateness += float( Results[chosenMA]['lateness']) / item['Qty'] break step += 1 if chosenMA == None: ACOexcess += item['Qty'] if G.minDeltaUt: ACOtargetUtil, ACOminUtil = utilisationCalc1(ACOcapacityDict, initialWeek, ind) else: ACOtargetUtil, ACOminUtil = utilisationCalc3(ACOcapacityDict, initialWeek, ind) return { 'ant': ant, 'excess': ACOexcess, 'earliness': ACOearliness, 'lateness': ACOlateness, 'targetUtil': ACOtargetUtil, 'minUtil': ACOminUtil }
def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): EarlinessMA = {} LatenessMA = {} # repeat allocation procedure for all items in the list for order in seq['seq']: item = itemList[order] # print 'item', item['orderID'] #================================================ # 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 previousAss = {} for ma in G.SPlist[item['sp']]: previousAss[ma] = 0 while step <= 3 and qty > 0: 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)) ] # print 'weeklist', weekList if len(weekList) == 0: step += 1 continue # check different MAs for week in weekList: # optimise MA allocation spAllocation = Allocation_IP(item, week, previousAss, capacity, G.weightFactor) # print 'all', spAllocation # implement optimal MA solution for ma in spAllocation.keys(): if spAllocation[ma]: Results = Allocation2(ma, spAllocation[ma], [week], capacity, G.incompleteBatches, earliness, lateness, Allocation, initialWeek) assert (Results['remainingUnits'] == 0) # update variables capacity = deepcopy(Results['remainingCap']) qty -= spAllocation[ma] Allocation = deepcopy(Results['Allocation']) earliness = deepcopy(Results['earliness']) 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] if qty <= 0: break step += 1 # confirm results if qty <= 0: G.CurrentCapacityDict = Results['remainingCap'] G.incompleteBatches = Results['remUnits'] # print initialWeek, G.Earliness for maT in EarlinessMA: G.Earliness[initialWeek][maT]['qty'].append(item['Qty']) G.Earliness[initialWeek][maT]['earliness'].append( EarlinessMA[maT] / item['Qty']) G.Lateness[initialWeek][maT]['qty'].append(item['Qty']) G.Lateness[initialWeek][maT]['lateness'].append( LatenessMA[maT] / item['Qty']) G.orders[item['orderID']]['Allocation'] = Results['Allocation'] G.orders[item['orderID']]['Excess'] = False chosenMA = [] for allMA in Results['Allocation']: if allMA['ma'] not in chosenMA: chosenMA.append(allMA['ma']) G.orders[item['orderID']]['chosenMA'] = chosenMA for allRep in Results['Allocation']: G.globalMAAllocation[allRep['ma']][allRep['week']][itemType][ item['priority']] += allRep['units'] 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'])) else: G.Excess[item['sp']][initialWeek] += item['Qty'] G.orders[item['orderID']]['Allocation'] = [] G.orders[item['orderID']]['Excess'] = True G.orders[item['orderID']]['chosenMA'] = None if itemType == 'forecast': G.forecastResults.append( (item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], None, 'NaN', 'NaN', 'None'))
def AllocationRoutine_Forecast(initialWeek, itemList, itemType, seq): # repeat allocation procedure for all items in the list for order in seq['seq']: item = itemList[order] # print 'item', item['orderID'] EarlinessMA = {} LatenessMA = {} lateForecast = 0 earlyForecast = 0 #================================================ # Allocation step 1...allocation at current Week #================================================ Results = {} step = 1 ind = G.WeekList.index(initialWeek) weekList = [initialWeek] weekLateness = [0] capacity = deepcopy(G.CurrentCapacityDict) incompleteBatches = deepcopy(G.incompleteBatches) qty = item['Qty'] Allocation = [] earliness = 0 lateness = 0 previousAss = {} for ma in G.SPlist[item['sp']]: 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: if step == 2: 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: 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 if len(weekList) == 0: step += 1 continue # check different MAs for weekIndex in range(len(weekList)): week = weekList[weekIndex] # optimise MA allocation spAllocation, probStatus = Allocation_IP( item, week, previousAss, capacity, G.weightFactor) # print 'all', spAllocation # implement optimal MA solution for ma in spAllocation.keys(): if spAllocation[ma]: Results = Allocation2(ma, spAllocation[ma], [week], capacity, incompleteBatches, earliness, lateness, Allocation, initialWeek) assert (Results['remainingUnits'] == 0) # update variables capacity = deepcopy(Results['remainingCap']) qty -= spAllocation[ma] Allocation = deepcopy(Results['Allocation']) earliness = deepcopy(Results['earliness']) lateness = deepcopy(Results['lateness']) if ma not in EarlinessMA: EarlinessMA[ma] = 0 LatenessMA[ma] = 0 EarlinessMA[ma] += max( [0, weekLateness[weekIndex] * (-1)]) * spAllocation[ma] LatenessMA[ma] += max([ 0, weekLateness[weekIndex] ]) * spAllocation[ma] #week - initialWeek previousAss[ma] += spAllocation[ma] if qty <= 0: break step += 1 # confirm results if qty <= 0: minAss = item['Qty'] * 10 maIB = None G.CurrentCapacityDict = Results['remainingCap'] G.incompleteBatches = Results['remUnits'] # print initialWeek, G.Earliness for maT in EarlinessMA: # assert(Results['remUnits'][maT]==0) G.Earliness[initialWeek][maT]['qty'].append(item['Qty']) G.Earliness[initialWeek][maT]['earliness'].append( EarlinessMA[maT] / item['Qty']) G.Lateness[initialWeek][maT]['qty'].append(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']]['Excess'] = False chosenMA = [] for allMA in Results['Allocation']: if allMA['ma'] not in chosenMA: chosenMA.append(allMA['ma']) 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']: G.globalMAAllocation[allRep['ma']][allRep['week']][itemType][ item['priority']] += allRep['units'] G.globalMAAllocationIW[allRep['ma']][initialWeek][itemType][ item['priority']] += allRep['units'] if itemType == 'forecast': 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: G.Excess[item['sp']][initialWeek] += item['Qty'] G.orders[item['orderID']]['Allocation'] = [] G.orders[item['orderID']]['Excess'] = True 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': G.forecastResults.append( (item['ppos'], item['sp'], item['MAlist'], item['Week'], item['Qty'], item['priority'], None, 'NaN', 'NaN', 'None'))