def carlier(self,tasks): order, U, C = schrage.schrage(tasks) i = 0 if U < self.UB: self.UB = U b = find_b(order, U, C) a = find_a(order, U, b) c = find_c(a, b, order) if c is None: return self.UB,order_only_id(order) R_prim, P_prim, Q_prim = find_RPQ(order, b, c) R_saved = order[c].get_r() order[c].change_r(max(order[c].get_r(), P_prim + R_prim)) LB = schrage.schrage_pmtn(tasks) if LB < self.UB: self.carlier(tasks) order[c].change_r(R_saved) Q_saved = order[c].get_q() order[c].change_q(max(order[c].get_q(), P_prim + Q_prim)) LB = schrage.schrage_pmtn(tasks) if LB < self.UB: self.carlier(tasks) order[c].change_q(Q_saved) return self.UB, order_only_id(order)
def leftNodeThread(pi, a, b, c, r_1, p_1, q_1): pi2 = pi r_pi2_c = pi2[c].times[0] pi2[c].times[0] = max(pi2[c].times[0], r_1 + p_1) p_3 = 0 r_3 = pi2[c].times[0] q_3 = pi2[c].times[2] for i in range(c, b + 1): p_3 += pi2[i].times[1] if r_3 > pi2[i].times[0]: r_3 = pi2[i].times[0] if q_3 > pi2[i].times[2]: q_3 = pi2[i].times[2] lb2, ptmn_order2 = schrage_pmtn(copy.deepcopy(pi2)) lb2 = max(max(r_1 + q_1 + p_1, r_3 + q_3 + p_3), lb2) if lb2 < ub: pi_list.append(copy.deepcopy(pi2)) pi2[c].times[0] = r_pi2_c
def rightNodeThread(pi, a, b, c, r_1, p_1, q_1): pi1 = pi r_pi1_c = pi1[c].times[2] pi1[c].times[2] = max(pi1[c].times[2], q_1 + p_1) p_2 = 0 r_2 = pi1[c].times[0] q_2 = pi1[c].times[2] for i in range(c, b + 1): p_2 += pi1[i].times[1] if r_2 > pi1[i].times[0]: r_2 = pi1[i].times[0] if q_2 > pi1[i].times[2]: q_2 = pi1[i].times[2] lb1, order1 = schrage_pmtn(copy.deepcopy(pi1)) lb1 = max(max(r_1 + q_1 + p_1, r_2 + q_2 + p_2), lb1) if lb1 < ub: pi_list.append(copy.deepcopy(pi1)) pi1[c].times[2] = r_pi1_c
def carlier_dl(tasks): global ub global pi u, pi = schrage(copy.deepcopy(tasks)) if u < ub: ub = u # find b, a, c values b = calculate_b(u, pi) a = calculate_a(b, u, pi) c = calculate_c(b, a, pi) # if c doesn't exist if c < 0: return ub # calculate r1, p1, q1 r_1 = pi[c + 1].times[0] p_1 = 0 q_1 = pi[c + 1].times[2] for i in range(c + 1, b + 1): p_1 += pi[i].times[1] if r_1 > pi[i].times[0]: r_1 = pi[i].times[0] if q_1 > pi[i].times[2]: q_1 = pi[i].times[2] # LEFT NODE r_pi_c = pi[c].times[0] pi[c].times[0] = max(pi[c].times[0], r_1 + p_1) p_2 = 0 r_2 = pi[c].times[0] q_2 = pi[c].times[2] for i in range(c, b + 1): p_2 += pi[i].times[1] if r_2 > pi[i].times[0]: r_2 = pi[i].times[0] if q_2 > pi[i].times[2]: q_2 = pi[i].times[2] lb, ptmn_order = schrage_pmtn(copy.deepcopy(pi)) lb = max(max(r_1 + q_1 + p_1, r_2 + q_2 + p_2), lb) if lb < ub: ub = carlier_dl(copy.deepcopy(pi)) pi[c].times[0] = r_pi_c # RIGHT NODE r_pi_c = pi[c].times[2] pi[c].times[2] = max(pi[c].times[2], q_1 + p_1) p_2 = 0 r_2 = pi[c].times[0] q_2 = pi[c].times[2] for i in range(c, b + 1): p_2 += pi[i].times[1] if r_2 > pi[i].times[0]: r_2 = pi[i].times[0] if q_2 > pi[i].times[2]: q_2 = pi[i].times[2] lb, order = schrage_pmtn(copy.deepcopy(pi)) lb = max(max(r_1 + q_1 + p_1, r_2 + q_2 + p_2), lb) if lb < ub: ub = carlier_dl(copy.deepcopy(pi)) pi[c].times[2] = r_pi_c return ub
def carlier_wl(tasks): # ----- "GLOBAL" VARIABLES DECLARATION ----- # # u: cmax for schrage # pi: tasks sorted with schrage # ub: upper border # lb: lower border global u global pi global ub global lb global pi_list u, pi = schrage(copy.deepcopy(pi_list[0])) if u < ub: ub = u # find b, a, c values b = calculate_b(u, pi) a = calculate_a(b, u, pi) c = calculate_c(b, a, pi) # if c doesn't exist if c < 0: return ub # calculate r1, p1, q1 r_1 = pi[c + 1].times[0] p_1 = 0 q_1 = pi[c + 1].times[2] for i in range(c + 1, b + 1): p_1 += pi[i].times[1] if r_1 > pi[i].times[0]: r_1 = pi[i].times[0] if q_1 > pi[i].times[2]: q_1 = pi[i].times[2] # LEFT NODE r_pi_c = pi[c].times[0] pi[c].times[0] = max(pi[c].times[0], r_1 + p_1) p_2 = 0 r_2 = pi[c].times[0] q_2 = pi[c].times[2] for i in range(c, b + 1): p_2 += pi[i].times[1] if r_2 > pi[i].times[0]: r_2 = pi[i].times[0] if q_2 > pi[i].times[2]: q_2 = pi[i].times[2] lb, ptmn_order = schrage_pmtn(copy.deepcopy(pi)) lb = max(max(r_1 + q_1 + p_1, r_2 + q_2 + p_2), lb) if lb < ub: pi_list.append(copy.deepcopy(pi)) pi[c].times[0] = r_pi_c # RIGHT NODE r_pi_c = pi[c].times[2] pi[c].times[2] = max(pi[c].times[2], q_1 + p_1) p_2 = 0 r_2 = pi[c].times[0] q_2 = pi[c].times[2] for i in range(c, b + 1): p_2 += pi[i].times[1] if r_2 > pi[i].times[0]: r_2 = pi[i].times[0] if q_2 > pi[i].times[2]: q_2 = pi[i].times[2] lb, order = schrage_pmtn(copy.deepcopy(pi)) lb = max(max(r_1 + q_1 + p_1, r_2 + q_2 + p_2), lb) if lb < ub: pi_list.append(copy.deepcopy(pi)) pi[c].times[2] = r_pi_c # remove checked node from the list pi_list.pop(0) if len(pi_list) > 0: return carlier_wl(tasks)