Constraints
Constraint Templates
Constraint templates help simplify data wrangling across multiple Power Flow formulations by providing an abstraction layer between the network data and network constraint definitions. The constraint template's job is to extract the required parameters from a given network data structure and pass the data as named arguments to the Power Flow formulations.
These templates should be defined over AbstractPowerModel
and should not refer to model variables. For more details, see the files: core/constraint_template.jl
and core/constraint.jl
(core/constraint_template.jl
provides higher level APIs, and pulls out index information from the data dictionaries, before calling out to methods defined in core/constraint.jl
).
Voltage Constraints
PowerModels.constraint_model_voltage
— FunctionThis constraint captures problem agnostic constraints that are used to link the model's voltage variables together, in addition to the standard problem formulation constraints.
Notable examples include the constraints linking the voltages in the ACTPowerModel, constraints linking convex relaxations of voltage variables.
do nothing, most models to not require any model-specific voltage constraints
PowerModels.constraint_model_voltage_on_off
— FunctionThis constraint captures problem agnostic constraints that are used to link the model's voltage variables together, in addition to the standard problem formulation constraints. The on/off name indicates that the voltages in this constraint can be set to zero via an indicator variable
Notable examples include the constraints linking the voltages in the ACTPowerModel, constraints linking convex relaxations of voltage variables.
do nothing, most models to not require any model-specific on/off voltage constraints
do nothing, this model does not have complex voltage constraints
do nothing, this model does not have complex voltage variables
PowerModels.constraint_ne_model_voltage
— FunctionThis constraint captures problem agnostic constraints that are used to link the model's voltage variables together, in addition to the standard problem formulation constraints. The network expantion name (ne) indicates that the voltages in this constraint can be set to zero via an indicator variable
Notable examples include the constraints linking the voltages in the ACTPowerModel, constraints linking convex relaxations of voltage variables.
do nothing, most models to not require any model-specific network expansion voltage constraints
do nothing, this model does not have complex voltage constraints
do nothing, this model does not have complex voltage variables
Generator Constraints
PowerModels.constraint_gen_setpoint_active
— Functionpg[i] == pg
pg[i] == pg
PowerModels.constraint_gen_setpoint_reactive
— Functionqq[i] == qq
qq[i] == qq
do nothing, apo models do not have reactive variables
Bus Constraints
Setpoint Constraints
PowerModels.constraint_theta_ref
— Functionreference bus angle constraint
t[ref_bus] == 0
nothing to do, no voltage angle variables
t[ref_bus] == 0
Do nothing, no way to represent this in these variables
PowerModels.constraint_voltage_magnitude_setpoint
— Functionv[i] == vm
v[i] == vm
do nothing, this model does not have voltage variables
Power Balance Constraints
PowerModels.constraint_power_balance
— FunctionPowerModels.constraint_power_balance_ls
— Functionnodal power balance with constant power factor load and shunt shedding
PowerModels.constraint_ne_power_balance
— FunctionBranch Constraints
Ohm's Law Constraints
PowerModels.constraint_ohms_yt_from
— FunctionCreates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
p[f_idx] == (g+g_fr)/tm*v[f_bus]^2 + (-g*tr+b*ti)/tm^2*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-b*tr-g*ti)/tm^2*(v[f_bus]*v[t_bus]*sin(t[f_bus]-t[t_bus]))
q[f_idx] == -(b+b_fr)/tm*v[f_bus]^2 - (-b*tr-g*ti)/tm^2*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr+b*ti)/tm^2*(v[f_bus]*v[t_bus]*sin(t[f_bus]-t[t_bus]))
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
p[f_idx] == -b*(t[f_bus] - t[t_bus])
nothing to do, no voltage angle variables
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
PowerModels.constraint_ohms_yt_to
— FunctionCreates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
p[t_idx] == (g+g_to)*v[t_bus]^2 + (-g*tr-b*ti)/tm^2*(v[t_bus]*v[f_bus]*cos(t[t_bus]-t[f_bus])) + (-b*tr+g*ti)/tm^2*(v[t_bus]*v[f_bus]*sin(t[t_bus]-t[f_bus]))
q[t_idx] == -(b+b_to)*v[t_bus]^2 - (-b*tr+g*ti)/tm^2*(v[t_bus]*v[f_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr-b*ti)/tm^2*(v[t_bus]*v[f_bus]*sin(t[t_bus]-t[f_bus]))
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
nothing to do, this model is symetric
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
PowerModels.constraint_ohms_y_from
— FunctionCreates Ohms constraints for AC models (y post fix indicates that Y values are in rectangular form)
p[f_idx] == (g+g_fr)*(v[f_bus]/tr)^2 + -g*v[f_bus]/tr*v[t_bus]*cos(t[f_bus]-t[t_bus]-as) + -b*v[f_bus]/tr*v[t_bus]*sin(t[f_bus]-t[t_bus]-as)
q[f_idx] == -(b+b_fr)*(v[f_bus]/tr)^2 + b*v[f_bus]/tr*v[t_bus]*cos(t[f_bus]-t[t_bus]-as) + -g*v[f_bus]/tr*v[t_bus]*sin(t[f_bus]-t[t_bus]-as)
PowerModels.constraint_ohms_y_to
— FunctionCreates Ohms constraints for AC models (y post fix indicates that Y values are in rectangular form)
p[t_idx] == (g+g_to)*v[t_bus]^2 + -g*v[t_bus]*v[f_bus]/tr*cos(t[t_bus]-t[f_bus]+as) + -b*v[t_bus]*v[f_bus]/tr*sin(t[t_bus]-t[f_bus]+as)
q[t_idx] == -(b+b_to)*v[t_bus]^2 + b*v[t_bus]*v[f_bus]/tr*cos(t[f_bus]-t[t_bus]+as) + -g*v[t_bus]*v[f_bus]/tr*sin(t[t_bus]-t[f_bus]+as)
On/Off Ohm's Law Constraints
PowerModels.constraint_ohms_yt_from_on_off
— Functionp[f_idx] == z*(g/tm*v[f_bus]^2 + (-g*tr+b*ti)/tm^2*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-b*tr-g*ti)/tm^2*(v[f_bus]*v[t_bus]*sin(t[f_bus]-t[t_bus])))
q[f_idx] == z*(-(b+c/2)/tm*v[f_bus]^2 - (-b*tr-g*ti)/tm^2*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr+b*ti)/tm^2*(v[f_bus]*v[t_bus]*sin(t[f_bus]-t[t_bus])))
-b*(t[f_bus] - t[t_bus] + vad_min*(1-z_branch[i])) <= p[f_idx] <= -b*(t[f_bus] - t[t_bus] + vad_max*(1-z_branch[i]))
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
p[f_idx] == g/tm*w_fr[i] + (-g*tr+b*ti)/tm*(wr[i]) + (-b*tr-g*ti)/tm*(wi[i])
q[f_idx] == -(b+c/2)/tm*w_fr[i] - (-b*tr-g*ti)/tm*(wr[i]) + (-g*tr+b*ti)/tm*(wi[i])
PowerModels.constraint_ohms_yt_to_on_off
— Functionp[t_idx] == z*(g*v[t_bus]^2 + (-g*tr-b*ti)/tm^2*(v[t_bus]*v[f_bus]*cos(t[t_bus]-t[f_bus])) + (-b*tr+g*ti)/tm^2*(v[t_bus]*v[f_bus]*sin(t[t_bus]-t[f_bus])))
q[t_idx] == z*(-(b+c/2)*v[t_bus]^2 - (-b*tr+g*ti)/tm^2*(v[t_bus]*v[f_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr-b*ti)/tm^2*(v[t_bus]*v[f_bus]*sin(t[t_bus]-t[f_bus])))
nothing to do, this model is symetric
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
p[t_idx] == g*w_to[i] + (-g*tr-b*ti)/tm*(wr[i]) + (-b*tr+g*ti)/tm*(-wi[i])
q[t_idx] == -(b+c/2)*w_to[i] - (-b*tr+g*ti)/tm*(wr[i]) + (-g*tr-b*ti)/tm*(-wi[i])
PowerModels.constraint_ne_ohms_yt_from
— Functionp_ne[f_idx] == z*(g/tm*v[f_bus]^2 + (-g*tr+b*ti)/tm^2*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-b*tr-g*ti)/tm^2*(v[f_bus]*v[t_bus]*sin(t[f_bus]-t[t_bus])))
q_ne[f_idx] == z*(-(b+c/2)/tm*v[f_bus]^2 - (-b*tr-g*ti)/tm^2*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr+b*ti)/tm^2*(v[f_bus]*v[t_bus]*sin(t[f_bus]-t[t_bus])))
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
p[f_idx] == g/tm*w_fr_ne[i] + (-g*tr+b*ti)/tm*(wr_ne[i]) + (-b*tr-g*ti)/tm*(wi_ne[i])
q[f_idx] == -(b+c/2)/tm*w_fr_ne[i] - (-b*tr-g*ti)/tm*(wr_ne[i]) + (-g*tr+b*ti)/tm*(wi_ne[i])
PowerModels.constraint_ne_ohms_yt_to
— Functionp_ne[t_idx] == z*(g*v[t_bus]^2 + (-g*tr-b*ti)/tm^2*(v[t_bus]*v[f_bus]*cos(t[t_bus]-t[f_bus])) + (-b*tr+g*ti)/tm^2*(v[t_bus]*v[f_bus]*sin(t[t_bus]-t[f_bus])))
q_ne[t_idx] == z*(-(b+c/2)*v[t_bus]^2 - (-b*tr+g*ti)/tm^2*(v[t_bus]*v[f_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr-b*ti)/tm^2*(v[t_bus]*v[f_bus]*sin(t[t_bus]-t[f_bus])))
nothing to do, this model is symetric
Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)
p[t_idx] == g*w_to_ne[i] + (-g*tr-b*ti)/tm*(wr_ne[i]) + (-b*tr+g*ti)/tm*(-wi_ne[i])
q[t_idx] == -(b+c/2)*w_to_ne[i] - (-b*tr+g*ti)/tm*(wr_ne[i]) + (-g*tr-b*ti)/tm*(-wi_ne[i])
Current
PowerModels.constraint_current_balance
— FunctionKirchhoff's current law applied to buses sum(cr + im*ci) = 0
PowerModels.constraint_power_magnitude_sqr
— Functionp[f_idx]^2 + q[f_idx]^2 <= w[f_bus]/tm*cm[f_bus,t_bus]
PowerModels.constraint_power_magnitude_sqr_on_off
— Functionp[arc_from]^2 + q[arc_from]^2 <= w[f_bus]/tm*cm[i]
PowerModels.constraint_power_magnitude_link
— Functioncm[f_bus,t_bus] == (g^2 + b^2)*(w[f_bus]/tm + w[t_bus] - 2*(tr*wr[f_bus,t_bus] + ti*wi[f_bus,t_bus])/tm) - c*q[f_idx] - ((c/2)/tm)^2*w[f_bus]
PowerModels.constraint_power_magnitude_link_on_off
— Functionccm[f_bus,t_bus] == (g^2 + b^2)*(w[f_bus]/tm + w[t_bus] - 2*(tr*wr[f_bus,t_bus] + ti*wi[f_bus,t_bus])/tm) - c*q[f_idx] - ((c/2)/tm)^2*w[f_bus]
Thermal Limit Constraints
PowerModels.constraint_thermal_limit_from
— Functionconstraint_thermal_limit_from(pm::AbstractPowerModel, n::Int, i::Int)
Adds the (upper and lower) thermal limit constraints for the desired branch to the PowerModel.
p[f_idx]^2 + q[f_idx]^2 <= rate_a^2
[rate_a, p[f_idx], q[f_idx]] in SecondOrderCone
p[f_idx]^2 + q[f_idx]^2 <= rate_a^2
-rate_a <= p[f_idx] <= rate_a
PowerModels.constraint_thermal_limit_to
— Functionp[t_idx]^2 + q[t_idx]^2 <= rate_a^2
[rate_a, p[t_idx], q[t_idx]] in SecondOrderCone
p[t_idx]^2 + q[t_idx]^2 <= rate_a^2
nothing to do, this model is symetric
PowerModels.constraint_thermal_limit_from_on_off
— Functionp[f_idx]^2 + q[f_idx]^2 <= (rate_a * z_branch[i])^2
PowerModels.constraint_thermal_limit_to_on_off
— Functionp[t_idx]^2 + q[t_idx]^2 <= (rate_a * z_branch[i])^2
nothing to do, this model is symetric
PowerModels.constraint_ne_thermal_limit_from
— Functionp_ne[f_idx]^2 + q_ne[f_idx]^2 <= (rate_a * branch_ne[i])^2
PowerModels.constraint_ne_thermal_limit_to
— Functionp_ne[t_idx]^2 + q_ne[t_idx]^2 <= (rate_a * branch_ne[i])^2
nothing to do, this model is symetric
Current Limit Constraints
Missing docstring for constraint_current_limit
. Check Documenter's build log for details.
PowerModels.constraint_current_to
— FunctionDefines how current distributes over series and shunt impedances of a pi-model branch
PowerModels.constraint_current_from
— FunctionDefines how current distributes over series and shunt impedances of a pi-model branch
Phase Angle Difference Constraints
PowerModels.constraint_voltage_angle_difference
— FunctionBounds the voltage angle difference between bus pairs
branch voltage angle difference bounds
t[f_bus] - t[t_bus] <= angmax
t[f_bus] - t[t_bus] >= angmin
nothing to do, no voltage angle variables
PowerModels.constraint_voltage_angle_difference_on_off
— Functionangmin <= z_branch[i]*(t[f_bus] - t[t_bus]) <= angmax
angmin*z_branch[i] + vad_min*(1-z_branch[i]) <= t[f_bus] - t[t_bus] <= angmax*z_branch[i] + vad_max*(1-z_branch[i])
angmin*z_branch[i] + vad_min*(1-z_branch[i]) <= t[f_bus] - t[t_bus] <= angmax*z_branch[i] + vad_max*(1-z_branch[i])
angmin*wr[i] <= wi[i] <= angmax*wr[i]
PowerModels.constraint_ne_voltage_angle_difference
— Functionangmin <= branch_ne[i]*(t[f_bus] - t[t_bus]) <= angmax
angmin*branch_ne[i] + vad_min*(1-branch_ne[i]) <= t[f_bus] - t[t_bus] <= angmax*branch_ne[i] + vad_max*(1-branch_ne[i])
angmin*branch_ne[i] + vad_min*(1-branch_ne[i]) <= t[f_bus] - t[t_bus] <= angmax*branch_ne[i] + vad_max*(1-branch_ne[i])
angmin*wr_ne[i] <= wi_ne[i] <= angmax*wr_ne[i]
Loss Constraints
PowerModels.constraint_power_losses
— FunctionDefines branch flow model power flow equations
Defines linear branch flow model power flow equations
PowerModels.constraint_power_losses_lb
— Functionp[f_idx] + p[t_idx] >= 0
q[f_idx] + q[t_idx] >= -c/2*(v[f_bus]^2/tr^2 + v[t_bus]^2)
PowerModels.constraint_voltage_magnitude_difference
— FunctionDefines voltage drop over a branch, linking from and to side voltage magnitude
Defines voltage drop over a branch, linking from and to side voltage magnitude
PowerModels.constraint_voltage_drop
— FunctionDefines voltage drop over a branch, linking from and to side complex voltage
Storage Constraints
PowerModels.constraint_storage_thermal_limit
— FunctionPowerModels.constraint_storage_current_limit
— FunctionPowerModels.constraint_storage_complementarity_nl
— FunctionPowerModels.constraint_storage_complementarity_mi
— FunctionPowerModels.constraint_storage_losses
— FunctionNeglects the active and reactive loss terms associated with the squared current magnitude.
PowerModels.constraint_storage_state_initial
— FunctionPowerModels.constraint_storage_state
— FunctionDC Line Constraints
PowerModels.constraint_dcline_power_losses
— FunctionCreates Line Flow constraint for DC Lines (Matpower Formulation)
p_fr + p_to == loss0 + p_fr * loss1
PowerModels.constraint_dcline_setpoint_active
— Functionpf[i] == pf, pt[i] == pt
p_fr[i] == pref_fr, p_to[i] == pref_to
Switch Constraints
PowerModels.constraint_switch_state
— Functionenforces static switch constraints
PowerModels.constraint_switch_on_off
— Functionenforces controlable switch constraints
PowerModels.constraint_switch_thermal_limit
— Functionenforces an mva limit on the power flow over a switch