コード例 #1
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
コード例 #2
0
def schrage_n2_pmtn(tasks):
    start = timer()
    W_tasks = []  # temporary order
    G_tasks = []  # ready to order tasks
    N_tasks = copy.deepcopy(tasks)
    t = get_min(get_column(N_tasks, 0))
    q_0 = 99999999
    task_l = Task(0, [0, 0, q_0])  # current task
    cmax = 0

    while len(N_tasks) != 0 or len(G_tasks) != 0:
        while len(N_tasks) != 0 and get_min(get_column(N_tasks, 0)) <= t:
            j = np.argmin(get_column(N_tasks, 0))
            task_j = copy.deepcopy(N_tasks[j])
            del N_tasks[j]
            G_tasks.append(task_j)
            if task_j.times[2] > task_l.times[2]:
                task_l.times[1] = t - task_j.times[0]
                t = task_j.times[0]
                if task_l.times[1] > 0:
                    G_tasks.append(task_l)
        if len(G_tasks) == 0:
            t = get_min(get_column(N_tasks, 0))
        else:
            j = np.argmax(get_column(G_tasks, 2))
            task_j = copy.deepcopy(G_tasks[j])
            del G_tasks[j]
            t += task_j.times[1]
            cmax = max(cmax, t + task_j.times[2])
            task_l = copy.deepcopy(task_j)
            W_tasks.append(task_j)
    stop = timer()
    return cmax, get_order(W_tasks), (stop-start)*1000
コード例 #3
0
def schrage_nlogn(tasks):
    start = timer()
    N_tasks = heap_min.Heap()

    # insert tasks
    for task in tasks:
        N_tasks.insert(task)

    G_tasks = heap_max.Heap()
    W_tasks = []  # temporary order

    t = N_tasks.root().times[0]  # min r value

    cmax = 0

    while N_tasks.count() != 0 or G_tasks.count() != 0:
        while N_tasks.count() != 0 and N_tasks.root().times[0] <= t:
            G_tasks.insert(N_tasks.remove())
        if G_tasks.count() == 0:
            t = N_tasks.root().times[0]
        else:
            task_j = G_tasks.remove()
            t += task_j.times[1]
            cmax = max(cmax, t + task_j.times[2])
            W_tasks.append(task_j)
    stop = timer()
    return get_order(W_tasks), (stop-start)*1000
コード例 #4
0
def improved_simulated_annealing(tasks, numb_of_machines, temperature, final_temperature, u, cooling_fcn_type, move_type,
                        insert, custom_order=""):

    max_iterations_number = get_max_iterations_number(temperature, final_temperature, u)

    start = timer()

    # step 1: create initial order
    if custom_order == "":
        order = get_order(tasks)
    else:
        order = copy.deepcopy(custom_order)

    iterations = 0
    for i in range(0, max_iterations_number):
        # step 2: generate movement
        new_order = copy.deepcopy(order)
        if insert == 0:
            swap_random_tasks(new_order)
        elif insert == 1:
            insert_random_task(new_order)

        # step 3: make a move or not
        probability = get_probability_sa(order, new_order, tasks, numb_of_machines, temperature, move_type)
        if decision(probability):
            order = copy.deepcopy(new_order)

        # step 4: cooling down
        temperature = cool_down_fcn(temperature, u, cooling_fcn_type, iterations, max_iterations_number)

        iterations += 1

    stop = timer()

    return order, iterations, (stop-start)*1000
コード例 #5
0
def simulated_annealing(tasks, temperature, min_temperature, u):
    start = timer()
    # step 1: create initial order
    order = get_order(tasks)

    while temperature > min_temperature:
        # step 2: generate movement
        new_order = copy.deepcopy(order)
        swam_random_tasks(new_order)

        # step 3: make a move or not
        probability = get_probability(order, new_order, tasks, temperature)
        if decision(probability):
            order = copy.deepcopy(new_order)

        # step 4: cooling down
        temperature = cool_down_fcn(temperature, u)
    stop = timer()
    return order, (stop - start) * 1000
