示例#1
0
def run4(problem):
    jobs = [
        8, 9, 3, 2, 1, 4, 7, 5, 6, 0, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19
    ]
    p = copy.deepcopy(problem)
    n = p.n
    p.earliness_penalties[jobs[0]] = p.earliness_penalties[jobs[0]] + p.a
    p.tardiness_penalties[jobs[0]] = p.tardiness_penalties[jobs[0]] - p.a
    p.earliness_penalties[jobs[n -
                               1]] = p.earliness_penalties[jobs[n - 1]] - p.a
    p.tardiness_penalties[jobs[n -
                               1]] = p.tardiness_penalties[jobs[n - 1]] + p.a
    start = time.process_time()
    memo_BT = bt.init_BT_memo(jobs, problem.due_dates,
                              problem.processing_times)
    memo_ET = et.init_ET_memo(jobs, problem.due_dates,
                              problem.processing_times)
    memo_ETI = dp.init_ETI_memo(jobs, problem.due_dates)
    block_lasts, end_times, eti_penalty1 = dp.opt_ETI(memo_BT, memo_ET,
                                                      memo_ETI,
                                                      utils.BIG_NUMBER, jobs,
                                                      0, n - 1, p)
    end = time.process_time()
    run_time1 = end - start
    print("**************** Main ****************")
    print("********* Basic DP Block Lasts:   *********")
    for i in block_lasts:
        print(i)
    print("********* Basic DP End Times:   *********")
    for i in end_times:
        print(i)
    print("********* Basic DP eti_penalty:   *********")
    print("overall penalty of basic DP:", eti_penalty1)

    start = time.process_time()
    memo_BT = bt.init_BT_memo(jobs, problem.due_dates,
                              problem.processing_times)
    memo_ET = et.init_ET_memo(jobs, problem.due_dates,
                              problem.processing_times)
    memo_ETI_bounded = dpb.init_ETI_memo_bounded(jobs, problem.due_dates)
    block_lasts, end_times, eti_penalty2 = dpb.opt_ETI_Bounded(
        memo_BT, memo_ET, memo_ETI_bounded, utils.BIG_NUMBER, n - 1, jobs, 0,
        n - 1, p)
    end = time.process_time()
    run_time2 = end - start
    print("**************** Main ****************")
    print("********* Bounded DP Block Lasts:   *********")
    for i in block_lasts:
        print(i)
    print("********* Bounded DP End Times:   *********")
    for i in end_times:
        print(i)
    print("********* Bounded DP eti_penalty:   *********")
    print("overall penalty of basic DP:", eti_penalty2)
    print("******************")
    print("runtime 1", run_time1)
    print("runtime 2", run_time2)
示例#2
0
 def cal_Fitness_Value(self, chromo, et_global_solution):
     if self.memo_FV.get(tuple(chromo)):
         return self.memo_FV[(tuple(chromo))].eti_penalty
     p = copy.deepcopy(self.problem)
     p.earliness_penalties[
         chromo[0]] = p.earliness_penalties[chromo[0]] + p.a
     p.tardiness_penalties[
         chromo[0]] = p.tardiness_penalties[chromo[0]] - p.a
     p.earliness_penalties[chromo[
         self.n - 1]] = p.earliness_penalties[chromo[self.n - 1]] - p.a
     p.tardiness_penalties[chromo[
         self.n - 1]] = p.tardiness_penalties[chromo[self.n - 1]] + p.a
     # memos
     memo_BT = bt.init_BT_memo(chromo, p.due_dates, p.processing_times)
     memo_ET = et.init_ET_memo(chromo, p.due_dates, p.processing_times)
     memo_ETI = dp.init_ETI_memo(chromo)
     block_lasts, end_times, eti_penalty, _ = dp.opt_ETI(
         memo_BT, memo_ET, memo_ETI, et_global_solution, utils.BIG_NUMBER,
         chromo, self.n - 1, p)
     # if self.iter == 0:
     #     print(eti_penalty)
     real_obj, b_ratio = self.cal_Real_Objective(chromo, block_lasts,
                                                 end_times, self.problem)
     self.memo_FV[tuple(chromo)] = utils.Solution(block_lasts, end_times,
                                                  real_obj, b_ratio)
     return real_obj
