Constraints

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.

Generator Constraints

source

pg[i] == pg

source
source

qq[i] == qq

source

do nothing, this model does not have reactive variables

source

Bus Constraints

Setpoint Constraints

source

t[ref_bus] == 0

source
source

Do nothing, no way to represent this in these variables

source

t[ref_bus] == 0

source

Do nothing, no way to represent this in these variables

source
source

vm - epsilon <= v[i] <= vm + epsilon

source

do nothing, this model does not have voltage variables

source

KCL Constraints

source
sum(p[a] for a in bus_arcs) == sum(pg[g] for g in bus_gens) - pd - gs*v^2
sum(q[a] for a in bus_arcs) == sum(qg[g] for g in bus_gens) - qd + bs*v^2
source
source

sum(p[a] for a in bus_arcs) == sum(pg[g] for g in bus_gens) - pd - gs*1.0^2

source
source
source
source
sum(p[a] for a in bus_arcs) + sum(p_ne[a] for a in bus_arcs_ne) == sum(pg[g] for g in bus_gens) - pd - gs*v^2
sum(q[a] for a in bus_arcs) + sum(q_ne[a] for a in bus_arcs_ne) == sum(qg[g] for g in bus_gens) - qd + bs*v^2
source
source

sum(p[a] for a in bus_arcs) + sum(p_ne[a] for a in bus_arcs_ne) == sum(pg[g] for g in bus_gens) - pd - gs*1.0^2

source
sum(p[a] for a in bus_arcs) + sum(p_ne[a] for a in bus_arcs_ne) == sum(pg[g] for g in bus_gens) - pd - gs*w[i]
sum(q[a] for a in bus_arcs) + sum(q_ne[a] for a in bus_arcs_ne) == sum(qg[g] for g in bus_gens) - qd + bs*w[i]
source

Branch Constraints

Ohm's Law Constraints

source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

p[f_idx] == 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] == -(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]))
source

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])
source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

p[f_idx] == g/tm*w[f_bus] + (-g*tr+b*ti)/tm*(wr[f_bus,t_bus]) + (-b*tr-g*ti)/tm*(wi[f_bus,t_bus])
q[f_idx] == -(b+c/2)/tm*w[f_bus] - (-b*tr-g*ti)/tm*(wr[f_bus,t_bus]) + (-g*tr+b*ti)/tm*(wi[f_bus,t_bus])
source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

source
source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

p[t_idx] == 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] == -(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]))
source

Do nothing, this model is symmetric

source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

p[t_idx] == g*w[t_bus] + (-g*tr-b*ti)/tm*(wr[f_bus,t_bus]) + (-b*tr+g*ti)/tm*(-wi[f_bus,t_bus])
q[t_idx] == -(b+c/2)*w[t_bus] - (-b*tr+g*ti)/tm*(wr[f_bus,t_bus]) + (-g*tr-b*ti)/tm*(-wi[f_bus,t_bus])
source
source
source

Creates Ohms constraints for AC models (y post fix indicates that Y values are in rectangular form)

p[f_idx] == g*(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+c/2)*(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)
source
source

Creates Ohms constraints for AC models (y post fix indicates that Y values are in rectangular form)

p[t_idx] == g*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+c/2)*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)
source

On/Off Ohm's Law Constraints

source
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])))
source

-b*(t[f_bus] - t[t_bus] + t_min*(1-line_z[i])) <= p[f_idx] <= -b*(t[f_bus] - t[t_bus] + t_max*(1-line_z[i]))

source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

-b*(t[f_bus] - t[t_bus] + t_min*(1-line_z[i])) <= p[f_idx] <= -b*(t[f_bus] - t[t_bus] + t_max*(1-line_z[i]))
source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

p[f_idx] ==        g/tm*w_from[i] + (-g*tr+b*ti)/tm*(wr[i]) + (-b*tr-g*ti)/tm*(wi[i])
q[f_idx] == -(b+c/2)/tm*w_from[i] - (-b*tr-g*ti)/tm*(wr[i]) + (-g*tr+b*ti)/tm*(wi[i])
source
source
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])))
source

Do nothing, this model is symmetric

source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

p[f_idx] + p[t_idx] >= r*( (-b*(t[f_bus] - t[t_bus]))^2 - (-b*(t_m))^2*(1-line_z[i]) )

where r = g/(g^2 + b^2) and t_m = max(|t_min|, |t_max|)

source

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])
source
source
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])))
source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

