Skip to content

Commit

Permalink
power flow models seem to be working
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoffrin committed Aug 17, 2016
1 parent b36b17c commit eed96d2
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 476 deletions.
2 changes: 1 addition & 1 deletion src/PowerModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ include("form/dcp.jl")
include("form/wr.jl")
include("form/wrm.jl")

include("prob/pf.jl")
include("prob/opf.jl")
#include("prob/ots.jl")
#include("prob/pf.jl")
#include("prob/misc.jl")

end
21 changes: 12 additions & 9 deletions src/core/constraint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ function constraint_thermal_limit_to{T <: AbstractConicPowerFormulation}(pm::Gen
end


function constraint_active_gen_setpoint{T}(pm::GenericPowerModel{T}, gen)
i = gen["index"]
pg = getvariable(pm.model, :pg)[gen["index"]]
@constraint(pm.model, pg == gen["pg"])
end

function constraint_reactive_gen_setpoint{T}(pm::GenericPowerModel{T}, gen)
i = gen["index"]
qg = getvariable(pm.model, :qg)[gen["index"]]
@constraint(pm.model, qg == gen["qg"])
end




Expand Down Expand Up @@ -139,15 +151,6 @@ function constraint_reactive_gen_setpoint(m, qg, gen)
@constraint(m, qg == gen["qg"])
end
function constraint_voltage_magnitude_setpoint(m, v, bus; epsilon = 0.0)
if epsilon == 0.0
@constraint(m, v == bus["vm"])
else
@assert epsilon > 0.0
@constraint(m, v <= bus["vm"] + epsilon)
@constraint(m, v >= bus["vm"] - epsilon)
end
end
function constraint_voltage_magnitude_setpoint_w(m, w, bus)
@constraint(m, w == bus["vm"]^2)
Expand Down
37 changes: 37 additions & 0 deletions src/form/acp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,49 @@ function init_vars(pm::ACPPowerModel)
reactive_line_flow_variables(pm)
end

function free_bounded_variables{T <: AbstractACPForm}(pm::GenericPowerModel{T})
for (i,bus) in pm.set.buses
v = getvariable(pm.model, :v)[i]
setupperbound(v, Inf)
setlowerbound(v, 0)
end
for (i,gen) in pm.set.gens
pg = getvariable(pm.model, :pg)[i]
setupperbound(pg, Inf)
setlowerbound(pg, -Inf)
qg = getvariable(pm.model, :pg)[i]
setupperbound(pg, Inf)
setlowerbound(pg, -Inf)
end
for arc in pm.set.arcs
p = getvariable(pm.model, :p)[arc]
setupperbound(p, Inf)
setlowerbound(p, -Inf)
q = getvariable(pm.model, :p)[arc]
setupperbound(q, Inf)
setlowerbound(q, -Inf)
end
end


function constraint_theta_ref(pm::ACPPowerModel)
@constraint(pm.model, getvariable(pm.model, :t)[pm.set.ref_bus] == 0)
end

function constraint_voltage_magnitude_setpoint{T <: AbstractACPForm}(pm::GenericPowerModel{T}, bus; epsilon = 0.0)
i = bus["index"]
v = getvariable(pm.model, :v)[i]

if epsilon == 0.0
@constraint(pm.model, v == bus["vm"])
else
@assert epsilon > 0.0
@constraint(pm.model, v <= bus["vm"] + epsilon)
@constraint(pm.model, v >= bus["vm"] - epsilon)
end
end


function constraint_active_kcl_shunt(pm::ACPPowerModel, bus)
i = bus["index"]
bus_branches = pm.set.bus_branches[i]
Expand Down
21 changes: 21 additions & 0 deletions src/form/dcp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,33 @@ function init_vars(pm::DCPPowerModel)
pm.model.ext[:p_expr] = p_expr
end

function free_bounded_variables{T <: AbstractDCPForm}(pm::GenericPowerModel{T})
for (i,gen) in pm.set.gens
pg = getvariable(pm.model, :pg)[i]
setupperbound(pg, Inf)
setlowerbound(pg, -Inf)
end
for arc in pm.set.arcs_from
p = getvariable(pm.model, :p)[arc]
setupperbound(p, Inf)
setlowerbound(p, -Inf)
end
end


function constraint_theta_ref(pm::DCPPowerModel)
@constraint(pm.model, getvariable(pm.model, :t)[pm.set.ref_bus] == 0)
end

function constraint_voltage_magnitude_setpoint{T <: AbstractDCPForm}(pm::GenericPowerModel{T}, bus; epsilon = 0.0)
# Do nothing, this model does not have voltage variables
end

function constraint_reactive_gen_setpoint{T}(pm::GenericPowerModel{T}, gen)
# Do nothing, this model does not have reactive variables
end


#constraint_active_kcl_shunt_const(pm.model, pm.var.p, pm.var.pg, bus, bus_branches, pm.set.bus_gens[i])
function constraint_active_kcl_shunt(pm::DCPPowerModel, bus)
i = bus["index"]
Expand Down
46 changes: 46 additions & 0 deletions src/form/wr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@ function init_vars{T <: AbstractWRForm}(pm::GenericPowerModel{T})
reactive_line_flow_variables(pm)
end

function free_bounded_variables{T <: AbstractWRForm}(pm::GenericPowerModel{T})
for (i,bus) in pm.set.buses
w = getvariable(pm.model, :w)[i]
setupperbound(w, Inf)
setlowerbound(w, 0)
end
for (i,j) in pm.set.buspair_indexes
wr = getvariable(pm.model, :wr)[(i,j)]
setupperbound(wr, Inf)
setlowerbound(wr, -Inf)
wi = getvariable(pm.model, :wi)[(i,j)]
setupperbound(wi, Inf)
setlowerbound(wi, -Inf)
end
for (i,gen) in pm.set.gens
pg = getvariable(pm.model, :pg)[i]
setupperbound(pg, Inf)
setlowerbound(pg, -Inf)
qg = getvariable(pm.model, :pg)[i]
setupperbound(pg, Inf)
setlowerbound(pg, -Inf)
end
for arc in pm.set.arcs
p = getvariable(pm.model, :p)[arc]
setupperbound(p, Inf)
setlowerbound(p, -Inf)
q = getvariable(pm.model, :p)[arc]
setupperbound(q, Inf)
setlowerbound(q, -Inf)
end
end

function constraint_universal(pm::SOCWRPowerModel)
w = getvariable(pm.model, :w)
wr = getvariable(pm.model, :wr)
Expand All @@ -33,10 +65,24 @@ function constraint_universal(pm::SOCWRPowerModel)
end
end


function constraint_theta_ref{T <: AbstractWRForm}(pm::GenericPowerModel{T})
# Do nothing, no way to represent this in these variables
end

function constraint_voltage_magnitude_setpoint{T <: AbstractWRForm}(pm::GenericPowerModel{T}, bus; epsilon = 0.0)
i = bus["index"]
w = getvariable(pm.model, :w)[i]

if epsilon == 0.0
@constraint(pm.model, w == bus["vm"]^2)
else
@assert epsilon > 0.0
@constraint(pm.model, w <= bus["vm"]^2 + epsilon)
@constraint(pm.model, w >= bus["vm"]^2 - epsilon)
end
end

function constraint_active_kcl_shunt{T <: AbstractWRForm}(pm::GenericPowerModel{T}, bus)
i = bus["index"]
bus_branches = pm.set.bus_branches[i]
Expand Down
Loading

0 comments on commit eed96d2

Please sign in to comment.