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 2 commits
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
30 changes: 11 additions & 19 deletions egret/model_library/unit_commitment/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from egret.model_library.transmission import tx_utils
from egret.common.log import logger

from .uc_utils import add_model_attr, uc_time_helper, SlackType
from .uc_utils import add_model_attr, uc_time_helper, SlackType, make_penalty_rule, make_indexed_penalty_rule

component_name = 'data_loader'

Expand Down Expand Up @@ -194,28 +194,26 @@ def load_params(model, model_data, slack_type):
# penalty costs for constraint violation #
##########################################

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment: these are sufficiently important constants that I think they warrant a big comment block in the corresponding files, defining the values and the hierarchy/presence.

ModeratelyBigPenalty = 1e3*system['baseMVA']
BigPenalty = 1e6*system['baseMVA']

model.ReserveShortfallPenalty = Param(within=NonNegativeReals, default=ModeratelyBigPenalty, mutable=True, initialize=system.get('reserve_shortfall_cost', ModeratelyBigPenalty))
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.))

BigPenalty = 1e4*system['baseMVA']

model.LoadMismatchPenalty = Param(within=NonNegativeReals, mutable=True, initialize=system.get('load_mismatch_cost', BigPenalty))
model.LoadMismatchPenaltyReactive = Param(within=NonNegativeReals, mutable=True, initialize=system.get('q_load_mismatch_cost', BigPenalty/2.))
model.ReserveShortfallPenalty = Param(within=NonNegativeReals, mutable=True, rule=make_penalty_rule(model, 'reserve_shortfall_cost', 10.))

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

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

model.SystemTransmissionLimitPenalty = Param(within=NonNegativeReals,
initialize=system.get('transmission_flow_violation_cost', BigPenalty/2.),
rule=make_penalty_rule(model, 'transmission_flow_violation_cost', 2.),
mutable=True)

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

##############################################
Expand Down Expand Up @@ -258,7 +256,6 @@ def _warn_neg_impedence(m, v, l):
model.HVDCLineOutOfService = Param(model.HVDCLines, model.TimePeriods, within=Boolean, default=False,
initialize=TimeMapper(dc_branch_attrs.get('planned_outage', dict())))

_branch_penalties = {}
_branches_with_slack = []
for bn, branch in branches.items():
if 'violation_penalty' in branch:
Expand All @@ -269,7 +266,6 @@ def _warn_neg_impedence(m, v, l):
if slack_type == SlackType.NONE:
logger.warning("Ignoring slacks on individual transmission constraints because SlackType.NONE was specified")
break
_branch_penalties[bn] = val
_branches_with_slack.append(bn)
if val <= 0:
logger.warning("Branch {} has a non-positive penalty {}, this will cause its limits to be ignored!".format(bn,val))
Expand All @@ -280,9 +276,8 @@ def _warn_neg_impedence(m, v, l):

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

## Interfaces
model.Interfaces = Set(initialize=interface_attrs['names'])
Expand Down Expand Up @@ -311,13 +306,11 @@ def get_interface_line_pairs(m):

model.InterfaceLineOrientation = Param(model.InterfaceLinePairs, initialize=_interface_line_orientation_dict, within=set([-1,0,1]))

_interface_penalties = {}
_interfaces_with_slack = []
for i_n, interface in interfaces.items():
if 'violation_penalty' in interface:
val = interface['violation_penalty']
if val is not None:
_interface_penalties[i_n] = val
_interfaces_with_slack.append(i_n)
if val <= 0:
logger.warning("Interface {} has a non-positive penalty {}, this will cause its limits to be ignored!".format(i_n,val))
Expand All @@ -328,9 +321,8 @@ def get_interface_line_pairs(m):

model.InterfaceLimitPenalty = Param(model.InterfacesWithSlack,
within=NonNegativeReals,
default=value(model.SystemInterfaceLimitPenalty),
mutable=True,
initialize=_interface_penalties)
rule=make_indexed_penalty_rule(model, 'interface', model.SystemInterfaceLimitPenalty))

