def sym_wyzarzanie1(tasks_val, tasks, machines_val, T_start, T_end):
    # pi0 = []
    # for i in range(0, tasks_val):
    #     pi0.append(i)
    # cmax0 = makespan(pi0, tasks, machines_val)
    pi0, cmax0 = neh.neh(tasks, machines_val, tasks_val)  #bierzemy z neha
    pi = pi0
    cmax_old = cmax0
    T0 = T_start  #temp poczatkowa
    T = T0
    u = 0.99  #wspolczynnik chlodzenia
    Tgr = T_end  #temp koncowa
    while (T >= Tgr):
        #piprim = swap(pi, tasks_val)
        piprim = insert(pi, tasks_val)  #uzywam inserta
        cmax = neh.makespan(piprim, tasks, machines_val)
        p = probability(cmax_old, cmax, T)  #licze P wykonania kroku
        s = ran.random()
        if p >= s:
            pi = piprim
            cmax_old = cmax
            T = chlodzenie1(T, u)  #podstawowe chlodzenie
        else:
            T = chlodzenie1(T, u)
    return pi, cmax_old
def sym_wyzarzanie2(tasks_val, tasks, machines_val, T_start, T_end, iter_val):
    # pi0 = []
    # for i in range(0, tasks_val):
    #     pi0.append(i)
    # cmax0 = makespan(pi0, tasks, machines_val)
    pi0, cmax0 = neh.neh(tasks, machines_val, tasks_val)
    pi = pi0
    cmax_old = cmax0
    T0 = T_start
    T = T0
    u = 0.99
    Tgr = T_end
    iter = 0
    max_iter = iter_val

    for i in range(0, max_iter):  #chlodzenie 2 jest na iteracje
        iter = iter + 1
        #piprim = swap(pi, tasks_val)
        piprim = insert(pi, tasks_val)
        cmax = neh.makespan(piprim, tasks, machines_val)
        p = probability(cmax_old, cmax, T)
        s = ran.random()
        if p >= s:
            pi = piprim
            cmax_old = cmax
            T = chlodzenie2(T, iter, max_iter)
        else:
            T = chlodzenie2(T, iter, max_iter)
        #print(T)
        if T == 0:
            break
    return pi, cmax_old
def sym_wyzarzanie4(tasks_val, tasks, machines_val, T_start, T_end):
    # pi0 = []
    # for i in range(0, tasks_val):
    #     pi0.append(i)
    # cmax0 = makespan(pi0, tasks, machines_val)
    pi0, cmax0 = neh.neh(tasks, machines_val, tasks_val)
    pi = pi0
    cmax_old = cmax0
    T0 = T_start
    T = T0
    u = 0.99
    Tgr = T_end
    while (T >= Tgr):
        #piprim = swap(pi, tasks_val)
        piprim = insert(pi, tasks_val)
        cmax = neh.makespan(piprim, tasks, machines_val)
        if cmax_old != cmax:
            p = probability4(cmax_old, cmax, T)
            s = ran.random()
            if p >= s:
                pi = piprim
                cmax_old = cmax
                T = chlodzenie1(T, u)
            else:
                T = chlodzenie1(T, u)
    return pi, cmax_old