Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

one penalty to rule them all #259

Merged
merged 8 commits into from
Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleaning up
  • Loading branch information
bknueven committed Dec 15, 2021
commit f399ffff2d2ec7a652033c64e4a77867844404f3
14 changes: 7 additions & 7 deletions egret/model_library/unit_commitment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,23 +197,23 @@ def load_params(model, model_data, slack_type):
BigPenalty = 1e6*system['baseMVA']

model.LoadMismatchPenalty = Param(within=NonNegativeReals, mutable=True, rule=lambda m : m.model_data.data['system'].get('load_mismatch_cost', BigPenalty))
model.LoadMismatchPenaltyReactive = Param(within=NonNegativeReals, mutable=True, rule=make_penalty_rule(model, 'q_load_mismatch_cost', 2.))
model.LoadMismatchPenaltyReactive = Param(within=NonNegativeReals, mutable=True, rule=make_penalty_rule('q_load_mismatch_cost', 2.))

model.ReserveShortfallPenalty = Param(within=NonNegativeReals, mutable=True, rule=make_penalty_rule(model, 'reserve_shortfall_cost', 10.))
model.ReserveShortfallPenalty = Param(within=NonNegativeReals, mutable=True, rule=make_penalty_rule('reserve_shortfall_cost', 10.))

model.Contingencies = Set(initialize=contingencies.keys())

# leaving this unindexed for now for simpility
model.SystemContingencyLimitPenalty = Param(within=NonNegativeReals,
rule=make_penalty_rule(model, 'contingency_flow_violation_cost', 2.),
rule=make_penalty_rule('contingency_flow_violation_cost', 2.),
mutable=True)

model.SystemTransmissionLimitPenalty = Param(within=NonNegativeReals,
rule=make_penalty_rule(model, 'transmission_flow_violation_cost', 2.),
rule=make_penalty_rule('transmission_flow_violation_cost', 2.),
mutable=True)

model.SystemInterfaceLimitPenalty = Param(within=NonNegativeReals,
rule=make_penalty_rule(model, 'interface_flow_violation_cost', (10/3.)), #3.333
rule=make_penalty_rule('interface_flow_violation_cost', (10/3.)), #3.333
mutable=True)

##############################################
Expand Down Expand Up @@ -276,7 +276,7 @@ def _warn_neg_impedence(m, v, l):

model.BranchLimitPenalty = Param(model.BranchesWithSlack,
within=NonNegativeReals,
rule=make_indexed_penalty_rule(model, 'branch', model.SystemTransmissionLimitPenalty),
rule=make_indexed_penalty_rule('branch', model.SystemTransmissionLimitPenalty),
mutable=True)

## Interfaces
Expand Down Expand Up @@ -322,7 +322,7 @@ def get_interface_line_pairs(m):
model.InterfaceLimitPenalty = Param(model.InterfacesWithSlack,
within=NonNegativeReals,
mutable=True,
rule=make_indexed_penalty_rule(model, 'interface', model.SystemInterfaceLimitPenalty))
rule=make_indexed_penalty_rule('interface', model.SystemInterfaceLimitPenalty))

##########################################################
# string indentifiers for the set of thermal generators. #
Expand Down
10 changes: 5 additions & 5 deletions egret/model_library/unit_commitment/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,23 +274,23 @@ def _check_for_requirement( requirement ):
## set some penalties by default based on the other model penalties
## set these penalties in relation to each other, from higher quality service to lower
model.RegulationPenalty = Param(within=NonNegativeReals,
rule=make_penalty_rule(model, 'regulation_penalty_price', 4.),
rule=make_penalty_rule('regulation_penalty_price', 4.),
mutable=True)

model.SpinningReservePenalty = Param(within=NonNegativeReals,
rule=make_penalty_rule(model, 'spinning_reserve_penalty_price', 5.),
rule=make_penalty_rule('spinning_reserve_penalty_price', 5.),
mutable=True)

model.NonSpinningReservePenalty = Param(within=NonNegativeReals,
rule=make_penalty_rule(model, 'non_spinning_reserve_penalty_price', (20/3.)), #6.667
rule=make_penalty_rule('non_spinning_reserve_penalty_price', (20/3.)), #6.667
mutable=True)

model.SupplementalReservePenalty = Param(within=NonNegativeReals,
rule=make_penalty_rule(model, 'supplemental_reserve_penalty_price', 8.),
rule=make_penalty_rule('supplemental_reserve_penalty_price', 8.),
mutable=True)

model.FlexRampPenalty = Param(within=NonNegativeReals,
rule=make_penalty_rule(model, 'flexible_ramp_penalty_price', (100/11.)), #9.09
rule=make_penalty_rule('flexible_ramp_penalty_price', (100/11.)), #9.09
mutable=True)

thermal_gen_attrs = md.attributes(element_type='generator', generator_type='thermal')
Expand Down
12 changes: 8 additions & 4 deletions egret/model_library/unit_commitment/uc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from functools import wraps
from pyomo.environ import Param, Var, quicksum
from pyomo.core.expr.numeric_expr import LinearExpression
from pyomo.core.base.initializer import ScalarCallInitializer, IndexedCallInitializer

import warnings

Expand Down Expand Up @@ -127,12 +128,15 @@ def get_linear_expr(*args):
return linear_summation
return _linear_expression

def make_penalty_rule(m, penalty_key, divisor):
# Helpers for making penalty factors "commonly" mutable.
# E.g., change LoadMismatchPenalty and the rest adjust
# automatically if not directly specified
def make_penalty_rule(penalty_key, divisor):
def penalty_rule(m):
return m.model_data.data['system'].get(penalty_key, m.LoadMismatchPenalty/divisor)
bknueven marked this conversation as resolved.
Show resolved Hide resolved
return penalty_rule

def make_indexed_penalty_rule(m, element_key, base_penalty):
def make_indexed_penalty_rule(element_key, base_penalty):
def penalty_rule(m, idx):
return m.model_data.data['elements'][element_key][idx].get('violation_penalty', base_penalty._rule(m, None))
return penalty_rule
Expand All @@ -146,7 +150,7 @@ def reset_unit_commitment_penalties(m):
scale_ModelData_to_pu(m.model_data, inplace=True)
_reconstruct_pyomo_component(m.LoadMismatchPenalty)
for param in m.component_objects(Param):
if param.mutable and param._rule and \
hasattr(param._rule, '_fcn') and (param._rule._fcn.__name__ == 'penalty_rule'):
if param.mutable and isinstance(param._rule, (ScalarCallInitializer, IndexedCallInitializer)) \
and (param._rule._fcn.__name__ == 'penalty_rule'):
_reconstruct_pyomo_component(param)
unscale_ModelData_to_pu(m.model_data, inplace=True)