##########################################################
# string indentifiers for the set of thermal generators. #
Expand Down
17 changes: 6 additions & 11 deletions egret/model_library/unit_commitment/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pyomo.environ import *
import math

from .uc_utils import add_model_attr, uc_time_helper
from .uc_utils import add_model_attr, uc_time_helper, make_penalty_rule
from .status_vars import _is_relaxed

@add_model_attr('storage_service', requires = {'data_loader': None,
Expand Down Expand Up @@ -272,30 +272,25 @@ def _check_for_requirement( requirement ):
raise Exception('Exception adding ancillary_services! ancillary_services requires one of: garver_3bin_vars, garver_2bin_vars, garver_3bin_relaxed_stop_vars, ALS_state_transition_vars, to be used for the status_vars.')

## set some penalties by default based on the other model penalties
default_reg_pen = value(model.LoadMismatchPenalty+model.ReserveShortfallPenalty)/2.
## set these penalties in relation to each other, from higher quality service to lower
model.RegulationPenalty = Param(within=NonNegativeReals,
initialize=system.get('regulation_penalty_price', default_reg_pen),
rule=make_penalty_rule(model, 'regulation_penalty_price', 4.),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

General comment: these are sufficiently important constants that I think they warrant a big comment block in the corresponding files, defining the values and the hierarchy/presence.

mutable=True)

default_spin_pen = value(model.RegulationPenalty+model.ReserveShortfallPenalty)/2.
model.SpinningReservePenalty = Param(within=NonNegativeReals,
initialize=system.get('spinning_reserve_penalty_price', default_spin_pen),
rule=make_penalty_rule(model, 'spinning_reserve_penalty_price', 5.),
mutable=True)

default_nspin_pen = value(model.SpinningReservePenalty+model.ReserveShortfallPenalty)/2.
model.NonSpinningReservePenalty = Param(within=NonNegativeReals,
initialize=system.get('non_spinning_reserve_penalty_price', default_nspin_pen),
rule=make_penalty_rule(model, 'non_spinning_reserve_penalty_price', (20/3.)), #6.667
mutable=True)

default_supp_pen = value(model.NonSpinningReservePenalty+model.ReserveShortfallPenalty)/2.
model.SupplementalReservePenalty = Param(within=NonNegativeReals,
initialize=system.get('supplemental_reserve_penalty_price', default_supp_pen),
rule=make_penalty_rule(model, 'supplemental_reserve_penalty_price', 8.),
mutable=True)

default_flex_pen = value(model.NonSpinningReservePenalty+model.SpinningReservePenalty)/2.
model.FlexRampPenalty = Param(within=NonNegativeReals,
initialize=system.get('flexible_ramp_penalty_price', default_flex_pen),
rule=make_penalty_rule(model, 'flexible_ramp_penalty_price', (100/11.)), #9.09
mutable=True)

thermal_gen_attrs = md.attributes(element_type='generator', generator_type='thermal')
Expand Down
28 changes: 27 additions & 1 deletion egret/model_library/unit_commitment/uc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
## some useful functions and function decorators for building these dynamic models
from enum import Enum
from functools import wraps
from pyomo.environ import Var, quicksum
from pyomo.environ import Param, Var, quicksum
from pyomo.core.expr.numeric_expr import LinearExpression

import warnings

import logging
logger = logging.getLogger('egret.model_library.unit_commitment.uc_utils')

from egret.model_library.transmission.tx_utils import scale_ModelData_to_pu, unscale_ModelData_to_pu

class SlackType(Enum):
'''
BUS_BALANCE: Slacks at every bus balance constraint
Expand Down Expand Up @@ -124,3 +126,27 @@ def get_linear_expr(*args):
if not is_var(arg):
return linear_summation
return _linear_expression

def make_penalty_rule(m, 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 penalty_rule(m, idx):
return m.model_data.data['elements'][element_key][idx].get('violation_penalty', base_penalty._rule(m, None))
return penalty_rule

def _reconstruct_pyomo_component(component):
component.clear()
component._constructed = False
component.construct()

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'):
_reconstruct_pyomo_component(param)
unscale_ModelData_to_pu(m.model_data, inplace=True)