Add MIP module for collector layout optimization
This commit is contained in:
49
main.py
49
main.py
@@ -15,6 +15,11 @@ from sklearn.cluster import KMeans
|
||||
from esau_williams import design_with_esau_williams
|
||||
from ga import design_with_ga
|
||||
|
||||
try:
|
||||
from mip import design_with_mip
|
||||
except ImportError:
|
||||
design_with_mip = None
|
||||
|
||||
# 设置matplotlib支持中文显示
|
||||
plt.rcParams["font.sans-serif"] = ["Microsoft YaHei", "SimHei", "Arial"]
|
||||
plt.rcParams["axes.unicode_minus"] = False
|
||||
@@ -1399,6 +1404,7 @@ def compare_design_methods(
|
||||
interactive=True,
|
||||
plot_results=True,
|
||||
use_ga=False,
|
||||
use_mip=False,
|
||||
):
|
||||
"""
|
||||
比较MST和三种电缆方案下的K-means设计方法
|
||||
@@ -1709,6 +1715,49 @@ def compare_design_methods(
|
||||
f" [GA] Cost: ¥{eval_ga['total_cost']:,.2f} | Loss: {eval_ga['total_loss']:.2f} kW | Circuits: {n_circuits_ga}"
|
||||
)
|
||||
|
||||
if use_mip and design_with_mip:
|
||||
# --- Run 5: Mixed Integer Programming ---
|
||||
mip_name = f"{name} (MIP)"
|
||||
conns_mip, turbines_mip = design_with_mip(
|
||||
turbines.copy(),
|
||||
substation,
|
||||
current_specs,
|
||||
voltage,
|
||||
power_factor,
|
||||
system_params,
|
||||
evaluate_func=evaluate_design,
|
||||
total_invest_func=total_investment,
|
||||
get_max_capacity_func=get_max_cable_capacity_mw,
|
||||
)
|
||||
eval_mip = evaluate_design(
|
||||
turbines,
|
||||
conns_mip,
|
||||
substation,
|
||||
cable_specs=current_specs,
|
||||
is_offshore=is_offshore,
|
||||
method_name=mip_name,
|
||||
voltage=voltage,
|
||||
power_factor=power_factor,
|
||||
)
|
||||
n_circuits_mip = sum(
|
||||
1
|
||||
for d in eval_mip["details"]
|
||||
if d["source"] == "substation" or d["target"] == "substation"
|
||||
)
|
||||
comparison_results.append(
|
||||
{
|
||||
"name": mip_name,
|
||||
"cost": eval_mip["total_cost"],
|
||||
"loss": eval_mip["total_loss"],
|
||||
"eval": eval_mip,
|
||||
"turbines": turbines_mip,
|
||||
"specs": current_specs,
|
||||
}
|
||||
)
|
||||
print(
|
||||
f" [MIP] Cost: ¥{eval_mip['total_cost']:,.2f} | Loss: {eval_mip['total_loss']:.2f} kW | Circuits: {n_circuits_mip}"
|
||||
)
|
||||
|
||||
# 记录最佳
|
||||
if eval_rot["total_cost"] < best_cost:
|
||||
best_cost = eval_rot["total_cost"]
|
||||
|
||||
Reference in New Issue
Block a user