def neh(tasks, numb_of_machines):
    start = timer()
    # step 1: find omegas(j)
    omegas = []
    for task in tasks:
        omegas.append(sum(task.times))

    # step 2: sort in descending order (get sorted order)
    omegas_order = np.argsort(-np.array(omegas)).tolist()

    # steps 3, 4: repeat n times (n = numb of tasks)
    solution_order = []
    for i in omegas_order:  # (3) get task with the highest omega value
        # (4) insert task & pick task with the lowest makespan
        lowest_makespan = float("inf")
        lowest_makespan_sequence = []
        sequences = get_sequences(i, solution_order)

        for sequence in sequences:
            if makespan(sequence, tasks, numb_of_machines) < lowest_makespan:
                lowest_makespan = makespan(sequence, tasks, numb_of_machines)
                lowest_makespan_sequence = sequence
        solution_order = lowest_makespan_sequence
    #print(lowest_makespan)
    stop = timer()
    return solution_order, (stop - start) * 1000
示例#2
0
def ta000Instance(choice):
    #  Loading a ta000 instance
    if choice == 1:
        tasks, numb_of_machines = get_data("ta000_2")
    elif choice == 2:
        tasks, numb_of_machines = get_data("ta000_3")

    #  searching for min makespan with Bruteforce
    bruteforce_order, bruteforce_time = bruteforce(copy.deepcopy(tasks),
                                                   numb_of_machines)
    bruteforce_makespan = makespan(bruteforce_order, tasks, numb_of_machines)

    #  searching for min makespan with Johnson
    johnson_order, johnson_time = johnson(copy.deepcopy(tasks),
                                          numb_of_machines)
    johnson_makespan = makespan(johnson_order, tasks, numb_of_machines)

    #  descriptions
    print("---------------------------")
    print("Best order (Bruteforce): {}".format(bruteforce_order))
    print("Best makespan (Bruteforce): {}".format(bruteforce_makespan))

    print("Best order (Johnson): {}".format(johnson_order))
    print("Best makespan (Johnson): {}".format(johnson_makespan))

    #  plot figures
    plt = draw_gantt(bruteforce_order, tasks, numb_of_machines,
                     bruteforce_time, "Podzial zadan (przeglad zupelny)")
    plt = draw_gantt(johnson_order, tasks, numb_of_machines, johnson_time,
                     "Podzial zadan (algorytm Johnsona)")
    plt = draw_gantt(get_order(tasks), tasks, numb_of_machines, 0,
                     "Podzial zadan (naturalna kolejnosc)")
    plt.show()
def generating(iter):
    number_of_machines = int(input("Ile maszyn?: "))
    number_of_tasks = int(input("Ile zadan?: "))
    bruteforceSpan = []
    johnsonSpan = []
    nehSpan = []
    durationBruteforce = []
    durationJohnson = []
    durationNeh = []
    i = 0
    while i < iter:
        generatedTasks = []
        cnt_tasks = 0
        cnt_machines = 0
        for cnt_tasks in range(0, number_of_tasks):
            rows = []
            for cnt_machines in range(0, number_of_machines):
                rows.append(int(random.uniform(1, 10)))
            print("{}".format(rows))
            generatedTasks.append(Task(cnt_tasks, rows))
        bruteforceOrder, timeBruteforce = bruteforce(
            copy.deepcopy(generatedTasks), number_of_machines)
        johnsonOrder, timeJohnson = johnson(copy.deepcopy(generatedTasks),
                                            number_of_machines)
        nehOrder, timeNeh = neh(copy.deepcopy(generatedTasks),
                                number_of_machines)
        durationBruteforce.append(timeBruteforce)
        durationJohnson.append(timeJohnson)
        durationNeh.append(timeNeh)
        bruteforceMakespan = makespan(bruteforceOrder, generatedTasks,
                                      number_of_machines)
        johnsonMakespan = makespan(johnsonOrder, generatedTasks,
                                   number_of_machines)
        nehMakespan = makespan(nehOrder, generatedTasks, number_of_machines)
        bruteforceSpan.append(bruteforceMakespan)
        johnsonSpan.append(johnsonMakespan)
        nehSpan.append(nehMakespan)
        i += 1

    x = PrettyTable()
    print("")
    print("----------------------------------------------------------")
    x.field_names = [
        "l.p.", "Bruteforce makespan", "Johnson makespan", "Neh makespan",
        "Czas bruteforce [ms]", "Czas Johnson [ms]", "Czas Neh [ms]"
    ]

    k = 0
    for k in range(0, iter):
        x.add_row([
            k + 1, "{}".format(bruteforceSpan[k]), "{}".format(johnsonSpan[k]),
            "{}".format(nehSpan[k]), "{}".format(durationBruteforce[k]),
            "{}".format(durationJohnson[k]), "{}".format(durationNeh[k])
        ])
    print(x)
