Variables for Mathematical Programs
CommonOPF provides standard variables names so that the packages that build upon CommonOPF can leverage common results getters and VariableBounds
.
Variable Containers
CommonOPF provides variable containers to standardize indexing across OPF models. The order of indexing is:
var_symbol
like:v
bus_or_edge
time_step
- phase in
[1, 2, 3]
(ifMultiPhase
model)
Single phase models
CommonOPF.add_time_vector_variables!
— Functionadd_time_vector_variables!(
m::JuMP.AbstractModel,
net::Network{SinglePhase},
var_symbol::Symbol,
indices::AbstractVector{T}
) where {T}
Add variables to the m.obj_dict
indexed on:
var_symbol
like:v
indices
, typically aVector{String}
for bus indices or aVector{Tuple{String, String}}
for edge indices (like("bus1", "bus2")
)- timesteps in
1:net.Ntimesteps
For example, accessing the edge variable :sij
one edge ("bus1", "bus2")
voltage variable at time step 5
looks like:
m[:sij][("bus1", "bus2")][5]
Multiphase models
CommonOPF.multiphase_bus_variable_container
— Functionmultiphase_bus_variable_container(; default::DefaultType=missing)
Return a DefaultDict of DefaultDict with three key types for indexing variables on:
AbstractString
for bus namesInt
for time stepAbstractVecOrMat
for vectors or matrices of phase variables
CommonOPF.multiphase_edge_variable_container
— Functionmultiphase_edge_variable_container(; default::DefaultType=missing)
Return a DefaultDict of DefaultDict with three key types for indexing variables on:
Tuple{String, String}
for edge namesInt
for time stepAbstractVecOrMat
for vectors or matrices of phase variables
Variable Bounds
CommonOPF.VariableBounds
— Typestruct VariableBounds
Limits for decision variables in mathematical programs. Upper and lower values can be specified for power, current, and voltage variables. The VariableBounds
struct is attached to Network.bounds
upon creation of the Network
.
mutable struct VariableBounds
s_upper_real::Union{Real, Missing}
s_lower_real::Union{Real, Missing}
s_upper_imag::Union{Real, Missing}
s_lower_imag::Union{Real, Missing}
v_upper_mag::Union{Real, Missing}
v_lower_mag::Union{Real, Missing}
i_upper_mag::Union{Real, Missing}
i_lower_mag::Union{Real, Missing}
end
CommonOPF.VariableBounds
— Methodfunction VariableBounds(ntwk::Dict)
Check for the keys of the VariableBounds
struct in the ntwk
dictionary. Any missing bounds are set to missing
.
Documenting Variables
CommonOPF provides a way to document model variables within the Network
struct. See the CommonOPF.VariableInfo
struct and the CommonOPF.print_var_info
method below for details. As an example (and test) of the print_var_info
method:
CommonOPF.print_var_info(net)
┌────────┬─────────────────────────────────────────────────────┬───────────────────┬─────────────────────┐
│ symbol │ description │ units │ dimensions │
├────────┼─────────────────────────────────────────────────────┼───────────────────┼─────────────────────┤
│ pij │ sending end real power from bus i to j │ RealPowerUnit │ (Edge, Time, Phase) │
├────────┼─────────────────────────────────────────────────────┼───────────────────┼─────────────────────┤
│ pj │ net bus injection real power on bus j │ RealPowerUnit │ (Bus, Time, Phase) │
├────────┼─────────────────────────────────────────────────────┼───────────────────┼─────────────────────┤
│ qij │ sending end ReactivePowerUnit power from bus i to j │ RealPowerUnit │ (Edge, Time, Phase) │
├────────┼─────────────────────────────────────────────────────┼───────────────────┼─────────────────────┤
│ qj │ net bus injection reactive power on bus j │ ReactivePowerUnit │ (Bus, Time, Phase) │
├────────┼─────────────────────────────────────────────────────┼───────────────────┼─────────────────────┤
│ vsqrd │ voltage magnitude squared │ VoltUnit │ (Bus, Time, Phase) │
└────────┴─────────────────────────────────────────────────────┴───────────────────┴─────────────────────┘
CommonOPF.VariableInfo
— Typestruct VariableInfo
symbol::Symbol
description::String
units::Units
dimensions::Tuple{Vararg{Dimensions}}
end
Variable information for describing variables in sub-modules of CommonOPF. See also Units
, Dimensions
, and print_var_info
.
CommonOPF.Units
— Type@enum Units begin
AmpUnit
VoltUnit
TimeUnit
ApparentPowerUnit
ComplexPowerUnit
ReactivePowerUnit
RealPowerUnit
RadiansUnit
end
Units acceptable for CommonOPF variables.
CommonOPF.Dimensions
— Type@enum Dimensions begin
BusDimension
EdgeDimension
TimeDimension
PhaseDimension
PhaseMatrixDimension
HermitianMatrixDimension
RealReactiveDimension
BusTerminalDimension
end
Dimensions for specifying variable and constraint indices in CommonOPF, i.e. how to access a variable or constraint in the JuMP.Model.obj_dict
.
CommonOPF.print_var_info
— Functionprint_var_info(net::Network)
Print the variable info in net.var_info
in a table like:
julia> print_var_info(net)
┌────────┬───────────────────────────┬──────────┬────────────────────┐
│ symbol │ description │ units │ dimensions │
├────────┼───────────────────────────┼──────────┼────────────────────┤
│ vsqrd │ voltage magnitude squared │ VoltUnit │ (Bus, Time, Phase) │
└────────┴───────────────────────────┴──────────┴────────────────────┘
Add values to Network.var_info
like:
net.var_info[:vsqrd] = CommonOPF.VariableInfo(
:vsqrd,
"voltage magnitude squared",
CommonOPF.VoltUnit,
(CommonOPF.BusDimension, CommonOPF.TimeDimension, CommonOPF.PhaseDimension)
)