问题: 我正在研究一个线性编程问题,使用Python中的pulp来模拟多个发电机的发电约束。我需要确保解决方案满足以下标准:
代码:
def add_constraints(prob, generators, power_vars, demand):
abs_diff_vars = {}
for gen in generators:
name = gen["name"]
for t in range(1, len(demand)):
abs_diff_vars[(name, t)] = pulp.LpVariable(f"abs_diff_{name}_{t}", lowBound=0)
# Demand Satisfaction Constraints
for t in range(len(demand)):
prob += pulp.lpSum([power_vars[(gen["name"], t)] for gen in generators]) >= demand[t], f"Demand_Satisfaction_{t}"
# Ramp-Up and Ramp-Down Constraints
for t in range(1, len(demand)):
for gen in generators:
name = gen["name"]
rampup = gen["rampup"]
rampdown = gen["rampdown"]
# Ramp-up constraint
prob += power_vars[(name, t)] - power_vars[(name, t-1)] <= rampup, f"Ramp_Up_Constraint_{name}_{t}"
# Ramp-down constraint
prob += power_vars[(name, t-1)] - power_vars[(name, t)] <= rampdown, f"Ramp_Down_Constraint_{name}_{t}"
# Absolute Difference Constraints
prob += abs_diff_vars[(name, t)] >= (power_vars[(name, t)] - power_vars[(name, t-1)]), f"Abs_Diff_Upper_{name}_{t}"
prob += abs_diff_vars[(name, t)] >= (power_vars[(name, t-1)] - power_vars[(name, t)]), f"Abs_Diff_Lower_{name}_{t}"
# Capacity Constraints
for t in range(len(demand)):
for gen in generators:
name = gen["name"]
max_power = gen["max"][t]
min_power = gen["tech_min"][t]
# Max Power Constraint
prob += power_vars[(name, t)] <= max_power, f"Max_Power_{name}_{t}"
# Min Power Constraint
prob += power_vars[(name, t)] >= min_power, f"Min_Power_{name}_{t}"
Inputs:
Demand -
[
17116.3, 16940.71, 16948.98, 16839.5, 16808.51, 16800.25,
16782.69, 16768.23, 16762.03, 16559.6, 16566.83, 16583.35,
16357.16, 16340.63, 16342.7, 16121.67, 16250.77, 16479.03,
16721.75, 17053.29, 17425.12, 17859.95, 18199.75, 18375.34,
18425.95, 18440.4, 18453.83, 18461.06, 18764.72, 18746.13,
18648.01, 18786.41, 18678.99, 18636.65, 18827.72, 18818.43,
19127.25, 19337.95, 19317.29, 19294.57, 19243.96, 19224.33,
19229.5, 19254.29, 19225.37, 19146.87, 19002.27, 18857.67,
18675.89, 18712.04, 18732.7, 18582.94, 18465.19, 18114.03,
18125.39, 18194.59, 18249.33, 18276.18, 18274.12, 18015.91,
18042.76, 18089.24, 18456.93, 18492.05, 18510.64, 18197.69,
18192.52, 18191.49, 18193.56, 18255.53, 18317.5, 18548.85,
18781.24, 19061.14, 19222.27, 19378.23, 19523.86, 19711.84,
19824.42, 19614.75, 19239.83, 18839.08, 18714.11, 18619.09,
18526.13, 18373.27, 18215.24, 18119.19, 18089.24, 18076.84,
18007.64, 17849.62, 17693.66, 17604.83, 17572.82, 17579.01]
Generator -
[
{
"cn_unit_source": "INTER",
"cn_dispatch_type": "MERIT",
"variable_charges": 1.6921,
"rampup": 40.0,
"rampdown": 40.0,
"tech_min": [0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,],
"name": "KSTPS7_22799688",
"max": [0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0,
0.0,0.0,0.0,0.0,0.0,0.0]
}, ]
这些限制似乎得到了很好的落实。但是,在您提供的数据中$max=min=0$,因此发电量自然 = 0,需求将无法得到满足。