Skip to content

Commit

Permalink
Adding juniper for ac minlp tests (#201)
Browse files Browse the repository at this point in the history
* adding juniper for ac minlp tests
* updating check_branch_status to use isapprox
* updating check_tnep_status to use isapprox
* removing 5-bus case ac tnep case
  • Loading branch information
ccoffrin authored Apr 17, 2018
1 parent 8ee7f0d commit abcf698
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 52 deletions.
3 changes: 2 additions & 1 deletion src/core/solution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,10 @@ end

solver_status_lookup = Dict{Any, Dict{Symbol, Symbol}}(
:Ipopt => Dict(:Optimal => :LocalOptimal, :Infeasible => :LocalInfeasible),
:Juniper => Dict(:Optimal => :LocalOptimal, :Infeasible => :LocalInfeasible),
:ConicNonlinearBridge => Dict(:Optimal => :LocalOptimal, :Infeasible => :LocalInfeasible),
# note that AmplNLWriter.AmplNLSolver is the solver type of bonmin
:AmplNLWriter => Dict(:Optimal => :LocalOptimal, :Infeasible => :LocalInfeasible)
:AmplNLWriter => Dict(:Optimal => :LocalOptimal, :Infeasible => :LocalInfeasible),
)

"translates solver status codes to our status codes"
Expand Down
2 changes: 1 addition & 1 deletion src/form/acp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function constraint_ohms_yt_to_ne(pm::GenericPowerModel{T}, n::Int, i, f_bus, t_
end

"`angmin <= branch_z[i]*(t[f_bus] - t[t_bus]) <= angmax`"
function constraint_voltage_angle_difference_on_off(pm::GenericPowerModel{T}, n::Int, arc_from, f_bus, t_bus, angmin, angmax, vad_min, vad_max) where T <: AbstractACPForm
function constraint_voltage_angle_difference_on_off(pm::GenericPowerModel{T}, n::Int, i, f_bus, t_bus, angmin, angmax, vad_min, vad_max) where T <: AbstractACPForm
va_fr = pm.var[:nw][n][:va][f_bus]
va_to = pm.var[:nw][n][:va][t_bus]
z = pm.var[:nw][n][:branch_z][i]
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ julia 0.6
Ipopt
SCS
GLPKMathProgInterface
Juniper 0.2.0
Pajarito 0.4.0
49 changes: 23 additions & 26 deletions test/ots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,39 @@
# used by OTS models
function check_br_status(sol)
for (i,branch) in sol["branch"]
@test branch["br_status"] == 0.0 || branch["br_status"] == 1.0
@test isapprox(branch["br_status"], 0.0, rtol=1e-6) || isapprox(branch["br_status"], 1.0, rtol=1e-6)
end
end


if (Pkg.installed("AmplNLWriter") != nothing && Pkg.installed("CoinOptServices") != nothing)
@testset "test ac ots" begin
#Omitting this test, until bugs can be resolved, bonmin does not report a integral solution
#@testset "3-bus case" begin
# result = run_ots("../test/data/matpower/case3.m", ACPPowerModel, BonminNLSolver(["bonmin.bb_log_level=0", "bonmin.nlp_log_level=0"]))
@testset "test ac ots" begin
@testset "3-bus case" begin
result = run_ots("../test/data/matpower/case3.m", ACPPowerModel, juniper_solver)

# check_br_status(result["solution"])
check_br_status(result["solution"])

# @test result["status"] == :LocalOptimal
# @test isapprox(result["objective"], 5812; atol = 1e0)
#end
@testset "5-bus case" begin
result = run_ots("../test/data/matpower/case5.m", ACPPowerModel, BonminNLSolver(["bonmin.bb_log_level=0", "bonmin.nlp_log_level=0"]))
@test result["status"] == :LocalOptimal
#@test isapprox(result["objective"], 5812; atol = 1e0) # true opt objective
@test isapprox(result["objective"], 5906.8; atol = 1e0)
end
@testset "5-bus case" begin
result = run_ots("../test/data/matpower/case5.m", ACPPowerModel, juniper_solver)

check_br_status(result["solution"])
check_br_status(result["solution"])

@test result["status"] == :LocalOptimal
# NOTE this objective value is out of date, and this test will not pass
@test isapprox(result["objective"], 15174; atol = 1e0)
end
#Omitting this test, returns local infeasible
#@testset "6-bus case" begin
# result = run_ots("../test/data/matpower/case6.m", ACPPowerModel, BonminNLSolver(["bonmin.bb_log_level=0", "bonmin.nlp_log_level=0"]))
@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 15174; atol = 1e0)
end
#Omitting this test, returns local infeasible
#@testset "6-bus case" begin
# result = run_ots("../test/data/matpower/case6.m", ACPPowerModel, juniper_solver)

# check_br_status(result["solution"])
# check_br_status(result["solution"])

# @test result["status"] == :LocalOptimal
# println(result["objective"])
# @test isapprox(result["objective"], 15174; atol = 1e0)
#end
end
# @test result["status"] == :LocalOptimal
# println(result["objective"])
# @test isapprox(result["objective"], 15174; atol = 1e0)
#end
end


Expand Down
12 changes: 5 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ setlevel!(getlogger(PowerModels), "error")

using Ipopt
using Pajarito
using Juniper
using GLPKMathProgInterface
using SCS

# needed for Non-convex OTS tests
if (Pkg.installed("AmplNLWriter") != nothing && Pkg.installed("CoinOptServices") != nothing)
using AmplNLWriter
using CoinOptServices
end

using Base.Test

# default setup for solvers
ipopt_solver = IpoptSolver(tol=1e-6, print_level=0)
pajarito_solver = PajaritoSolver(mip_solver=GLPKSolverMIP(), cont_solver=ipopt_solver, log_level=0)
glpk_solver = GLPKSolverMIP()
juniper_solver = JuniperSolver(IpoptSolver(tol=1e-4, print_level=0), mip_solver=glpk_solver, log_levels=[])
#juniper_solver = JuniperSolver(IpoptSolver(tol=1e-4, print_level=0), mip_solver=glpk_solver)
pajarito_solver = PajaritoSolver(mip_solver=glpk_solver, cont_solver=ipopt_solver, log_level=0)
scs_solver = SCSSolver(max_iters=1000000, verbose=0)


Expand Down
39 changes: 22 additions & 17 deletions test/tnep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@

function check_tnep_status(sol)
for (idx,val) in sol["ne_branch"]
@test val["built"] == 0.0 || val["built"] == 1.0
@test isapprox(val["built"], 0.0, rtol=1e-6) || isapprox(val["built"], 1.0, rtol=1e-6)
end
end


@testset "test ac tnep" begin
@testset "3-bus case" begin
result = run_tnep("../test/data/matpower/case3_tnep.m", ACPPowerModel, juniper_solver)

check_tnep_status(result["solution"])

@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 2; atol = 1e-2)
end
# omitting due to numerical stability issues on Linux
#@testset "5-bus case" begin
# result = run_tnep("../test/data/matpower/case5_tnep.m", ACPPowerModel, juniper_solver)

# check_tnep_status(result["solution"])

# @test result["status"] == :LocalOptimal
# @test isapprox(result["objective"], 1; atol = 1e-2)
#end
end


@testset "test soc tnep" begin
@testset "3-bus case" begin
result = run_tnep("../test/data/matpower/case3_tnep.m", SOCWRPowerModel, pajarito_solver; setting = Dict("output" => Dict("branch_flows" => true)))
Expand Down Expand Up @@ -70,22 +91,6 @@ end
end


if (Pkg.installed("AmplNLWriter") != nothing && Pkg.installed("CoinOptServices") != nothing)

@testset "test ac tnep" begin
@testset "5-bus case" begin
result = run_tnep("../test/data/matpower/case5_tnep.m", ACPPowerModel, BonminNLSolver(["bonmin.bb_log_level=0", "bonmin.nlp_log_level=0"]))

check_tnep_status(result["solution"])

@test result["status"] == :LocalOptimal
@test isapprox(result["objective"], 1; atol = 1e-2)
end
end

end


@testset "test tnep branch flow output" begin
@testset "3-bus case" begin
result = run_tnep("../test/data/matpower/case3_tnep.m", SOCWRPowerModel, pajarito_solver; setting = Dict("output" => Dict("branch_flows" => true)))
Expand Down

0 comments on commit abcf698

Please sign in to comment.