Skip to content

Commit

Permalink
Add tests from #332
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson committed Oct 28, 2019
1 parent 8687913 commit 3cc8626
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/problem_depot/problems/lp.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@add_problem lp function lp_abs_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
@add_problem lp function lp_dual_abs_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
x = Variable()
p = minimize(abs(x), x<=-1)
if test
Expand All @@ -19,6 +19,11 @@
if test
@test p.optval 2 atol=atol rtol=rtol
@test evaluate(sum(abs(x))) 2 atol=atol rtol=rtol
@test p.constraints[1].dual 1 atol=atol rtol=rtol
@test p.constraints[2].dual 1 atol=atol rtol=rtol
@test p.constraints[3].dual[1,1] 0 atol=atol rtol=rtol
@test p.constraints[3].dual[2,2] 0 atol=atol rtol=rtol
@test p.constraints[3].dual[1,2] p.constraints[3].dual[2,1] atol=atol rtol=rtol
end
end

Expand Down Expand Up @@ -207,7 +212,7 @@ end
# TODO: @davidlizeng. We should finish this someday.
end

@add_problem lp function lp_norm_inf_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
@add_problem lp function lp_dual_norm_inf_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
x = Variable(3)
p = minimize(norm_inf(x), [-2 <= x, x <= 1])
if test
Expand All @@ -217,10 +222,12 @@ end
if test
@test p.optval 0 atol=atol rtol=rtol
@test evaluate(norm_inf(x)) 0 atol=atol rtol=rtol
@test norm(p.constraints[1].dual) 0 atol=atol rtol=rtol
@test norm(p.constraints[2].dual) 0 atol=atol rtol=rtol
end
end

@add_problem lp function lp_norm_1_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
@add_problem lp function lp_dual_norm_1_atom(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
x = Variable(3)
p = minimize(norm_1(x), [-2 <= x, x <= 1])
if test
Expand All @@ -230,5 +237,7 @@ end
if test
@test p.optval 0 atol=atol rtol=rtol
@test evaluate(norm_1(x)) 0 atol=atol rtol=rtol
@test norm(p.constraints[1].dual) 0 atol=atol rtol=rtol
@test norm(p.constraints[2].dual) 0 atol=atol rtol=rtol
end
end
52 changes: 52 additions & 0 deletions src/problem_depot/problems/socp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,55 @@ end
@test o1 <= o2
end
end


@add_problem socp function socp_dual_minimal_norm_solutions(handle_problem!, ::Val{test}, atol, rtol, ::Type{T}) where {T, test}
x = Variable(2)
A = [1 2; 2 4];
b = [3, 6];
p = minimize(norm(x, 1), A*x==b)

if test
@test vexity(p) == ConvexVexity()
end

handle_problem!(p)
if test
@test p.optval 1.5 atol=atol rtol=rtol
@test evaluate(x) [0, 1.5] atol=atol rtol=rtol
@test evaluate(norm(x, 1)) p.optval atol=atol rtol=rtol
@test dot(b, p.constraints[1].dual) p.optval atol=atol rtol=rtol
end

x = Variable(2)
A = [1 2; 2 4];
b = [3, 6];
p = minimize(norm(x, 2), A*x==b)

test && @test vexity(p) == ConvexVexity()

handle_problem!(p)

if test
@test p.optval 3/sqrt(5) atol=atol rtol=rtol
@test evaluate(x) [3/5, 6/5] atol=atol rtol=rtol
@test evaluate(norm(x, 2)) p.optval atol=atol rtol=rtol
@test dot(b, p.constraints[1].dual) p.optval atol=atol rtol=rtol
end

x = Variable(2)
A = [1 2; 2 4];
b = [3, 6];
p = minimize(norm(x, Inf), A*x==b)

test && @test vexity(p) == ConvexVexity()

handle_problem!(p)

if test
@test p.optval 1.0 atol=atol rtol=rtol
@test evaluate(x) [1, 1] atol=atol rtol=rtol
@test evaluate(norm(x, Inf)) p.optval atol=atol rtol=rtol
@test dot(b, p.constraints[1].dual) p.optval atol=atol rtol=rtol
end
end
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ end
end

@testset "GLPK MIP" begin
run_tests(; exclude=[r"socp", r"sdp", r"exp"]) do p
run_tests(; exclude=[r"socp", r"sdp", r"exp", r"dual"]) do p
solve!(p, GLPKSolverMIP())
end
end
Expand Down

0 comments on commit 3cc8626

Please sign in to comment.