Skip to content

Commit a58a58d

Browse files
committed
.
1 parent 2164081 commit a58a58d

6 files changed

Lines changed: 34 additions & 30 deletions
532 Bytes
Binary file not shown.
-293 Bytes
Binary file not shown.
8.03 KB
Binary file not shown.
-165 Bytes
Binary file not shown.
-165 Bytes
Binary file not shown.

scripts/run_milp_BnC_s4.2.6.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
for sta in [10, 20, 30, 50]:
2525
try:
2626
instance = f'{oil} x {sta}'
27-
print(f'\n\n====================================== Solving {instance} ====================================')
27+
print(f'\n\n Solving {instance} ====================================')
2828
with open(f"../data/large scale processed dataset/preprocessed_data_o{oil}_s{sta}.pkl", "rb") as f:
2929
d = pickle.load(f)
3030

@@ -39,9 +39,6 @@
3939
M, gamma = cfg["general"]["M"], cfg["general"]["gamma"]
4040
nQ, nS, nH, nUN = cfg["general"]["nQ"], cfg["general"]["nS"], cfg["general"]["nH"], cfg["general"]["nUN"]
4141
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-
4542
Q_vr = {(v, r): cfg["assets"]["Q_vr"][v][r] for v in cfg["assets"]["Q_vr"] for r in
4643
cfg["assets"]["Q_vr"][v]}
4744
L_p_or = {(o, r): cfg["L_p_or_values"]["c_i"] for o in OilSpills for r in ["c", "i"]}
@@ -52,39 +49,46 @@
5249
spill_df = preprocess_utils.create_spill_dataframe(coordinates_spill, v_o, Sensitivity_R)
5350
station_df = preprocess_utils.create_station_dataframe(coordinates_st)
5451
DistanceMax = 10
52+
# NumberStMax = 5 if sta in [10, 20] else 10
5553
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
5758
#%% ------------------------------------- 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)
6972
#%% ------------------------------------- Branch and Cut -------------------------------------
7073
# 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)
8084

8185
results.append({
8286
"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)
8892
})
8993

9094
except KeyError as e:

0 commit comments

Comments
 (0)