Skip to content

Commit

Permalink
v0.10-rc: iterate only over active connections (#314)
Browse files Browse the repository at this point in the history
* FEATURE: Making the JuMP model sparse

Previously, all matrices and vectors that were used to
create the JuMP model were the maximum size of the whole
network in terms of connections and terminals, e.g. even
if a component only had one connection to the network, if
the whole network was 3 phases, then 3 JuMP variables /
constraints were used in every case.

In this update only JuMP variables and constraints are
created for the actual connections that exist on each component.
This means that there are fewer cases where a problem is
overdefined, and therefore larger cases can solve much faster.

Single and two phase delta connected components are still not
modeled in this sparse manor, and will be addressed in future
updates.

Several tests were found to be unstable, and need to be rewriten
in the future, i.e. these tests would always pass locally, but
fail on travis, which means the cases are probably poorly defined.

This is in preparation for the addition of explicit neutral
conductors.

Also, some dangling function name changes and outstanding bugs were
addressed, and support for older versions of JuMP was removed.

Changes:

- Refactor variables, constraints, objectives to support iterating over arbitrary connections/terminals (breaking)
- Add `ref_add_connections!` that adds lists of connections to ref for each component (breaking)
- Rename constraint and variable functions to better match PowerModels conventions (breaking)
  - variable_mc_gen_power_setpoint -> variable_mc_generator_power
  - variable_mc_gen_power_setpoint_on_off -> variable_mc_generator_power_on_off
  - constraint_mc_gen_setpoint -> constraint_mc_generator_power
  - constraint_mc_slack_power_balance -> constraint_mc_power_balance_slack
  - constraint_mc_shed_power_balance -> constraint_mc_power_balance_shed
  - constraint_mc_load_power_balance -> constraint_mc_power_balance
  - variable_mc_load_setpoint -> variable_mc_load_power
  - constraint_mc_load_setpoint -> constraint_mc_load_power
- Updates objective function for MLD problem (breaking)
- Add `correct_mc_voltage_angle_differences`, `correct_mc_thermal_limits`
- Removed support for JuMP \< v0.21 (breaking)
- Overrides `_objective_min_fuel_cost_polynomial_linquad` from PowerModels to support arbitrary connections on generators
- Updated solution building functions to automatically parse arbitrarily-sized vectors of variables into solutions
- Changed `Array{...,1}` to `Vector{...}` and `Array{...,2}` to `Matrix{...}`
- Removes phase projection by default, but keeps phase projection for delta connected components for now (breaking)
- Adds `apply_phase_projection_delta!` to project phases of delta connected components
- Fixes grounding logic for generator and solar objects
- Fixes bug in parsing of file paths on windows in redirect/compile dss commands

Squashed commit of the following:

commit 9a92736
Author: David M Fobes <[email protected]>
Date:   Mon Nov 2 11:07:06 2020 -0700

    FIX: dss parser file path bug

    fixes bug in dss parser where whole file paths were not being  passed
    during redirect/compile commands if `\` was used instead of `/`, i.e.
    dss files exist in subdirectories.

commit 614d712
Author: David M Fobes <[email protected]>
Date:   Mon Nov 2 09:57:57 2020 -0700

    FIX: unstable test

commit a10bed8
Author: David M Fobes <[email protected]>
Date:   Fri Oct 30 14:13:48 2020 -0600

    FIX: unstable unit tests on travis (work locally, need to debug)

commit ed10967
Author: David M Fobes <[email protected]>
Date:   Thu Oct 29 14:59:48 2020 -0600

    REVERT: storage test was changed unnecessarily

commit 03c6816
Author: David M Fobes <[email protected]>
Date:   Thu Oct 29 14:40:09 2020 -0600

    UPD: travis tests to julia 1.5

commit d3552c5
Author: David M Fobes <[email protected]>
Date:   Thu Oct 29 14:34:31 2020 -0600

    UPD: changelog and version bump

commit 259447f
Author: David M Fobes <[email protected]>
Date:   Thu Oct 29 14:34:15 2020 -0600

    REF: reorganize order of functions in objective.jl

commit 40b8a19
Merge: 42ad101 6cca182
Author: David M Fobes <[email protected]>
Date:   Thu Oct 29 14:07:40 2020 -0600

    Merge branch 'master' into feature-iterate-over-connections

commit 42ad101
Author: David M Fobes <[email protected]>
Date:   Thu Oct 29 12:04:49 2020 -0600

    Disable "3-bus SDPUBFKCLMX opf_bf" test (unstable)

commit 31a37be
Author: David M Fobes <[email protected]>
Date:   Tue Aug 25 07:09:58 2020 -0600

    FIX: minor cleanup to matrix forms

commit 339ee99
Author: David M Fobes <[email protected]>
Date:   Tue Aug 25 07:07:36 2020 -0600

    ADD: solution processors

    Adds a couple of solution processors for converting ACR and
    LPUBFDiag voltage results to vm,va (if possible)

commit 21d8882
Author: David M Fobes <[email protected]>
Date:   Tue Jul 28 17:26:43 2020 -0600

    FIX: loop

commit a6d2e7b
Author: David M Fobes <[email protected]>
Date:   Tue Jul 28 15:58:05 2020 -0600

    FIX: required objective functions

commit a3b8004
Author: David M Fobes <[email protected]>
Date:   Tue Jul 28 15:57:04 2020 -0600

    UPD: drop support for JuMP<0.21

commit d17fd59
Author: David M Fobes <[email protected]>
Date:   Tue Jul 28 15:54:44 2020 -0600

    FIX: Relaxations

commit ee2b74f
Author: David M Fobes <[email protected]>
Date:   Tue Jul 28 10:50:00 2020 -0600

    REF: rename

    variable_mc_gen_power_setpoint -> variable_mc_generator_power
    constraint_mc_gen_setpoint -> constraint_mc_generator_power
    constraint_mc_gen_current -> constraint_mc_generator_current
    constraint_mc_gen_current_real -> constraint_mc_generator_current_real
    constraint_mc_gen_current_imaginary -> constraint_mc_generator_current_imaginary
    constraint_mc_gen_setpoint_wye -> constraint_mc_generator_power_wye

commit cda69e7
Author: David M Fobes <[email protected]>
Date:   Tue Jul 28 08:46:51 2020 -0600

    ADD: delta projection

commit b4a800b
Author: David M Fobes <[email protected]>
Date:   Tue Jul 28 08:38:06 2020 -0600

    FIX: transformer tests

commit 17c3a6e
Author: David M Fobes <[email protected]>
Date:   Mon Jul 27 16:12:33 2020 -0600

    FIX: mld formulation

    objectives changed due to changes in objective function

commit bc92a50
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 14:23:50 2020 -0600

    WIP: FIX: MLD

commit 776bb06
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 13:48:58 2020 -0600

    REF: power_balance_shed to be consistent with others

commit 6ca0396
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 13:48:31 2020 -0600

    FIX: delta gen ACR

commit b0a76e6
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 13:48:05 2020 -0600

    FIX: load models for ACP

commit a34408d
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 13:47:47 2020 -0600

    FIX: delta components

commit d092cd9
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 13:46:57 2020 -0600

    FIX: IVR

commit e9551d1
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 13:46:29 2020 -0600

    FIX: UBF formulations

commit c9641ac
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 13:45:34 2020 -0600

    FIX: network_power_balance

commit ba007d3
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 09:49:07 2020 -0600

    FIX: ACR

commit 5660e28
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 08:52:55 2020 -0600

    REF: make power balance constraint implementation consistent

commit 1930c3f
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 08:51:56 2020 -0600

    FIX: transformer eng2math

commit 5c57994
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 08:51:14 2020 -0600

    REF: make variable names consistent

commit 517a64a
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 08:00:51 2020 -0600

    FIX: ACR delta components

commit 662343e
Author: David M Fobes <[email protected]>
Date:   Fri Jul 24 08:00:26 2020 -0600

    REVERT: transformer eng2math

commit 69a69c6
Author: David M Fobes <[email protected]>
Date:   Thu Jul 23 16:06:45 2020 -0600

    WIP: upgrade to active terminal variables and constraints

commit 1d9e384
Author: David M Fobes <[email protected]>
Date:   Tue Jul 14 16:22:51 2020 -0600

    WIP: REF: per phase problem construction (unprojected)

commit b83e765
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:14:40 2020 -0600

    FIX: MLD objective

commit bd0ec41
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:14:17 2020 -0600

    FIX: Storage thermal limit

commit a30ba49
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:14:02 2020 -0600

    WIP: UPD: LPUBFDiag constraints for connections only

commit 17b7a9d
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:13:34 2020 -0600

    WIP: UPD: APO constraints for connections only

commit a480b04
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:13:02 2020 -0600

    WIP: UPD: ACP constraints only for connections

commit 81affab
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:12:37 2020 -0600

    WIP: UPD: variables to be created for only connections

commit 00e9c48
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:11:59 2020 -0600

    WIP: temp disable broken checks

commit a5fa500
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:11:07 2020 -0600

    FIX: _calc_branch_power_max

commit 8d9e2bf
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:10:47 2020 -0600

    FIX: _calc_transformer_current_max_frto

commit f61510a
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:10:15 2020 -0600

    FIX: _calc_load_vbounds

commit e669d64
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:09:30 2020 -0600

    WIP: update to use conns refs

commit 4cd9e8a
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:08:00 2020 -0600

    RM: transformer calcs on branches

commit be08089
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:04:24 2020 -0600

    ADD: ref add bus connections to run and instantiate funcs

commit 055e32f
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:03:40 2020 -0600

    ADD: storage injection bound calculator

commit f04169b
Author: David M Fobes <[email protected]>
Date:   Fri Jul 10 15:03:06 2020 -0600

    ADD: bus connections to ref

* FIX: ps, qs, energy were not getting converted into SI

* FIX: Incremental compilation broken warning

Instead of overwriting some objective functions from PowerModels,
we instead created some multiconductor versions of them and still
rely on some PowerModels helper functions for building the cost
functions.

Added:

- objective_mc_min_fuel_cost
- objective_mc_min_fuel_cost_pwl
- objective_mc_variable_pg_cost
- objective_mc_min_fuel_cost_polynomial
- _objective_mc_min_fuel_cost_polynomial_linquad
- _objective_mc_min_fuel_cost_polynomial_nl

* UPD: Publication in README

* FIX: bug in json parser

* FIX: #315 - bug in dss parser

Fixes bug in dss parser that skips some files with same names as
previously parsed files even if full path to file is different

Closes #315
Closes #307
Closes #305
Closes #304
Closes #302
Closes #298
Closes #296
  • Loading branch information
pseudocubic authored Dec 8, 2020
1 parent 351c97d commit 983e461
Show file tree
Hide file tree
Showing 53 changed files with 3,286 additions and 2,454 deletions.
30 changes: 29 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
# PowerModelsDistribution.jl Change Log

## staged
## v0.10.0

- Refactor variables, constraints, objectives to support iterating over arbitrary connections/terminals (breaking)
- Add `ref_add_connections!` that adds lists of connections to ref for each component (breaking)
- Rename constraint and variable functions to better match PowerModels conventions (breaking)
- variable_mc_gen_power_setpoint -> variable_mc_generator_power
- variable_mc_gen_power_setpoint_on_off -> variable_mc_generator_power_on_off
- constraint_mc_gen_setpoint -> constraint_mc_generator_power
- constraint_mc_slack_power_balance -> constraint_mc_power_balance_slack
- constraint_mc_shed_power_balance -> constraint_mc_power_balance_shed
- constraint_mc_load_power_balance -> constraint_mc_power_balance
- variable_mc_load_setpoint -> variable_mc_load_power
- constraint_mc_load_setpoint -> constraint_mc_load_power
- Updates objective function for MLD problem (breaking)
- Add `correct_mc_voltage_angle_differences`, `correct_mc_thermal_limits`
- Removed support for JuMP \< v0.21 (breaking)
- Overrides `_objective_min_fuel_cost_polynomial_linquad` from PowerModels to support arbitrary connections on generators
- Updated solution building functions to automatically parse arbitrarily-sized vectors of variables into solutions
- Changed `Array{...,1}` to `Vector{...}` and `Array{...,2}` to `Matrix{...}`
- Removes phase projection by default, but keeps phase projection for delta connected components for now (breaking)
- Adds `apply_phase_projection_delta!` to project phases of delta connected components
- Fixes grounding logic for generator and solar objects
- Fixes bug in parsing of file paths on windows in redirect/compile dss commands
- Adds multiconductor version of the OPF objective function `objective_mc_min_fuel_cost`
- Update publication in README
- Fixes bug in json parser (typo)
- Fixes bug in dss parser that skips some files with same names as previously parsed files

## v0.9.3

- Fix bug in buscoords parser to support more valid buscoords files
- Fix bug in parse_json(::String) which passed additional unused argument to parse_json(::IO)
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "PowerModelsDistribution"
uuid = "d7431456-977f-11e9-2de3-97ff7677985e"
authors = ["David M Fobes <[email protected]>", "Carleton Coffrin"]
repo = "https://github.com/lanl-ansi/PowerModelsDistribution.jl.git"
version = "0.9.3"
version = "0.10.0"

[deps]
InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0"
Expand All @@ -19,7 +19,7 @@ Cbc = ">= 0.4"
InfrastructureModels = "~0.5"
Ipopt = ">= 0.4"
JSON = "~0.18, ~0.19, ~0.20, ~0.21"
JuMP = "~0.19.2, ~0.20, ~0.21"
JuMP = "~0.21"
Juniper = ">= 0.4"
MathOptInterface = "~0.8, ~0.9"
Memento = "~0.10, ~0.11, ~0.12, ~0.13, ~1.0, ~1.1"
Expand Down
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

<img src="https://lanl-ansi.github.io/PowerModelsDistribution.jl/dev/assets/logo.svg" align="left" width="200" alt="PowerModelsDistribution logo">

Release:
[![docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://lanl-ansi.github.io/PowerModelsDistribution.jl/stable/)

Dev:
[![Build Status](https://travis-ci.org/lanl-ansi/PowerModelsDistribution.jl.svg?branch=master)](https://travis-ci.org/lanl-ansi/PowerModelsDistribution.jl)
[![codecov](https://codecov.io/gh/lanl-ansi/PowerModelsDistribution.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/lanl-ansi/PowerModelsDistribution.jl)
[![docs](https://img.shields.io/badge/docs-latest-blue.svg)](https://lanl-ansi.github.io/PowerModelsDistribution.jl/latest/)
![CI](https://github.com/lanl-ansi/PowerModelsDistribution.jl/workflows/CI/badge.svg) ![Documentation](https://github.com/lanl-ansi/PowerModelsDistribution.jl/workflows/Documentation/badge.svg)

PowerModelsDistribution.jl is an extention package of PowerModels.jl for Steady-State Power Distribution Network Optimization. It is designed to enable computational evaluation of emerging power network formulations and algorithms in a common platform. The code is engineered to decouple problem specifications (e.g. Power Flow, Optimal Power Flow, ...) from the power network formulations (e.g. AC, linear-approximation, SOC-relaxation, ...).
This enables the definition of a wide variety of power network formulations and their comparison on common problem specifications.
Expand Down Expand Up @@ -61,16 +55,21 @@ This code has been developed as part of the Advanced Network Science Initiative

## Citing PowerModelsDistribution

If you find PowerModelsDistribution useful for your work, we kindly request that you cite the following [publication](https://arxiv.org/abs/2004.10081):
If you find PowerModelsDistribution useful for your work, we kindly request that you cite the following [publication](https://doi.org/10.1016/j.epsr.2020.106664):

```bibtex
@misc{fobes2020powermodelsdistributionjl,
title={PowerModelsDistribution.jl: An Open-Source Framework for Exploring Distribution Power Flow Formulations},
author={David M Fobes and Sander Claeys and Frederik Geth and Carleton Coffrin},
year={2020},
eprint={2004.10081},
archivePrefix={arXiv},
primaryClass={cs.CE}
@article{FOBES2020106664,
title = "PowerModelsDistribution.jl: An open-source framework for exploring distribution power flow formulations",
journal = "Electric Power Systems Research",
volume = "189",
pages = "106664",
year = "2020",
issn = "0378-7796",
doi = "https://doi.org/10.1016/j.epsr.2020.106664",
url = "http://www.sciencedirect.com/science/article/pii/S0378779620304673",
author = "David M. Fobes and Sander Claeys and Frederik Geth and Carleton Coffrin",
keywords = "Nonlinear optimization, Convex optimization, AC optimal power flow, Julia language, Open-source",
abstract = "In this work we introduce PowerModelsDistribution, a free, open-source toolkit for distribution power network optimization, whose primary focus is establishing a baseline implementation of steady-state multi-conductor unbalanced distribution network optimization problems, which includes implementations of Power Flow and Optimal Power Flow problem types. Currently implemented power flow formulations for these problem types include AC (polar and rectangular), a second-order conic relaxation of the Branch Flow Model (BFM) and Bus Injection Model (BIM), a semi-definite relaxation of BFM, and several linear approximations, such as the simplified unbalanced BFM. The results of AC power flow have been validated against OpenDSS, an open-source “electric power distribution system simulator”, using IEEE distribution test feeders (13, 34, 123 bus and LVTestCase), all parsed using a built-in OpenDSS parser. This includes support for standard distribution system components as well as novel resource models such as generic energy storage (multi-period) and photovoltaic systems, with the intention to add support for additional components in the future."
}
```

Expand Down
1 change: 1 addition & 0 deletions src/PowerModelsDistribution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module PowerModelsDistribution
include("core/variable_mx.jl")
include("core/constraint.jl")
include("core/objective.jl")
include("core/solution.jl")

include("form/acp.jl")
include("form/acr.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/core/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ function instantiate_mc_model(data::Dict{String,<:Any}, model_type::Type, build_
data = transform_data_model(data)
end

return _PM.instantiate_model(data, model_type, build_method; ref_extensions=[ref_extensions..., ref_add_arcs_transformer!], kwargs...)
return _PM.instantiate_model(data, model_type, build_method; ref_extensions=[ref_extensions..., ref_add_arcs_transformer!, ref_add_connections!], kwargs...)
end
94 changes: 50 additions & 44 deletions src/core/constraint.jl
Original file line number Diff line number Diff line change
@@ -1,104 +1,110 @@
"do nothing by default"
function constraint_mc_model_voltage(pm::_PM.AbstractPowerModel, n::Int)
function constraint_mc_model_voltage(pm::_PM.AbstractPowerModel, nw::Int)
end


"Generic thermal limit constraint from-side"
function constraint_mc_thermal_limit_from(pm::_PM.AbstractPowerModel, n::Int, f_idx, rate_a)
p_fr = var(pm, n, :p, f_idx)
q_fr = var(pm, n, :q, f_idx)
function constraint_mc_thermal_limit_from(pm::_PM.AbstractPowerModel, nw::Int, f_idx::Tuple{Int,Int,Int}, f_connections::Vector{Int}, rate_a::Vector{<:Real})
p_fr = [var(pm, nw, :p, f_idx)[c] for c in f_connections]
q_fr = [var(pm, nw, :q, f_idx)[c] for c in f_connections]

mu_sm_fr = JuMP.@constraint(pm.model, p_fr.^2 + q_fr.^2 .<= rate_a.^2)

if _IM.report_duals(pm)
sol(pm, n, :branch, f_idx[1])[:mu_sm_fr] = mu_sm_fr
sol(pm, nw, :branch, f_idx[1])[:mu_sm_fr] = mu_sm_fr
end
end


"Generic thermal limit constraint to-side"
function constraint_mc_thermal_limit_to(pm::_PM.AbstractPowerModel, n::Int, t_idx, rate_a)
p_to = var(pm, n, :p, t_idx)
q_to = var(pm, n, :q, t_idx)
function constraint_mc_thermal_limit_to(pm::_PM.AbstractPowerModel, nw::Int, t_idx::Tuple{Int,Int,Int}, t_connections::Vector{Int}, rate_a::Vector{<:Real})
p_to = [var(pm, nw, :p, t_idx)[c] for c in t_connections]
q_to = [var(pm, nw, :q, t_idx)[c] for c in t_connections]

mu_sm_to = JuMP.@constraint(pm.model, p_to.^2 + q_to.^2 .<= rate_a.^2)

if _IM.report_duals(pm)
sol(pm, n, :branch, t_idx[1])[:mu_sm_to] = mu_sm_to
sol(pm, nw, :branch, t_idx[1])[:mu_sm_to] = mu_sm_to
end
end


"on/off bus voltage magnitude constraint"
function constraint_mc_bus_voltage_magnitude_on_off(pm::_PM.AbstractPowerModel, n::Int, i::Int, vmin, vmax)
vm = var(pm, n, :vm, i)
z_voltage = var(pm, n, :z_voltage, i)
function constraint_mc_bus_voltage_magnitude_on_off(pm::_PM.AbstractPowerModel, nw::Int, i::Int, vmin::Vector{<:Real}, vmax::Vector{<:Real})
vm = var(pm, nw, :vm, i)
z_voltage = var(pm, nw, :z_voltage, i)

for c in conductor_ids(pm, n)
if isfinite(vmax[c])
JuMP.@constraint(pm.model, vm[c] <= vmax[c]*z_voltage)
terminals = ref(pm, nw, :bus, i)["terminals"]
grounded = ref(pm, nw, :bus, i)["grounded"]

for (idx, t) in [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]]
if isfinite(vmax[idx])
JuMP.@constraint(pm.model, vm[t] <= vmax[idx]*z_voltage)
end

if isfinite(vmin[c])
JuMP.@constraint(pm.model, vm[c] >= vmin[c]*z_voltage)
if isfinite(vmin[idx])
JuMP.@constraint(pm.model, vm[t] >= vmin[idx]*z_voltage)
end
end
end


"on/off bus voltage magnitude squared constraint for relaxed formulations"
function constraint_mc_bus_voltage_magnitude_sqr_on_off(pm::_PM.AbstractPowerModel, n::Int, i::Int, vmin, vmax)
w = var(pm, n, :w, i)
z_voltage = var(pm, n, :z_voltage, i)
function constraint_mc_bus_voltage_magnitude_sqr_on_off(pm::_PM.AbstractPowerModel, nw::Int, i::Int, vmin::Vector{<:Real}, vmax::Vector{<:Real})
w = var(pm, nw, :w, i)
z_voltage = var(pm, nw, :z_voltage, i)

terminals = ref(pm, nw, :bus, i)["terminals"]
grounded = ref(pm, nw, :bus, i)["grounded"]

for c in conductor_ids(pm, n)
if isfinite(vmax[c])
JuMP.@constraint(pm.model, w[c] <= vmax[c]^2*z_voltage)
for (idx,t) in [(idx,t) for (idx,t) in enumerate(terminals) if !grounded[idx]]
if isfinite(vmax[idx])
JuMP.@constraint(pm.model, w[t] <= vmax[idx]^2*z_voltage)
end

if isfinite(vmin[c])
JuMP.@constraint(pm.model, w[c] >= vmin[c]^2*z_voltage)
if isfinite(vmin[idx])
JuMP.@constraint(pm.model, w[t] >= vmin[idx]^2*z_voltage)
end
end
end


function constraint_mc_gen_power_setpoint_real(pm::_PM.AbstractPowerModel, n::Int, i, pg)
pg_var = var(pm, n, :pg, i)
function constraint_mc_gen_power_setpoint_real(pm::_PM.AbstractPowerModel, nw::Int, i::Int, pg::Vector{<:Real})
pg_var = [var(pm, nw, :pg, i)[c] for c in ref(pm, nw, :gen, i)["connections"]]
JuMP.@constraint(pm.model, pg_var .== pg)
end


"on/off constraint for generators"
function constraint_mc_gen_power_on_off(pm::_PM.AbstractPowerModel, n::Int, i::Int, pmin, pmax, qmin, qmax)
pg = var(pm, n, :pg, i)
qg = var(pm, n, :qg, i)
z = var(pm, n, :z_gen, i)

for c in conductor_ids(pm, n)
if isfinite(pmax[c])
JuMP.@constraint(pm.model, pg[c] .<= pmax[c].*z)
function constraint_mc_gen_power_on_off(pm::_PM.AbstractPowerModel, nw::Int, i::Int, connections::Vector{<:Int}, pmin::Vector{<:Real}, pmax::Vector{<:Real}, qmin::Vector{<:Real}, qmax::Vector{<:Real})
pg = var(pm, nw, :pg, i)
qg = var(pm, nw, :qg, i)
z = var(pm, nw, :z_gen, i)

for (idx, c) in enumerate(connections)
if isfinite(pmax[idx])
JuMP.@constraint(pm.model, pg[c] .<= pmax[idx].*z)
end

if isfinite(pmin[c])
JuMP.@constraint(pm.model, pg[c] .>= pmin[c].*z)
if isfinite(pmin[idx])
JuMP.@constraint(pm.model, pg[c] .>= pmin[idx].*z)
end

if isfinite(qmax[c])
JuMP.@constraint(pm.model, qg[c] .<= qmax[c].*z)
if isfinite(qmax[idx])
JuMP.@constraint(pm.model, qg[c] .<= qmax[idx].*z)
end

if isfinite(qmin[c])
JuMP.@constraint(pm.model, qg[c] .>= qmin[c].*z)
if isfinite(qmin[idx])
JuMP.@constraint(pm.model, qg[c] .>= qmin[idx].*z)
end
end
end


""
function constraint_mc_storage_thermal_limit(pm::_PM.AbstractPowerModel, n::Int, i, rating)
ps = var(pm, n, :ps, i)
qs = var(pm, n, :qs, i)
function constraint_mc_storage_thermal_limit(pm::_PM.AbstractPowerModel, nw::Int, i::Int, connections::Vector{Int}, rating::Vector{<:Real})
ps = [var(pm, nw, :ps, i)[c] for c in connections]
qs = [var(pm, nw, :qs, i)[c] for c in connections]

JuMP.@constraint(pm.model, ps.^2 + qs.^2 .<= rating.^2)
end
Loading

2 comments on commit 983e461

@pseudocubic
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/26068

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.10.0 -m "<description of version>" 983e4617e5fd203e398566d73980de64bd3ff497
git push origin v0.10.0

Please sign in to comment.