I am having similar issues with rolling horizon optimization and correctly implementing custom constraints
def define_cons_max_curtailment(model,network, generator_name):
"""
Define the constraint for the maximum curtailment rate of a specified generator.
Args:
network (Network): The network object containing generators and other components.
generator_name (str): The name of the generator for which the constraint is to be defined.
The function adds a constraint to the network model that limits the maximum curtailment rate
for the specified generator. The curtailment rate is taken from the 'curtailment_rate_max' column
in the network's generator DataFrame.
"""
m = model
c_rate_max = network.generators.loc[generator_name, "curtailment_rate_max"]
m.add_constraints(
m.variables["Generator-p"].sel(Generator=generator_name).sum()
>= (
(1 - c_rate_max)
* network.generators_t.p_max_pu[generator_name].sum()
* m.variables["Generator-p_nom"][generator_name].to_linexpr()
),
name=f"{generator_name}_max_curtailment",
)
return(m)
# Add Custom Constraints
def custom_constraints(network,generator_name):
m = network.optimize.create_model()
m = define_cons_max_curtailment(m, network, generator_name)
network.optimize.optimize_with_rolling_horizon(snapshots=network.snapshots, horizon=100, overlap=0, extra_functionality=custom_constraints(network, generator_name="pv_generator"), solver_name='highs')
The simulation runs but does not apply my custom constraint "define_cons_max_curtailment"