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 GenericPowerModel
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_voltage
— Function.do nothing, this model does not have complex voltage constraints
do nothing, this model does not have complex voltage constraints
do nothing, this model does not have complex voltage variables
PowerModels.constraint_voltage_on_off
— Function.do nothing, this model does not have complex voltage constraints
do nothing, this model does not have complex voltage variables
PowerModels.constraint_voltage_ne
— Function.do nothing, this model does not have complex voltage constraints
do nothing, this model does not have complex voltage variables
Generator Constraints
PowerModels.constraint_active_gen_setpoint
— Function.pg[i] == pg
PowerModels.constraint_reactive_gen_setpoint
— Function.qq[i] == qq
do nothing, apo models do not have reactive variables
Bus Constraints
Setpoint Constraints
PowerModels.constraint_theta_ref
— Function.reference bus angle constraint
t[ref_bus] == 0
nothing to do, no voltage angle variables
t[ref_bus] == 0
t[ref_bus] == 0
Do nothing, no way to represent this in these variables
v[i] == vm
v[i] == vm
do nothing, this model does not have voltage variables
Power Balance Constraints
PowerModels.constraint_power_balance
— Function.ensures that power generation and demand are balanced
KCL Constraints
PowerModels.constraint_kcl_shunt
— Function.sum(p[a] for a in bus_arcs) + sum(p_dc[a_dc] for a_dc in bus_arcs_dc) == sum(pg[g] for g in bus_gens) - sum(pd[d] for d in bus_loads) - sum(gs[s] for s in bus_shunts)*v^2
sum(q[a] for a in bus_arcs) + sum(q_dc[a_dc] for a_dc in bus_arcs_dc) == sum(qg[g] for g in bus_gens) - sum(qd[d] for d in bus_loads) + sum(bs[s] for s in bus_shunts)*v^2
sum(p[a] for a in bus_arcs) + sum(p_dc[a_dc] for a_dc in bus_arcs_dc) == sum(pg[g] for g in bus_gens) - sum(pd[d] for d in bus_loads) - sum(gs[s] for d in bus_shunts)*w[i]
sum(q[a] for a in bus_arcs) + sum(q_dc[a_dc] for a_dc in bus_arcs_dc) == sum(qg[g] for g in bus_gens) - sum(qd[d] for d in bus_loads) + sum(bs[s] for d in bus_shunts)*w[i]
PowerModels.constraint_kcl_shunt_storage
— Function.PowerModels.constraint_kcl_shunt_ne
— Function.sum(p[a] for a in bus_arcs) + sum(p_dc[a_dc] for a_dc in bus_arcs_dc) + sum(p_ne[a] for a in bus_arcs_ne) == sum(pg[g] for g in bus_gens) - sum(pd[d] for d in bus_loads) - sum(gs[s] for s in bus_shunts)*vm^2
sum(q[a] for a in bus_arcs) + sum(p_dc[a_dc] for a_dc in bus_arcs_dc) + sum(q_ne[a] for a in bus_arcs_ne) == sum(qg[g] for g in bus_gens) - sum(qd[d] for d in bus_loads) + sum(bs[s] for s in bus_shunts)*vm^2
sum(p[a] for a in bus_arcs) + sum(p_ne[a] for a in bus_arcs_ne) + sum(p_dc[a_dc] for a_dc in bus_arcs_dc) == sum(pg[g] for g in bus_gens) - sum(pd[d] for d in bus_loads) - sum(gs[s] for s in bus_shunts)*w[i]
sum(q[a] for a in bus_arcs) + sum(q_ne[a] for a in bus_arcs_ne) + sum(q_dc[a_dc] for a_dc in bus_arcs_dc) == sum(qg[g] for g in bus_gens) - sum(qd[d] for d in bus_loads) + sum(bs[s] for s in bus_shunts)*w[i]
Branch Constraints
Ohm's Law Constraints
PowerModels.constraint_ohms_yt_from
— Function.Creates 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*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-b*tr-g*ti)/tm*(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*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr+b*ti)/tm*(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
— Function.Creates 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*(v[t_bus]*v[f_bus]*cos(t[t_bus]-t[f_bus])) + (-b*tr+g*ti)/tm*(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*(v[t_bus]*v[f_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr-b*ti)/tm*(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
— Function.Creates 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
— Function.Creates 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_to == -(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
— Function.p[f_idx] == z*(g/tm*v[f_bus]^2 + (-g*tr+b*ti)/tm*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-b*tr-g*ti)/tm*(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*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr+b*ti)/tm*(v[f_bus]*v[t_bus]*sin(t[f_bus]-t[t_bus])))
-b*(t[f_bus] - t[t_bus] + vad_min*(1-branch_z[i])) <= p[f_idx] <= -b*(t[f_bus] - t[t_bus] + vad_max*(1-branch_z[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
— Function.p[t_idx] == z*(g*v[t_bus]^2 + (-g*tr-b*ti)/tm*(v[t_bus]*v[f_bus]*cos(t[t_bus]-t[f_bus])) + (-b*tr+g*ti)/tm*(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*(v[t_bus]*v[f_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr-b*ti)/tm*(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_ohms_yt_from_ne
— Function.p_ne[f_idx] == z*(g/tm*v[f_bus]^2 + (-g*tr+b*ti)/tm*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-b*tr-g*ti)/tm*(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*(v[f_bus]*v[t_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr+b*ti)/tm*(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_ohms_yt_to_ne
— Function.p_ne[t_idx] == z*(g*v[t_bus]^2 + (-g*tr-b*ti)/tm*(v[t_bus]*v[f_bus]*cos(t[t_bus]-t[f_bus])) + (-b*tr+g*ti)/tm*(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*(v[t_bus]*v[f_bus]*cos(t[f_bus]-t[t_bus])) + (-g*tr-b*ti)/tm*(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_power_magnitude_sqr
— Function.p[f_idx]^2 + q[f_idx]^2 <= w[f_bus]/tm*cm[f_bus,t_bus]
p[arc_from]^2 + q[arc_from]^2 <= w[f_bus]/tm*cm[i]
PowerModels.constraint_power_magnitude_link
— Function.cm[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]
cm[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
— Function.constraint_thermal_limit_from(pm::GenericPowerModel, 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
-rate_a <= p[f_idx] <= rate_a
PowerModels.constraint_thermal_limit_to
— Function.p[t_idx]^2 + q[t_idx]^2 <= rate_a^2
[rate_a, p[t_idx], q[t_idx]] in SecondOrderCone
nothing to do, this model is symetric
PowerModels.constraint_thermal_limit_from_on_off
— Function.p[f_idx]^2 + q[f_idx]^2 <= (rate_a * branch_z[i])^2
PowerModels.constraint_thermal_limit_to_on_off
— Function.p[t_idx]^2 + q[t_idx]^2 <= (rate_a * branch_z[i])^2
nothing to do, this model is symetric
PowerModels.constraint_thermal_limit_from_ne
— Function.p_ne[f_idx]^2 + q_ne[f_idx]^2 <= (rate_a * branch_ne[i])^2
PowerModels.constraint_thermal_limit_to_ne
— Function.p_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
PowerModels.constraint_current_limit
— Function.Adds a current magnitude limit constraint for the desired branch to the PowerModel.
Phase Angle Difference Constraints
PowerModels.constraint_voltage_angle_difference
— Function.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
t[f_bus] - t[t_bus] <= angmax
t[f_bus] - t[t_bus] >= angmin
angmin <= branch_z[i]*(t[f_bus] - t[t_bus]) <= angmax
angmin*branch_z[i] + vad_min*(1-branch_z[i]) <= t[f_bus] - t[t_bus] <= angmax*branch_z[i] + vad_max*(1-branch_z[i])
angmin*wr[i] <= wi[i] <= angmax*wr[i]
angmin <= 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*wr_ne[i] <= wi_ne[i] <= angmax*wr_ne[i]
Loss Constraints
PowerModels.constraint_loss_lb
— Function.p[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_flow_losses
— Function.Defines branch flow model power flow equations
Defines voltage drop over a branch, linking from and to side voltage magnitude
PowerModels.constraint_branch_current
— Function.Defines relationship between branch (series) power flow, branch (series) current and node voltage magnitude
Defines relationship between branch (series) power flow, branch (series) current and node voltage magnitude
Storage Constraints
PowerModels.constraint_storage_thermal_limit
— Function.PowerModels.constraint_storage_current_limit
— Function.PowerModels.constraint_storage_complementarity
— Function.PowerModels.constraint_storage_loss
— Function.PowerModels.constraint_storage_state_initial
— Function.PowerModels.constraint_storage_state
— Function.DC Line Constraints
PowerModels.constraint_dcline
— Function.Creates Line Flow constraint for DC Lines (Matpower Formulation)
p_fr + p_to == loss0 + p_fr * loss1
PowerModels.constraint_active_dcline_setpoint
— Function.pf[i] == pf, pt[i] == pt