示例#3
0
def run1(problem):
    # print('"***************  Single Machine Scheduling with E/T/I Penalties  ***************"')
    # jobs=[3,2,1,4,0]
    # jobs = [4,7]
    # jobs = [8, 9, 3, 2, 1, 4, 7, 5, 6, 0,10,11,12,13,14,15,16,17,18,19]
    jobs = [1, 4, 2, 0, 3]
    # due2 = list(problem.due_dates)
    # due2, jobs = zip(*sorted(zip(due2, jobs)))

    # The variable part of idleness penalty is absorbed by the first job and the last job.
    p = copy.deepcopy(problem)
    p.earliness_penalties[jobs[0]] = p.earliness_penalties[jobs[0]] + p.a
    p.tardiness_penalties[jobs[0]] = p.tardiness_penalties[jobs[0]] - p.a
    p.earliness_penalties[jobs[n -
                               1]] = p.earliness_penalties[jobs[n - 1]] - p.a
    p.tardiness_penalties[jobs[n -
                               1]] = p.tardiness_penalties[jobs[n - 1]] + p.a

    start = time.process_time()
    memo_BT = bt.init_BT_memo(jobs, problem.due_dates,
                              problem.processing_times)
    memo_ET = et.init_ET_memo(jobs, problem.due_dates,
                              problem.processing_times)
    memo_ETI = dp.init_ETI_memo(jobs, problem.due_dates)
    block_lasts, end_times, eti_penalty1 = dp.opt_ETI(memo_BT, memo_ET,
                                                      memo_ETI,
                                                      utils.BIG_NUMBER, jobs,
                                                      0, n - 1, p)
    end = time.process_time()
    run_time1 = end - start
    print("**************** Main ****************")
    print("*********  DP block lasts:   *********")
    for i in block_lasts:
        print(i)
    print("*********  DP end times:   *********")
    for i in end_times:
        print(i)
    print("*********  DP eti_penalty:   *********")
    print("overall penalty of DP:", eti_penalty1)

    start = time.process_time()
    eti_penalty2, test_model = test.test_DP(jobs, problem.b, problem.due_dates,
                                            problem.processing_times,
                                            problem.earliness_penalties,
                                            problem.tardiness_penalties)
    end = time.process_time()
    run_time2 = end - start
    print("*********  DP eti_penalty:   *********")
    print("overall penalty of DP:", eti_penalty1)
    print("*********  DP runtime:   *********")
    print(run_time1)
    print("*********  CPLEX eti_penalty:   *********")
    print("overall penalty of CPLEX:", eti_penalty2)
    print("*********  CPLEX runtime:   *********")
    print(run_time2)
    return round(eti_penalty1), round(eti_penalty2), block_lasts, test_model
示例#4
0
def run9_0(p, jobs):
    # sys.setrecursionlimit(2000)
    start = time.process_time()
    memo_BT = bt.init_BT_memo(jobs, p.due_dates, p.processing_times)
    memo_ET = et.init_ET_memo(jobs, p.due_dates, p.processing_times)
    memo_ETI = dp.init_ETI_memo(jobs, p.due_dates)
    _, _, eti_penalty1, cplex_time = dp.opt_ETI(memo_BT, memo_ET, memo_ETI,
                                                utils.BIG_NUMBER, jobs,
                                                p.n - 1, p)
    end = time.process_time()
    run_time1 = end - start
    f = open('My_DP_results_0725.txt', 'a')
    f.write(
        str(p.n) + "\t" + str(p.b) + "\t" + str(p.rho) + "\t" +
        str(run_time1) + "\t" + str(cplex_time) + "\n")
    f.close()
示例#5
0
def run9(p, jobs):
    sys.setrecursionlimit(1200)
    start = time.process_time()
    memo_BT = bt.init_BT_memo(jobs, p.due_dates, p.processing_times)
    memo_ET = et.init_ET_memo(jobs, p.due_dates, p.processing_times)
    et_global_solution = et.init_ET_global_solution(jobs, p)
    memo_ETI = dpb.init_ETI_memo_bounded(jobs)
    block_lasts, _, eti_penalty1, cplex_time = dpb.opt_ETI_Bounded(
        memo_BT, memo_ET, memo_ETI, et_global_solution, utils.BIG_NUMBER,
        p.n - 1, jobs, p.n - 1, p)
    end = time.process_time()
    run_time1 = end - start
    num_idle = len(block_lasts) - 1
    f = open('My_DP_Bounded_0725.txt', 'a')
    f.write(
        str(p.n) + "\t" + str(p.b) + "\t" + str(p.rho) + "\t" +
        str(run_time1) + "\t" + str(eti_penalty1) + "\t" + str(num_idle) +
        "\n")
    f.close()