def order_type(LM, LT, MCoeff, esp):
    """ input : List of machines, List of tasks, Array of coefficients, Double for the coefficient*LB wanted
        output : List of mahines
        order type depending on Mcoeff
        then allocate tasks with the LB criteria
        very good if not all types are compatible: because all coeffs on a machine will be 1 while they could be less if mixed
    """

    LM = data_structure.create_LM(len(LM))
    LB = borne_inf(LT, LM, MCoeff)
    #LT = sorted(LT, key = itemgetter('size'), reverse=True)

    # allocate task in the right order
    machine = 0
    for Type in ordered_types:
        for task in LT:
            # append tasks of this one type
            if task['type'] == Type:
                LM[machine]['LTM'].append(task)
                if ((data_structure.cost_M_gen(LM[machine], MCoeff)) >
                        esp * LB):

                    LM[machine]['LTM'].remove(task)
                    # trier les taches de la machine par ordre décroissant
                    LM[machine]['LTM'] = sorted(LM[machine]['LTM'],
                                                key=itemgetter('size'),
                                                reverse=True)
                    machine += 1

                    if (machine == len(LM)):

                        #print ("pas de machine libre")

                        return 0

                    LM[machine]['LTM'].append(task)

    # cas ou il reste des machines libres
    for machine in range(len(LM)):

        if not LM[machine]["LTM"]:  # this machine is empty

            # try to fit tasks from the most charged machine(s) on the empty machine
            most_charged = data_structure.max_ind_cost_LM_gen(LM, MCoeff)
            #print(len(most_charged))

            coutMax = data_structure.cost_M_gen(LM[most_charged[0]], MCoeff)

            for heavy_machine in most_charged:

                last_task = LM[heavy_machine]['LTM'][-1]
                # add last task to empty machine
                LM[machine]['LTM'].append(last_task)
                if data_structure.cost_M_gen(LM[machine], MCoeff) >= coutMax:
                    LM[machine]['LTM'].remove(last_task)
                    break
                # remove last task from heavy machine
                LM[heavy_machine]['LTM'].remove(last_task)

    return LM
예제 #2
0
def SchedJuxtapose(LM, LT, Mcoeff, algo=PTAS.PTAS):
    """Return the combination of M1 and M2 which costs the least"""

    LT1 = LTCutinTwo(LT)[0]
    LT2 = LTCutinTwo(LT)[1]

    Perm = PermutationGenerator(len(LM))

    CostC1list = []
    CostC2list = []
    CostEachMax = []

    for i in range(len(LM) - 1):
        LM1 = ds.create_LM(Perm[i][0])
        if Perm[i][0] == 1:
            LM1_done = lpt.lpt(LM1, LT1, Mcoeff)
        else:
            LM1_done = algo(
                LM1, LT1, Mcoeff, len(LT1)
            )  #LM1_done is a list of list which contains all Type1 tasks optimally distributed(using algopart M1 of M
        CostC1 = 0  # Reinitialisation of CostC1
        CostC1 = lpt.final_cost_LM_1type(
            LM1_done
        )  # we stock the cost of the machine which has the maximum cost
        CostC1list.append(
            CostC1)  # We stock the CostC1 of each combination in CostC1List[]

    for j in range(len(LM) - 1):
        LM2 = ds.create_LM(Perm[j][1])
        if Perm[j][1] == 1:
            LM2_done = lpt.lpt(LM2, LT2, Mcoeff)
        else:
            LM2_done = algo(
                LM2, LT2, Mcoeff, len(LT2)
            )  # LM2_done is a list of list which contains all Type2 tasks optimally distributed(using LPT) to part M2 of M
        CostC2 = 0  # Reinitialisation of CostC2
        CostC2 = lpt.final_cost_LM_1type(
            LM2_done
        )  # we stock the cost of the machine which has the maximum cost
        CostC2list.append(
            CostC2)  # We stock the CostC2 of each combination in CostC2List[]

    # We aim to find the min(max(CostC1list[k],CostC2list[k])), then k-th element in Perm would be the most optimal combination
    # 1st step: we stock each max(CostC1list[k],CostC2list[k]) in CostEachMax[]
    for k in range(len(LM) - 1):
        eachMax = max(CostC1list[k], CostC2list[k])
        CostEachMax.append(eachMax)

    # 2nd step: we find the indice that contains the minimal value in the list CostEachMax
    indiceMin = CostEachMax.index(min(CostEachMax))
    LM1f = ds.create_LM(Perm[indiceMin][0])
    if Perm[indiceMin][0] == 1:
        LM1f_done = lpt.lpt(LM1f, LT1, Mcoeff)
    else:
        LM1f_done = algo(LM1f, LT1, Mcoeff, 5)
    LM2f = ds.create_LM(Perm[indiceMin][1])
    if Perm[indiceMin][1] == 1:
        LM2f_done = lpt.lpt(LM2f, LT2, Mcoeff)
    LM2f_done = algo(LM2f, LT2, Mcoeff, 5)
    LM = LM1f_done + LM2f_done
    return LM