Skip to content

Commit

Permalink
revive NLP+quadratic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed Apr 15, 2018
1 parent 9c091fc commit 7bc291d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
44 changes: 44 additions & 0 deletions test/nlp_solver.jl
Expand Up @@ -441,4 +441,48 @@ new_optimizer() = IpoptOptimizer(print_level=0)
test_result()
@test JuMP.objectivevalue(m) 5.8446115 atol=1e-6
end

@testset "Quadratic inequality constraints, linear objective" begin
m = Model(optimizer=new_optimizer())
@variable(m, -2 <= x <= 2)
@variable(m, -2 <= y <= 2)
@objective(m, Min, x - y)
@constraint(m, x + x^2 + x*y + y^2 <= 1)
JuMP.optimize(m)

@test JuMP.hasresultvalues(m)
@test JuMP.terminationstatus(m) == MOI.Success
@test JuMP.primalstatus(m) == MOI.FeasiblePoint
@test JuMP.objectivevalue(m) -1-4/sqrt(3) atol=1e-6
@test JuMP.resultvalue(x) + JuMP.resultvalue(y) -1/3 atol=1e-3
end

@testset "Quadratic inequality constraints, NL objective" begin
m = Model(optimizer=new_optimizer())
@variable(m, -2 <= x <= 2)
@variable(m, -2 <= y <= 2)
@NLobjective(m, Min, x - y)
@constraint(m, x + x^2 + x*y + y^2 <= 1)
JuMP.optimize(m)

@test JuMP.hasresultvalues(m)
@test JuMP.terminationstatus(m) == MOI.Success
@test JuMP.primalstatus(m) == MOI.FeasiblePoint
@test JuMP.objectivevalue(m) -1-4/sqrt(3) atol=1e-6
@test JuMP.resultvalue(x) + JuMP.resultvalue(y) -1/3 atol=1e-3
end

@testset "Quadratic equality constraints" begin
m = Model(optimizer=new_optimizer())
@variable(m, 0 <= x[1:2] <= 1)
@constraint(m, x[1]^2 + x[2]^2 == 1/2)
@NLobjective(m, Max, x[1] - x[2])
JuMP.optimize(m)

@test JuMP.hasresultvalues(m)
@test JuMP.terminationstatus(m) == MOI.Success
@test JuMP.primalstatus(m) == MOI.FeasiblePoint
@test JuMP.objectivevalue(m) sqrt(1/2) atol=1e-6
@test JuMP.resultvalue.(x) [sqrt(1/2), 0] atol=1e-6
end
end
26 changes: 0 additions & 26 deletions test/old/nonlinear.jl
Expand Up @@ -116,21 +116,6 @@ end
end


@testset "Quad con solve through NL pathway" for nlp_solver in convex_nlp_solvers
# Solve a problem with linear objective with quadratic
# constraints, but force it to use the nonlinear code.
m = Model(solver=nlp_solver)
@variable(m, -2 <= x <= 2)
@variable(m, -2 <= y <= 2)
@NLobjective(m, Min, x - y)
@constraint(m, x + x^2 + x*y + y^2 <= 1)
status = solve(m)

@test status == :Optimal
@test isapprox(getobjectivevalue(m), -1-4/sqrt(3), atol=1e-6)
@test isapprox(getvalue(x) + getvalue(y), -1/3, atol=1e-3)
end

@testset "Resolve with parameter with $nlp_solver (simplify = $simplify)" for nlp_solver in convex_nlp_solvers, simplify in [true,false]
m = Model(solver=nlp_solver, simplify_nonlinear_expressions=simplify)
@variable(m, z)
Expand All @@ -146,17 +131,6 @@ end
@test isapprox(getvalue(z), 5.0, atol=1e-3)
end

@testset "Quadratic equality constraints with $nlp_solver" for nlp_solver in nlp_solvers
m = Model(solver=nlp_solver)
@variable(m, 0 <= x[1:2] <= 1)
@constraint(m, x[1]^2 + x[2]^2 == 1/2)
@NLobjective(m, Max, x[1] - x[2])
status = solve(m)

@test status == :Optimal
@test isapprox(getvalue(x), [sqrt(1/2), 0], atol=1e-6)
end

if ipt
@testset "Passing starting solutions through QP pathway with Ipopt" begin
# https://discourse.julialang.org/t/create-quadratic-objective-will-objective-and-nlobjective-lead-to-different-solution-using-ipopt/1666
Expand Down

0 comments on commit 7bc291d

Please sign in to comment.