-b*(t[f_bus] - t[t_bus] + t_min*(1-line_ne[i])) <= p_ne[f_idx] <= -b*(t[f_bus] - t[t_bus] + t_max*(1-line_ne[i]))
source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

p[f_idx] == g/tm*w_from_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_from_ne[i] - (-b*tr-g*ti)/tm*(wr_ne[i]) + (-g*tr+b*ti)/tm*(wi_ne[i])
source
source
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])))
source

Do nothing, this model is symmetric

source

Creates Ohms constraints (yt post fix indicates that Y and T values are in rectangular form)

p_ne[f_idx] + p_ne[t_idx] >= r*( (-b*(t[f_bus] - t[t_bus]))^2 - (-b*(t_m))^2*(1-line_ne[i]) )

where r = g/(g^2 + b^2) and t_m = max(|t_min|, |t_max|)

source

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])
source

Current

source

p[f_idx]^2 + q[f_idx]^2 <= w[f_bus]/tm*cm[f_bus,t_bus]

source
source

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]

source

Thermal Limit Constraints

source

p[f_idx]^2 + q[f_idx]^2 <= rate_a^2

source

norm([p[f_idx]; q[f_idx]]) <= rate_a

source

-rate_a <= p[f_idx] <= rate_a

source
source

p[t_idx]^2 + q[t_idx]^2 <= rate_a^2

source

norm([p[t_idx]; q[t_idx]]) <= rate_a

source

Do nothing, this model is symmetric

source
source

p[f_idx]^2 + q[f_idx]^2 <= (rate_a * line_z[i])^2

source

Generic on/off thermal limit constraint

-rate_a*line_z[i] <= p[f_idx] <=  rate_a*line_z[i]
source
source

p[t_idx]^2 + q[t_idx]^2 <= (rate_a * line_z[i])^2

source

nothing to do, from handles both sides

source

-rate_a*line_z[i] <= p[t_idx] <= rate_a*line_z[i]

source
source

p_ne[f_idx]^2 + q_ne[f_idx]^2 <= (rate_a * line_ne[i])^2

source

Generic on/off thermal limit constraint

-rate_a*line_ne[i] <= p_ne[f_idx] <=  rate_a*line_ne[i]
source
source

p_ne[t_idx]^2 + q_ne[t_idx]^2 <= (rate_a * line_ne[i])^2

source

nothing to do, from handles both sides

source

-rate_a*line_ne[i] <= p_ne[t_idx] <= rate_a*line_ne[i]

source

Phase Angle Difference Constraints

source
t[f_bus] - t[t_bus] <= angmax
t[f_bus] - t[t_bus] >= angmin
source

angmin <= t[f_bus] - t[t_bus] <= angmax

source
source
source
source
source

angmin <= line_z[i]*(t[f_bus] - t[t_bus]) <= angmax

source

angmin*line_z[i] + t_min*(1-line_z[i]) <= t[f_bus] - t[t_bus] <= angmax*line_z[i] + t_max*(1-line_z[i])

source

angmin*wr[i] <= wi[i] <= angmax*wr[i]

source
source

angmin <= line_ne[i]*(t[f_bus] - t[t_bus]) <= angmax

source

angmin*line_ne[i] + t_min*(1-line_ne[i]) <= t[f_bus] - t[t_bus] <= angmax*line_ne[i] + t_max*(1-line_ne[i])

source

angmin*wr_ne[i] <= wi_ne[i] <= angmax*wr_ne[i]

source

Loss Constraints

source
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)
source

Commonly Used Constraints

The following methods generally assume that the model contains p and q values for branches line flows and bus flow conservation.

Generic thermal limit constraint

constraint_thermal_limit_from(pm::GenericPowerModel, f_idx, rate_a)
constraint_thermal_limit_to(pm::GenericPowerModel, t_idx, rate_a)

Generic on/off thermal limit constraint

constraint_thermal_limit_from_on_off(pm::GenericPowerModel, i, f_idx, rate_a)
constraint_thermal_limit_to_on_off(pm::GenericPowerModel, i, t_idx, rate_a)
constraint_thermal_limit_from_ne(pm::GenericPowerModel, i, f_idx, rate_a)
constraint_thermal_limit_to_ne(pm::GenericPowerModel, i, t_idx, rate_a)
constraint_active_gen_setpoint(pm::GenericPowerModel, i, pg)
constraint_reactive_gen_setpoint(pm::GenericPowerModel, i, qg)