def add_constraints(prob, generators, power_vars, demand):
# Absolute Difference Variables
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}"
Input for 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
]
Input for generator –
[
{
“cn_unit_source”: “INTRA”,
“cn_dispatch_type”: “MUST”,
“variable_charges”: 0,
“rampup”: 0,
“rampdown”: 0,
“tech_min”: [3204.93,3181.24,3173.94,3189.28,3168,3129.09,3149.76,3116.75,3098.06,3093.31,3057.82,3070.67,3038.04,3043.26,3025.4,2968.14,2962,2972.11,3128.8,3172.06,3213.99,3205.06,3182.21,3168.66,3126.87,3198.76,3239.04,3375.79,3583.01,3770.13,3741.18,3921.2,4029.8,4232.19,4400.67,4600.04,4666.72,4818.1,5013.12,5201.65,5267.81,5396.66,5517.87,5591.76,5601.87,5641.31,5681.82,5725.98,5767.36,5723.67,5751.78,5776.97,5672.74,5681.85,5570.83,5552.37,5426.99,5402.41,5296.31,5255.07,5089.96,4988.26,4791.9,4700.34,4400.67,4235.78,4079.16,3959.17,3801.92,3607.67,3451.74,3302.87,3290,3189.38,3061.46,2987.27,2970.09,2967.8,2977.63,2986.67,2947.17,2946.03,2956.67,2962.26,2963.86,2973.09,2972.52,2974.3,2932.38,2929.72,2952.9,2948.59,2961.63,2960.09,2960.11,2964.6],
“name”: “REMC”,
“max”:[3204.93,3181.24,3173.94,3189.28,3168,3129.09,3149.76,3116.75,3098.06,3093.31,3057.82,3070.67,3038.04,3043.26,3025.4,2968.14,2962,2972.11,3128.8,3172.06,3213.99,3205.06,3182.21,3168.66,3126.87,3198.76,3239.04,3375.79,3583.01,3770.13,3741.18,3921.2,4029.8,4232.19,4400.67,4600.04,4666.72,4818.1,5013.12,5201.65,5267.81,5396.66,5517.87,5591.76,5601.87,5641.31,5681.82,5725.98,5767.36,5723.67,5751.78,5776.97,5672.74,5681.85,5570.83,5552.37,5426.99,5402.41,5296.31,5255.07,5089.96,4988.26,4791.9,4700.34,4400.67,4235.78,4079.16,3959.17,3801.92,3607.67,3451.74,3302.87,3290,3189.38,3061.46,2987.27,2970.09,2967.8,2977.63,2986.67,2947.17,2946.03,2956.67,2962.26,2963.86,2973.09,2972.52,2974.3,2932.38,2929.72,2952.9,2948.59,2961.63,2960.09,2960.11,2964.6]
},
{
“cn_unit_source”: “INTRA”,
“cn_dispatch_type”: “MERIT”,
“variable_charges”: 0,
“rampup”: 0,
“rampdown”: 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
],
“name”: “ANTONY LREPL_1_MSEDCL_22798341”,
“max”: [
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72,
0.72
]
},
{
“cn_unit_source”: “INTRA”,
“cn_dispatch_type”: “MERIT”,
“variable_charges”: 0,
“rampup”: 0,
“rampdown”: 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
],
“name”: “AMNS KL_MSEDCL_22798342”,
“max”: [
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
1.24,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
]
},
{
“cn_unit_source”: “INTRA”,
“cn_dispatch_type”: “MERIT”,
“variable_charges”: 0,
“rampup”: 0,
“rampdown”: 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
],
“name”: “URAN_OPENCYCLE_MSEDCL_22798353”,
“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,
88.0,
88.0,
88.0,
88.0,
88.0,
88.0,
88.0,
88.0,
88.0,
88.0,
88.0,
89.0,
89.0,
89.0,
89.0,
89.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
]
},
{
“cn_unit_source”: “INTER”,
“cn_dispatch_type”: “MERIT”,
“variable_charges”: 0,
“rampup”: 0,
“rampdown”: 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”: “RGPPL-LTRLNG_MSEB_Beneficiary_22799674”,
“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
]
},
{
“cn_unit_source”: “INTER”,
“cn_dispatch_type”: “MERIT”,
“variable_charges”: 0,
“rampup”: 0,
“rampdown”: 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”: “RGPPL-RLNG_MSEB_Beneficiary_22799744”,
“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
]
},
{
“cn_unit_source”: “INTER”,
“cn_dispatch_type”: “MERIT”,
“variable_charges”: 1.4495,
“rampup”: 120.0,
“rampdown”: 120.0,
“tech_min”: [
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72,
140.72
],
“name”: “LARA-I_22799714”,
“max”: [
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87,
255.87
]
}
]
Aim to meet the demand requirements while adhering to the ramp-up and ramp-down constraints
Isha Garg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.