Skip to content

Commit

Permalink
Merge local repo into github.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dillard Robertson committed May 5, 2021
2 parents 4b9976b + aa9c565 commit 0f0b642
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion egret/models/ac_relaxations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def _relaxation_helper(model, md, include_soc, use_linear_relaxation):
coramin.relaxations.relax(model,
in_place=True,
use_fbbt=True,
use_fbbt=False,
fbbt_options={'deactivate_satisfied_constraints': True,
'max_iter': 2})
if not use_linear_relaxation:
Expand Down
65 changes: 60 additions & 5 deletions egret/models/acopf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import egret.model_library.transmission.gen as libgen
from egret.model_library.defn import FlowType, CoordinateType
from egret.data.data_utils import map_items, zip_items
from math import pi, radians, degrees
from math import pi, radians, degrees, cos, sin
from collections import OrderedDict
from egret.data.networkx_utils import get_networkx_graph
import networkx
Expand Down Expand Up @@ -93,7 +93,12 @@ 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)

libbus.declare_var_pl(model, bus_attrs['names'], initialize=bus_p_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_ql(model, bus_attrs['names'], initialize=bus_q_loads)
model.pl.fix()
model.ql.fix()
Expand All @@ -106,8 +111,53 @@ def _create_base_power_ac_model(model_data, include_feasibility_slack=False):
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()}))
libbranch.declare_var_c(model=model, index_set=unique_bus_pairs, initialize=1)
libbranch.declare_var_s(model=model, index_set=unique_bus_pairs, initialize=0)
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:
the_mid = bdat['angle_diff_min']
else:
the_mid = 0
lb = (bus_attrs['v_min'][from_bus]
* bus_attrs['v_min'][to_bus]
* cos(max(abs(bdat['angle_diff_min']),
abs(bdat['angle_diff_max']))*pi/180))
ub = (bus_attrs['v_max'][from_bus]
* bus_attrs['v_max'][to_bus]
* cos(the_mid*pi/180))
return lb, ub
libbranch.declare_var_c(model=model,
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]
* bus_attrs['v_min'][to_bus]
* sin(bdat['angle_diff_min']*pi/180))
else:
lb = (bus_attrs['v_max'][from_bus]
* bus_attrs['v_max'][to_bus]
* sin(bdat['angle_diff_min']*pi/180))
if bdat['angle_diff_max'] >= 0:
ub = (bus_attrs['v_max'][from_bus]
* bus_attrs['v_max'][to_bus]
* sin(bdat['angle_diff_max']*pi/180))
else:
ub = (bus_attrs['v_min'][from_bus]
* bus_attrs['v_min'][to_bus]
* sin(bdat['angle_diff_max']*pi/180))
return lb, ub
libbranch.declare_var_s(model=model, index_set=unique_bus_pairs, initialize=0,
bounds=_s_bounds_rule)

### include the feasibility slack for the bus balances
p_rhs_kwargs = {}
Expand Down Expand Up @@ -277,10 +327,15 @@ def create_atan_acopf_model(model_data, include_feasibility_slack=False):
else:
cycle_basis_bus_pairs.add((b2, b1))

branches = dict(md.elements(element_type='branch'))
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
libbranch.declare_var_dva(model=model,
index_set=list(cycle_basis_bus_pairs),
initialize=0,
bounds=(-pi/2, pi/2))
bounds=_dva_bounds_rule)
libbranch.declare_eq_dva_arctan(model=model, index_set=list(cycle_basis_bus_pairs))
libbranch.declare_eq_dva_cycle_sum(model=model, cycle_basis=cycle_basis, valid_bus_pairs=cycle_basis_bus_pairs)
libbranch.declare_ineq_soc(model=model, index_set=list(unique_bus_pairs), use_outer_approximation=False)
Expand Down

0 comments on commit 0f0b642

Please sign in to comment.