Skip to content

Commit

Permalink
Merge pull request #1 from michaelbynum/relaxations2
Browse files Browse the repository at this point in the history
FBBT should be optional
  • Loading branch information
dilr authored May 11, 2021
2 parents 0f0b642 + 2333911 commit 49c2b44
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
52 changes: 41 additions & 11 deletions egret/models/ac_relaxations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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'])
Expand All @@ -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'])
Expand All @@ -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
16 changes: 5 additions & 11 deletions egret/models/acopf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 49c2b44

Please sign in to comment.