def IR4_mod(tasks, solution_order, numb_of_machines):
    maxDiff = 0
    baseTime = makespan(solution_order, tasks, numb_of_machines)
    for i in solution_order:
        idx = solution_order.index(i)
        solution_order.remove(i)
        tempTime = makespan(solution_order, tasks, numb_of_machines)
        if baseTime - tempTime > maxDiff:
            maxDiff = baseTime - tempTime
            maxTask = i
        solution_order.insert(idx, i)
    return maxTask
示例#5
0
def bruteforce(tasks, numb_of_machines):
    start = timer()
    best_order = get_order(tasks)
    best_makespan = makespan(best_order, tasks, numb_of_machines)

    for p in permute(get_order(tasks)):
        print("order: {}" .format(p))
        print("makespan: {}" .format(makespan(p, tasks, numb_of_machines)))
        print("---")
        if makespan(p, tasks, numb_of_machines) < best_makespan:
            best_order = list(p)
            best_makespan = makespan(p, tasks, numb_of_machines)
    stop = timer()
    return best_order, (stop-start)*1000
def test():
    tasks, numb_of_machines = get_data("data.090")
    neh_order, neh_time = qneh(copy.deepcopy(tasks), numb_of_machines,0)
    print ("Neh time: {}".format(neh_time))
    print ("Makespan {}".format(makespan(neh_order, tasks, numb_of_machines)))
    neh_order, neh_time = qneh(copy.deepcopy(tasks), numb_of_machines,1)
    print ("Neh mod1 time: {}".format(neh_time))
    print ("Makespan {}".format(makespan(neh_order, tasks, numb_of_machines)))
    neh_order, neh_time = qneh(copy.deepcopy(tasks), numb_of_machines,2)
    print ("Neh mod2 time: {}".format(neh_time))
    print ("Makespan {}".format(makespan(neh_order, tasks, numb_of_machines)))
    neh_order, neh_time = qneh(copy.deepcopy(tasks), numb_of_machines,3)
    print ("Neh mod3 time: {}".format(neh_time))
    print ("Makespan {}".format(makespan(neh_order, tasks, numb_of_machines)))
    neh_order, neh_time = qneh(copy.deepcopy(tasks), numb_of_machines,4)
    print ("Neh mod4 time: {}".format(neh_time))
    print ("Makespan {}".format(makespan(neh_order, tasks, numb_of_machines)))
import copy
from src.datareader import get_data
from src.neh import neh
from src.makespan import makespan, to_natural_order
from src.qneh import qneh

tasks, numb_of_machines = get_data("data.050")
# searching for min makespan with NEH
neh_order, neh_time = neh(copy.deepcopy(tasks), numb_of_machines)
neh_makespan = makespan(neh_order, tasks, numb_of_machines)
print("[NEH] makespan: {}, time: {}".format(neh_makespan, neh_time))

print(
    "------------------------------------------------------------------------")
neh_order, neh_time = qneh(copy.deepcopy(tasks), numb_of_machines, 0)
neh_makespan = makespan(neh_order, tasks, numb_of_machines)
print("[qNEH] makespan: {}, time: {}".format(neh_makespan, neh_time))