Ejemplo n.º 1
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
Ejemplo n.º 2
0
def run11(p, jobs):
    start = time.process_time()
    eti_penalty3, opt_model = test.test_DP(jobs, p.b, p.due_dates,
                                           p.processing_times,
                                           p.earliness_penalties,
                                           p.tardiness_penalties)
    end = time.process_time()
    run_time3 = end - start
    obj = opt_model.solution.get_objective_value()
    f = open('Nes_CPLEX_TIMING_results.txt', 'a')
    f.write(
        str(p.n) + "\t" + str(p.b) + "\t" + str(p.rho) + "\t" +
        str(run_time3) + "\t" + str(obj) + "\n")
    f.close()