コード例 #6
0
def schrage_n2(tasks):
    start = timer()
    W_tasks = []  # temporary order
    G_tasks = []  # ready to order tasks
    N_tasks = copy.deepcopy(tasks)
    t = get_min(get_column(N_tasks, 0))

    while len(N_tasks) != 0 or len(G_tasks) != 0:
        while len(N_tasks) != 0 and get_min(get_column(N_tasks, 0)) <= t:
            j = np.argmin(get_column(N_tasks, 0))
            G_tasks.append(N_tasks[j])
            del N_tasks[j]
        if len(G_tasks) == 0:
            t = get_min(get_column(N_tasks, 0))
        else:
            j = np.argmax(get_column(G_tasks, 2))
            t += G_tasks[j].times[1]
            W_tasks.append(G_tasks[j])
            del G_tasks[j]
    stop = timer()
    return get_order(W_tasks), (stop-start)*1000
コード例 #7
0
def schrage_nlogn_pmtn(tasks):
    start = timer()
    N_tasks = heap_min.Heap()

    # insert tasks
    for task in tasks:
        N_tasks.insert(task)

    G_tasks = heap_max.Heap()
    W_tasks = []  # temporary order

    t = N_tasks.root().times[0]  # min r value

    cmax = 0

    q_0 = 99999999
    task_l = Task(0, [0, 0, q_0])  # current task

    while N_tasks.count() != 0 or G_tasks.count() != 0:
        while N_tasks.count() != 0 and N_tasks.root().times[0] <= t:
            task_j = N_tasks.remove()
            G_tasks.insert(task_j)
            if task_j.times[2] > task_l.times[2]:
                task_l.times[1] = t - task_j.times[0]
                t = task_j.times[0]
                if task_l.times[1] > 0:
                    G_tasks.insert(task_l)  # continue paused
        if G_tasks.count() == 0:
            t = N_tasks.root().times[0]
        else:
            task_j = G_tasks.remove()
            t += task_j.times[1]
            cmax = max(cmax, t + task_j.times[2])
            task_l = copy.deepcopy(task_j)
            W_tasks.append(task_j)
    stop = timer()
    return cmax, get_order(W_tasks), (stop-start)*1000
コード例 #8
0
import copy
from datareader import get_data
from makespan import makespan, to_natural_order, get_order
from schrage import schrage_n2, schrage_n2_pmtn, schrage_nlogn, schrage_nlogn_pmtn
from random_search import random_search

tasks = get_data("in50.txt")

# INITIAL ORDER
init_order = get_order(tasks)
init_makespan = makespan(init_order, tasks)
print("[INIT] makespan: ", init_makespan)

# SCHRAGE ORDER
schrage_n2_order, schrage_n2_time = schrage_n2(tasks)
shrage_n2_makespan = makespan(schrage_n2_order, tasks)
#print("[SHRAGE N^2] order: ", schrage_n2_order)
print("[SHRAGE N^2] makespan: {}, time: {}" .format(shrage_n2_makespan, schrage_n2_time))

# SCHRAGE ORDER NLOGN
schrage_nlogn_order, schrage_nlogn_time = schrage_nlogn(tasks)
schrage_nlogn_makespan = makespan(schrage_nlogn_order, tasks)
#print("[SHRAGE NLOGN] order: ", schrage_nlogn_order)
print("[SHRAGE NLOGN] makespan: {}, time: {}" .format(schrage_nlogn_makespan, schrage_nlogn_time))

#SCHRAGE ORDER N2 PMTN
schrage_n2_ptmn_makespan, schrage_n2_ptmn_order, schrage_n2_ptmn_time = schrage_n2_pmtn(tasks)
print("[SHRAGE N^2 PMTN] makespan: {}, time: {}" .format(schrage_n2_ptmn_makespan, schrage_n2_ptmn_time))

#SCHRAGE ORDER NLOGN PMTN
schrage_nlogn_pmtn_makespan, schrage_nlogn_pmtn_order, schrage_nlogn_pmtn_time = schrage_nlogn_pmtn(tasks)