Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more tests (in particular from MathProgBase) #73

Merged
merged 20 commits into from
Oct 24, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add many more tests from CSIP suite
  • Loading branch information
rschwarz committed Oct 24, 2018
commit a571b89e18eb0bdc52130b9a5e46ba9eb5f984e1
166 changes: 164 additions & 2 deletions test/csip_tests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Translation of tests from CSIP wrapper

solver = SCIPSolver("display/verblevel", 0)

@testset "LP" begin
s = SCIPSolver("display/verblevel", 0)
m = Model(solver=s)
m = Model(solver=solver)
@variable(m, x >= 0)
@variable(m, y >= 0)
@constraint(m, 2x + y <= 1.5)
Expand All @@ -14,3 +15,164 @@
@test getvalue(x) ≈ 0.75
@test getvalue(y) ≈ 0.0
end

@testset "MIP" begin
m = Model(solver=solver)
@variable(m, x[1:5], Bin)
@constraint(m, 2x[1] + 8x[2] + 4x[3] + 2x[4] + 5x[5] <= 10)
@objective(m, :Min, -5x[1] - 3x[2] - 2x[3] - 7x[4] - 4x[5])

status = solve(m)
@test status == :Optimal
@test getobjectivevalue(m) ≈ -16.0
@test getvalue(x) ≈ [1.0, 0.0, 0.0, 1.0, 1.0]
end

@testset "MIP2 (unbounded)" begin
m = Model(solver=solver)
@variable(m, x, Int)
@objective(m, :Min, x)

status = solve(m, suppress_warnings=true)
@test status == :Unbounded
end

@testset "MIP3 (infeasible)" begin
m = Model(solver=solver)
@variable(m, x, Int)
@constraint(m, x >= 2)
@constraint(m, x <= 1)

status = solve(m, suppress_warnings=true)
@test status == :Infeasible
end

@testset "SOCP" begin
m = Model(solver=solver)
@variable(m, x)
@variable(m, y)
@variable(m, t >= 0)
@constraint(m, x + y >= 1)
@constraint(m, x^2 + y^2 <= t^2)
@objective(m, :Min, t)

status = solve(m)
@test status == :Optimal
@test getobjectivevalue(m) ≈ sqrt(0.5) atol=1e-5
@test getvalue(t) ≈ sqrt(0.5) atol=1e-5
@test getvalue(x) ≈ 0.5 atol=1e-5
@test getvalue(y) ≈ 0.5 atol=1e-5
end

@testset "NLP" begin
m = Model(solver=solver)
@variable(m, x <= 0)
@variable(m, y <= 0)
@variable(m, z)
@NLconstraint(m, z^2 <= 1)
@NLobjective(m, :Max, x + y - z^3)

status = solve(m)
@test status == :Optimal
@test getobjectivevalue(m) ≈ 1.0 atol=1e-5
@test getvalue(x) ≈ 0.0 atol=1e-5
@test getvalue(y) ≈ 0.0 atol=1e-5
@test getvalue(z) ≈ -1.0 atol=1e-5
end

@testset "NLP (no objective)" begin
m = Model(solver=solver)
@variable(m, z)
@NLconstraint(m, z^2 <= 1)

status = solve(m)
@test status == :Optimal
@test getvalue(z)^2 <= 1.0 + 1e-5
end

@testset "quad obj" begin
m = Model(solver=solver)
@variable(m, x)
@variable(m, y)
@constraint(m, x + y >= 1)
@objective(m, :Min, x^2 + y^2)

status = solve(m)
@test status == :Optimal
@test getobjectivevalue(m) ≈ 0.5 atol=1e-5
@test getvalue(x) ≈ 0.5 atol=1e-5
@test getvalue(y) ≈ 0.5 atol=1e-5
end

@testset "lazy" begin
m = Model(solver=solver)
@variable(m, x <= 2)
@variable(m, y <= 2)
@objective(m, :Max, 0.5x + y)

function lazycb(cb)
if getvalue(x) + getvalue(y) > 3.0
@lazyconstraint(cb, x + y <= 3)
end
end
addlazycallback(m, lazycb)

status = solve(m)
@test status == :Optimal
@test getobjectivevalue(m) ≈ 2.5 atol=1e-5
@test getvalue(x) ≈ 1.0 atol=1e-5
@test getvalue(y) ≈ 2.0 atol=1e-5
end

@testset "lazy2 (integer)" begin
m = Model(solver=solver)
@variable(m, x <= 100.5, Int)
@objective(m, :Min, -x)

function lazycb(cb)
if getvalue(x) > 10.5
@lazyconstraint(cb, x <= 10.5)
end
end
addlazycallback(m, lazycb)

status = solve(m)
@test status == :Optimal
@test getobjectivevalue(m) ≈ -10.0 atol=1e-5
@test getvalue(x) ≈ 10.0 atol=1e-5
end

@testset "lazy interrupt" begin
m = Model(solver=solver)
@variable(m, x >= 1.5, Int)

function lazycb(cb)
return JuMP.StopTheSolver
end
addlazycallback(m, lazycb)

status = solve(m)
@test status == :UserLimit
end

@testset "obj sense" begin
m = Model(solver=solver)
@variable(m, -2.3 <= x <= 4.2)
@objective(m, :Min, x)

status = solve(m)
@test status == :Optimal
@test getvalue(x) ≈ -2.3

# change sense and resolve
setobjectivesense(m, :Max)
status = solve(m)
@test status == :Optimal
@test getvalue(x) ≈ 4.2

# change sense and resolve
setobjectivesense(m, :Min)
status = solve(m)
@test status == :Optimal
@test getvalue(x) ≈ -2.3
end