From 2333911e9a06abdf2a32ebb0a81453b4f9bec9af Mon Sep 17 00:00:00 2001 From: Michael Bynum Date: Wed, 5 May 2021 11:12:48 -0600 Subject: [PATCH] acopf variable bounds --- egret/models/ac_relaxations.py | 52 +++++++++++++++++++++++++++------- egret/models/acopf.py | 16 ++++------- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/egret/models/ac_relaxations.py b/egret/models/ac_relaxations.py index 32d65cdf..b288df4e 100644 --- a/egret/models/ac_relaxations.py +++ b/egret/models/ac_relaxations.py @@ -16,10 +16,10 @@ logger = logging.getLogger(__name__) -def _relaxation_helper(model, md, include_soc, use_linear_relaxation): +def _relaxation_helper(model, md, include_soc, use_linear_relaxation, use_fbbt=True): coramin.relaxations.relax(model, in_place=True, - use_fbbt=False, + use_fbbt=use_fbbt, fbbt_options={'deactivate_satisfied_constraints': True, 'max_iter': 2}) if not use_linear_relaxation: @@ -214,10 +214,17 @@ def use_linear_relaxation(self, val): self._use_linear_relaxation = True -def create_soc_relaxation(model_data, use_linear_relaxation=True, include_feasibility_slack=False): +def create_soc_relaxation(model_data, + use_linear_relaxation=True, + include_feasibility_slack=False, + use_fbbt=True): model, md = _create_base_power_ac_model(model_data, include_feasibility_slack=include_feasibility_slack) if use_linear_relaxation: - _relaxation_helper(model=model, md=md, include_soc=True, use_linear_relaxation=use_linear_relaxation) + _relaxation_helper(model=model, + md=md, + include_soc=True, + use_linear_relaxation=use_linear_relaxation, + use_fbbt=use_fbbt) else: branch_attrs = md.attributes(element_type='branch') bus_pairs = zip_items(branch_attrs['from_bus'], branch_attrs['to_bus']) @@ -227,15 +234,22 @@ def create_soc_relaxation(model_data, use_linear_relaxation=True, include_feasib return model, md -def create_atan_relaxation(model_data, use_linear_relaxation=True, include_feasibility_slack=False, - use_soc_edge_cuts=False): +def create_atan_relaxation(model_data, + use_linear_relaxation=True, + include_feasibility_slack=False, + use_soc_edge_cuts=False, + use_fbbt=True): model, md = create_atan_acopf_model(model_data=model_data, include_feasibility_slack=include_feasibility_slack) del model.ineq_soc del model._con_ineq_soc if use_soc_edge_cuts: del model.ineq_soc_ub del model._con_ineq_soc_ub - _relaxation_helper(model=model, md=md, include_soc=True, use_linear_relaxation=use_linear_relaxation) + _relaxation_helper(model=model, + md=md, + include_soc=True, + use_linear_relaxation=use_linear_relaxation, + use_fbbt=use_fbbt) if use_soc_edge_cuts: branch_attrs = md.attributes(element_type='branch') bus_pairs = zip_items(branch_attrs['from_bus'], branch_attrs['to_bus']) @@ -250,13 +264,29 @@ def create_atan_relaxation(model_data, use_linear_relaxation=True, include_feasi return model, md -def create_polar_acopf_relaxation(model_data, include_soc=True, use_linear_relaxation=True, include_feasibility_slack=False): +def create_polar_acopf_relaxation(model_data, + include_soc=True, + use_linear_relaxation=True, + include_feasibility_slack=False, + use_fbbt=True): model, md = create_psv_acopf_model(model_data, include_feasibility_slack=include_feasibility_slack) - _relaxation_helper(model=model, md=md, include_soc=include_soc, use_linear_relaxation=use_linear_relaxation) + _relaxation_helper(model=model, + md=md, + include_soc=include_soc, + use_linear_relaxation=use_linear_relaxation, + use_fbbt=use_fbbt) return model, md -def create_rectangular_acopf_relaxation(model_data, include_soc=True, use_linear_relaxation=True, include_feasibility_slack=False): +def create_rectangular_acopf_relaxation(model_data, + include_soc=True, + use_linear_relaxation=True, + include_feasibility_slack=False, + use_fbbt=True): model, md = create_rsv_acopf_model(model_data, include_feasibility_slack=include_feasibility_slack) - _relaxation_helper(model=model, md=md, include_soc=include_soc, use_linear_relaxation=use_linear_relaxation) + _relaxation_helper(model=model, + md=md, + include_soc=include_soc, + use_linear_relaxation=use_linear_relaxation, + use_fbbt=use_fbbt) return model, md diff --git a/egret/models/acopf.py b/egret/models/acopf.py index e111a9e3..51328dc9 100644 --- a/egret/models/acopf.py +++ b/egret/models/acopf.py @@ -93,12 +93,7 @@ def _create_base_power_ac_model(model_data, include_feasibility_slack=False): ### declare (and fix) the loads at the buses bus_p_loads, bus_q_loads = tx_utils.dict_of_bus_loads(buses, loads) - def _pl_bounds_rule(m, bus): - load = bus_p_loads[bus] - if load < 0.0: - return load, 0.0 - return 0.0, load - libbus.declare_var_pl(model, bus_attrs['names'], initialize=bus_p_loads, bounds=_pl_bounds_rule) + libbus.declare_var_pl(model, bus_attrs['names'], initialize=bus_p_loads) libbus.declare_var_ql(model, bus_attrs['names'], initialize=bus_q_loads) model.pl.fix() model.ql.fix() @@ -111,11 +106,11 @@ def _pl_bounds_rule(m, bus): initialize={k: v**2 for k, v in bus_attrs['vm'].items()}, bounds=zip_items({k: v**2 for k, v in bus_attrs['v_min'].items()}, {k: v**2 for k, v in bus_attrs['v_max'].items()})) + branch_w_index = {(v['from_bus'], v['to_bus']): v for v in branches.values()} + def _c_bounds_rule(m, from_bus, to_bus): bdat = branch_w_index[(from_bus, to_bus)] - busf = buses[from_bus] - bust = buses[to_bus] if bdat['angle_diff_max'] < 0: the_mid = bdat['angle_diff_max'] elif bdat['angle_diff_min'] > 0: @@ -134,10 +129,9 @@ def _c_bounds_rule(m, from_bus, to_bus): index_set=unique_bus_pairs, initialize=1, bounds=_c_bounds_rule) + def _s_bounds_rule(m, from_bus, to_bus): bdat = branch_w_index[(from_bus, to_bus)] - busf = buses[from_bus] - bust = buses[to_bus] if bdat['angle_diff_min'] >= 0: lb = (bus_attrs['v_min'][from_bus] @@ -331,7 +325,7 @@ def create_atan_acopf_model(model_data, include_feasibility_slack=False): branch_w_index = {(v['from_bus'], v['to_bus']): v for v in branches.values()} def _dva_bounds_rule(m, from_bus, to_bus): bdat = branch_w_index[(from_bus, to_bus)] - return bdat['angle_diff_min'] * pi / 180, bdat['angle_diff_max'] * pi / 180 + return max(-pi/2, bdat['angle_diff_min'] * pi / 180), min(pi/2, bdat['angle_diff_max'] * pi / 180) libbranch.declare_var_dva(model=model, index_set=list(cycle_basis_bus_pairs), initialize=0,