|
24 | 24 | for sta in [10, 20, 30, 50]: |
25 | 25 | try: |
26 | 26 | instance = f'{oil} x {sta}' |
27 | | - print(f'\n\n====================================== Solving {instance} ====================================') |
| 27 | + print(f'\n\n Solving {instance} ====================================') |
28 | 28 | with open(f"../data/large scale processed dataset/preprocessed_data_o{oil}_s{sta}.pkl", "rb") as f: |
29 | 29 | d = pickle.load(f) |
30 | 30 |
|
|
39 | 39 | M, gamma = cfg["general"]["M"], cfg["general"]["gamma"] |
40 | 40 | nQ, nS, nH, nUN = cfg["general"]["nQ"], cfg["general"]["nS"], cfg["general"]["nH"], cfg["general"]["nUN"] |
41 | 41 | Vehicles, c_v, C_r = cfg["assets"]["vehicles"], cfg["assets"]["c_v"], cfg["assets"]["C_r"] |
42 | | - W = [3.1, 2.5, 0.25, 0.0025, 0.025, 250, 0.25, 0.25] |
43 | | - # W = cfg["general"]["weights"] |
44 | | - |
45 | 42 | Q_vr = {(v, r): cfg["assets"]["Q_vr"][v][r] for v in cfg["assets"]["Q_vr"] for r in |
46 | 43 | cfg["assets"]["Q_vr"][v]} |
47 | 44 | L_p_or = {(o, r): cfg["L_p_or_values"]["c_i"] for o in OilSpills for r in ["c", "i"]} |
|
52 | 49 | spill_df = preprocess_utils.create_spill_dataframe(coordinates_spill, v_o, Sensitivity_R) |
53 | 50 | station_df = preprocess_utils.create_station_dataframe(coordinates_st) |
54 | 51 | DistanceMax = 10 |
| 52 | + # NumberStMax = 5 if sta in [10, 20] else 10 |
55 | 53 | NumberStMax = 5 if sta in [10, 20] else 10 |
56 | | - |
| 54 | + if sta == 10: NumberStMax = 4 |
| 55 | + elif sta == 20: NumberStMax = 7 |
| 56 | + elif sta == 30: NumberStMax = 10 |
| 57 | + elif sta == 50: NumberStMax = 15 |
57 | 58 | #%% ------------------------------------- MILP ------------------------------------- |
58 | | - print('Running MILP') |
59 | | - start_time_milp = time.time() |
60 | | - model_1, x_s, y_os, z_sor, h_sov = build_model(Stations, OilSpills, Resources, Vehicles, W, |
61 | | - v_o_n, eta_o, t_os_n, gamma, M, demand_or, demand_ov, L_p_or, |
62 | | - NumberStMax, A_sr, nH, nUN, nQ, Q_vr, n_vs, |
63 | | - F_s, C_r, Eff_sor, pn_sor, c_v, Distance, DistanceMax, 'model_p') |
64 | | - |
65 | | - model_objectives, coverage_percentage, resource_stockpile_r, x_s1, y_os1, z_sor_lamoscad, h_sov_lamoscad, solution_values, \ |
66 | | - num_var_constr = solve_model(model_1, x_s, y_os, z_sor, h_sov, OilSpills) |
67 | | - runtime_milp = round(time.time() - start_time_milp, 2) |
68 | | - print('model_objectives', model_objectives[0]) |
| 59 | + # print('Running MILP') |
| 60 | + # W = [3.1, 2.5, 0.25, 0.0025, 0.025, 25, 0.5, 0.25] |
| 61 | + # start_time_milp = time.time() |
| 62 | + # model_1, x_s, y_os, z_sor, h_sov = build_model(Stations, OilSpills, Resources, Vehicles, W, |
| 63 | + # v_o_n, eta_o, t_os_n, gamma, M, demand_or, demand_ov, L_p_or, |
| 64 | + # NumberStMax, A_sr, nH, nUN, nQ, Q_vr, n_vs, |
| 65 | + # F_s, C_r, Eff_sor, pn_sor, c_v, Distance, DistanceMax, 'model_p') |
| 66 | + # |
| 67 | + # model_objectives, coverage_percentage, resource_stockpile_r, x_s1, y_os1, z_sor_lamoscad, h_sov_lamoscad, solution_values, \ |
| 68 | + # num_var_constr = solve_model(model_1, x_s, y_os, z_sor, h_sov, OilSpills) |
| 69 | + # runtime_milp = round(time.time() - start_time_milp, 2) |
| 70 | + # print('num_var_constr', num_var_constr) |
| 71 | + # print('runtime_milp', runtime_milp) |
69 | 72 | #%% ------------------------------------- Branch and Cut ------------------------------------- |
70 | 73 | # print('Running BnC') |
71 | | - # start_time_BnC = time.time() |
72 | | - # best_sol, LB_final, UB_final, obj1_from_rmp = branch_and_cut.branch_and_cut_loop(OilSpills, Stations, Resources, Vehicles, |
73 | | - # A_sr, C_r, Eff_sor, Distance, F_s, v_o_n, eta_o, t_os_n, pn_sor, |
74 | | - # demand_or, demand_ov, nQ, Q_vr, n_vs, L_p_or, M, gamma, W, NumberStMax, |
75 | | - # max_iters=1, tolerance=0.01, stable_iterations=3) |
76 | | - # runtime_BnC = time.time() - start_time_BnC |
77 | | - # print("Facilities opened:", [s for s in best_sol["x"] if best_sol["x"][s] > 0.5]) |
78 | | - # print("Final LB:", LB_final) |
79 | | - # print("Final UB:", UB_final) |
| 74 | + W = [3.1, 2.5, 0.25, 0.0025, 0.025, 25, 0.025, 0.25] |
| 75 | + start_time_BnC = time.time() |
| 76 | + best_sol, LB_final, UB_final, obj1_from_rmp = branch_and_cut.branch_and_cut_loop(OilSpills, Stations, Resources, Vehicles, |
| 77 | + A_sr, C_r, Eff_sor, Distance, F_s, v_o_n, eta_o, t_os_n, pn_sor, |
| 78 | + demand_or, demand_ov, nQ, Q_vr, n_vs, L_p_or, M, gamma, W, NumberStMax, |
| 79 | + max_iters=1, tolerance=0.01, stable_iterations=3) |
| 80 | + runtime_BnC = time.time() - start_time_BnC |
| 81 | + print("Facilities opened:", [s for s in best_sol["x"] if best_sol["x"][s] > 0.5]) |
| 82 | + print("Final LB:", LB_final) |
| 83 | + print("Final UB:", UB_final) |
80 | 84 |
|
81 | 85 | results.append({ |
82 | 86 | "instance": instance, |
83 | | - "num_var_constr": num_var_constr, |
84 | | - "model_objectives[0]": model_objectives[0], |
85 | | - "runtime_milp": runtime_milp, |
86 | | - # "milp_obj1_from_mp": round(obj1_from_rmp, 2), |
87 | | - # "runtime_BnC": round(runtime_BnC, 2) |
| 87 | + # "num_var_constr": num_var_constr, |
| 88 | + # "model_objectives[0]": model_objectives[0], |
| 89 | + # "runtime_milp": runtime_milp, |
| 90 | + "milp_obj1_from_mp": round(obj1_from_rmp, 2), |
| 91 | + "runtime_BnC": round(runtime_BnC, 2) |
88 | 92 | }) |
89 | 93 |
|
90 | 94 | except KeyError as e: |
|
0 commit comments