From 3b9e5d5f9ec4b7a67c6fc8be048bbec30246c2ca Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 18 Sep 2024 16:53:44 +0800 Subject: [PATCH] [fix bug] 01. scale withdraw benefits; 02. add generation flow upper limit of hydropower plant --- prepshot/_model/cost.py | 6 ++++-- prepshot/_model/generation.py | 3 ++- prepshot/_model/hydro.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/prepshot/_model/cost.py b/prepshot/_model/cost.py index bea3871..585c93a 100644 --- a/prepshot/_model/cost.py +++ b/prepshot/_model/cost.py @@ -279,13 +279,15 @@ def income_rule(self) -> poi.ExprBuilder: model = self.model if model.params['isinflow']: coef = 3600 * model.params['dt'] * model.params['price'] + vf = model.params['var_factor'] + w = model.params['weight'] income = sum( - model.withdraw[s, h, m, y] * coef + model.withdraw[s, h, m, y] * coef * vf[y] for s in model.station for h in model.hour for m in model.month for y in model.year - ) + ) / w return income return poi.ExprBuilder(0) diff --git a/prepshot/_model/generation.py b/prepshot/_model/generation.py index d4425ae..097c724 100644 --- a/prepshot/_model/generation.py +++ b/prepshot/_model/generation.py @@ -134,7 +134,8 @@ def gen_up_bound_rule( The constraint of the model. """ model = self.model - lhs = model.gen[h, m, y, z, te] - model.cap_existing[y, z, te] + lhs = model.gen[h, m, y, z, te] \ + - model.cap_existing[y, z, te] * model.params['dt'] return model.add_linear_constraint(lhs, poi.Leq, 0) diff --git a/prepshot/_model/hydro.py b/prepshot/_model/hydro.py index 9db2bd7..ff86ed9 100644 --- a/prepshot/_model/hydro.py +++ b/prepshot/_model/hydro.py @@ -147,6 +147,10 @@ def __init__(self, model : object) -> None: model.station, model.hour, model.month, model.year, rule=self.outflow_up_bound_rule ) + model.genflow_up_bound_cons = poi.make_tupledict( + model.station, model.hour, model.month, model.year, + rule=self.genflow_up_bound_rule + ) model.storage_low_bound_cons = poi.make_tupledict( model.station, model.hour, model.month, model.year, rule=self.storage_low_bound_rule @@ -373,6 +377,33 @@ def outflow_up_bound_rule( lhs = model.outflow[s, h, m, y] - max_outflow return model.add_linear_constraint(lhs, poi.Leq, 0) + def genflow_up_bound_rule( + self, s : str, h : int, m : int, y : int + ) -> poi.ConstraintIndex: + """Upper bound of generation flow. + + Parameters + ---------- + s : str + hydropower plant. + h : int + Hour. + m : int + Month. + y : int + Year. + + Returns + ------- + poi.ConstraintIndex + The constraint of the model. + """ + model = self.model + rc = model.params['reservoir_characteristics'] + max_genflow = rc['GQ_max', s] + lhs = model.genflow[s, h, m, y] - max_genflow + return model.add_linear_constraint(lhs, poi.Leq, 0) + def storage_low_bound_rule( self, s : str, h : int, m : int, y : int ) -> poi.ConstraintIndex: