Skip to content

Commit

Permalink
Add test for conic subsolver (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Mar 1, 2022
1 parent 44769d0 commit e6531e4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ JSON = "~0.18, ~0.19, ~0.20, ~0.21"
JuMP = "0.23"
MathOptInterface = "1"
MutableArithmetics = "1"
SCS = "1"
julia = "1.6"

[extras]
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
SCS = "c946c3f1-0d1f-5ce8-9dea-7daa1f7e2d13"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "GLPK", "HiGHS", "Ipopt", "JuMP"]
test = ["GLPK", "HiGHS", "Ipopt", "JuMP", "SCS", "Test"]
46 changes: 46 additions & 0 deletions test/conic.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module TestConicModels

using Test
using JuMP

import Juniper
import SCS

function runtests()
for name in names(@__MODULE__; all = true)
if startswith("$(name)", "test_")
@testset "$(name)" begin
getfield(@__MODULE__, name)()
end
end
end
return
end

function test_simple_conic_model()
model = Model(
optimizer_with_attributes(
Juniper.Optimizer,
"nl_solver" => optimizer_with_attributes(
SCS.Optimizer,
MOI.Silent() => true,
),
"atol" => 1e-4,
),
)
@variable(model, 0 <= x[1:2] <= 10, Int)
@objective(model, Max, 3x[1] + 5x[2])
@constraint(model, [10, x[1], x[2]] in SecondOrderCone())
optimize!(model)
@test termination_status(model) == LOCALLY_SOLVED
@test primal_status(model) == FEASIBLE_POINT
@test dual_status(model) == FEASIBLE_POINT
@test isapprox(value.(x), [6, 8]; atol = 1e-4)
@test sqrt(value(x[1])^2 + value(x[2])^2) <= 10 + 1e-4
@test isapprox(objective_value(model), 58; atol = 1e-5)
return
end

end

TestConicModels.runtests()
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@ start = time()
include("fpump.jl")
include("pod.jl")
include("MOI_wrapper.jl")
include("conic.jl")
end
println("Time for all tests: ", time() - start)

0 comments on commit e6531e4

Please sign in to comment.