Adding curtailment costs

138 views
Skip to first unread message

Frank Meissner

unread,
Jan 20, 2024, 8:24:54 AM1/20/24
to pypsa
Hi, I try to add curtailment costs to the objective but get the error: 
"ValueError: Constant values in objective function not supported."

This is my code:

pot_generation = n.generators_t["p_max_pu"].loc[:,n_obj_generators_wind] * n.generators["p_nom"].loc[n_obj_generators_wind]

act_generation = n.model["Generator-p"].loc[:,n_obj_generators_wind]

curtailment= -(- act_generation + pot_generation)

sum_curtailemnt =curtailment.sum()

n.model.objective + sum_curtailemnt

With pot_generation --> 

Generator wind-2-SouthWest wind-3-Central wind-4-North \ snapshot 2019-01-01 00:00:00 0.840 0.126000 0.039667 2019-01-01 01:00:00 0.970 0.123333 0.045667

act_generation -->
Variable (snapshot: 25, Generator: 5) ------------------------------------- [2019-01-01 00:00:00, wind-2-SouthWest]: Generator-p[2019-01-01 00:00:00, wind-2-SouthWest] ∈ [-inf, inf] [2019-01-01 00:00:00, wind-3-Central]: Generator-p[2019-01-01 00:00:00, wind-3-Central] ∈ [-inf, inf] [2019-01-01 00:00:00, wind-4-North]: Generator-p[2019-01-01 00:00:00, wind-4-North] ∈ [-inf, inf]

curtailment --> 
LinearExpression (snapshot: 25, Generator: 5): ---------------------------------------------- [2019-01-01 00:00:00, wind-2-SouthWest]: +1 Generator-p[2019-01-01 00:00:00, wind-2-SouthWest] - 0.84 [2019-01-01 00:00:00, wind-3-Central]: +1 Generator-p[2019-01-01 00:00:00, wind-3-Central] - 0.126 [2019-01-01 00:00:00, wind-4-North]: +1 Generator-p[2019-01-01 00:00:00, wind-4-North] - 0.03967

sum_curtailemnt -->
LinearExpression ---------------- +1 Generator-p[2019-01-01 00:00:00, wind-2-SouthWest] + 1 Generator-p[2019-01-01 00:00:00, wind-3-Central] + 1 Generator-p[2019-01-01 00:00:00, wind-4-North] - 2958 ..

Does anyone has an idea which mistake I have?

Thanks, Frank

Frank Meissner

unread,
Jan 21, 2024, 7:54:46 AM1/21/24
to pypsa
I have found the solution:  It is not possible to add a constant - in this case the capacitance P_nom (multiplied by P_max_pu) to the objective. 
Therefore, a new variable curtailment c (for wind and pv) is inserted.

The following then applies:

c >= P_max_pu * P_nom + p_generation

And the objective is supplemented by: xyz EUR x c
Maybe it will help someone.
Frank

Fabian Neumann

unread,
Jan 21, 2024, 9:57:03 AM1/21/24
to pypsa
Hi Frank,

Great that you have found a solution that works for you!

Just note that any constant in the objective function will not change the optimal solution, so likely you could have just omitted the constant term in your custom expressions for the objective function.

Best wishes,

Fabian N
Reply all
Reply to author
Forward
0 new messages