def AllocationRoutine_ForecastGA(initialWeek, itemList, itemType, chromo):

    EarlinessMA = {}
    LatenessMA = {}

    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 = Allocation_IP(item, week, previousAss, capacity, G.weightFactor)

                # implement optimal MA solution to update temporary variables
                for ma in spAllocation.keys():
                    if spAllocation[ma]:
                        Results = Allocation2(ma, spAllocation[ma], [week], capacity, inBatches, earliness, lateness, Allocation, initialWeek)
                        assert (Results['remainingUnits'] == 0)
                        
                        # update order variables
                        capacity = deepcopy(Results['remainingCap'])
                        inBatches = deepcopy(Results['remUnits'])
                        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 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_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
    }
Пример #4
0
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_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_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'))
            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']))
                
        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}