Skip to content

Commit

Permalink
Merge pull request #979 from JuliaOpt/ml/tidy
Browse files Browse the repository at this point in the history
fix ip_dual_solvers and relaxation test
  • Loading branch information
mlubin authored Feb 24, 2017
2 parents 316742a + 699b55b commit 5735b54
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 46 deletions.
93 changes: 50 additions & 43 deletions test/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -831,50 +831,57 @@ end
@test typeof(getvalue(x)) == Vector{Float64}
end

if length(ip_solvers) > 0
@testset "Relaxation keyword argument to solve with $solver" for solver in ip_dual_solvers
m = Model(solver=ip_solvers[1])
@variable(m, 1.5 <= y <= 2, Int)
@variable(m, z, Bin)
@variable(m, 0.5 <= w <= 1.5, Int)
@variable(m, 1 <= v <= 2)

@objective(m, Min, y + z + w + v)

@test solve(m, relaxation=true) == :Optimal
@test isapprox(getvalue(y), 1.5, atol=TOL)
@test isapprox(getvalue(z), 0, atol=TOL)
@test isapprox(getvalue(w), 0.5, atol=TOL)
@test isapprox(getvalue(v), 1, atol=TOL)
@test isapprox(getdual(y), 1, atol=TOL)
@test isapprox(getdual(z), 1, atol=TOL)
@test isapprox(getdual(w), 1, atol=TOL)
@test isapprox(getdual(v), 1, atol=TOL)
@test isapprox(getobjectivevalue(m), 1.5 + 0 + 0.5 + 1, atol=TOL)
@testset "Relaxation keyword argument to solve with $solver" for solver in ip_dual_solvers
m = Model(solver=solver)
@variable(m, 1.5 <= y <= 2, Int)
@variable(m, z, Bin)
@variable(m, 0.5 <= w <= 1.5, Int)
@variable(m, 1 <= v <= 2)

@test solve(m) == :Optimal
@test getvalue(y) == 2
@test getvalue(z) == 0
@test getvalue(w) == 1
@test getvalue(v) == 1
@test getobjectivevalue(m) == 2 + 0 + 1 + 1

@variable(m, 1 <= x <= 2, SemiCont)
@variable(m, -2 <= t <= -1, SemiInt)

addSOS1(m, [x, 2y, 3z, 4w, 5v, 6t])
@objective(m, Min, x + y + z + w + v - t)

@test solve(m, relaxation=true) == :Optimal

@test getvalue(x) == 0
@test getvalue(y) == 1.5
@test getvalue(z) == 0
@test getvalue(w) == 0.5
@test getvalue(v) == 1
@test getvalue(t) == 0
@test getobjectivevalue(m) == 0 + 1.5 + 0 + 0.5 + 1 + 0
end
@objective(m, Min, y + z + w + v)

@test solve(m, relaxation=true) == :Optimal
@test isapprox(getvalue(y), 1.5, atol=TOL)
@test isapprox(getvalue(z), 0, atol=TOL)
@test isapprox(getvalue(w), 0.5, atol=TOL)
@test isapprox(getvalue(v), 1, atol=TOL)
@test isapprox(getdual(y), 1, atol=TOL)
@test isapprox(getdual(z), 1, atol=TOL)
@test isapprox(getdual(w), 1, atol=TOL)
@test isapprox(getdual(v), 1, atol=TOL)
@test isapprox(getobjectivevalue(m), 1.5 + 0 + 0.5 + 1, atol=TOL)

@test solve(m) == :Optimal
@test getvalue(y) == 2
@test getvalue(z) == 0
@test getvalue(w) == 1
@test getvalue(v) == 1
@test getobjectivevalue(m) == 2 + 0 + 1 + 1
end

@testset "Relaxation keyword argument to solve (w/ SOS constraints) with $solver" for solver in sos_solvers
m = Model(solver=solver)
@variable(m, 1.5 <= y <= 2, Int)
@variable(m, z, Bin)
@variable(m, 0.5 <= w <= 1.5, Int)
@variable(m, 1 <= v <= 2)

@objective(m, Min, y + z + w + v)
@variable(m, 1 <= x <= 2, SemiCont)
@variable(m, -2 <= t <= -1, SemiInt)

addSOS1(m, [x, 2y, 3z, 4w, 5v, 6t])
@objective(m, Min, x + y + z + w + v - t)

@test solve(m, relaxation=true) == :Optimal

@test getvalue(x) == 0
@test getvalue(y) == 1.5
@test getvalue(z) == 0
@test getvalue(w) == 0.5
@test getvalue(v) == 1
@test getvalue(t) == 0
@test getobjectivevalue(m) == 0 + 1.5 + 0 + 0.5 + 1 + 0
end

@testset "Unrecognized keyword argument to solve" begin
Expand Down
6 changes: 3 additions & 3 deletions test/solvers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ glp && push!(ip_solvers, GLPKMathProgInterface.GLPKSolverMIP())
#osl && push!(ip_solvers, CoinOptServices.OsilSolver())
# IP solvers that give duals for relaxations
ip_dual_solvers = Any[]
grb && push!(ip_solvers, Gurobi.GurobiSolver(OutputFlag=0))
cpx && push!(ip_solvers, CPLEX.CplexSolver(CPX_PARAM_SCRIND=0))
mos && push!(ip_solvers, Mosek.MosekSolver(LOG=0))
grb && push!(ip_dual_solvers, Gurobi.GurobiSolver(OutputFlag=0))
cpx && push!(ip_dual_solvers, CPLEX.CplexSolver(CPX_PARAM_SCRIND=0))
mos && push!(ip_dual_solvers, Mosek.MosekSolver(LOG=0))
# Support semi-continuous, semi-integer solvers
semi_solvers = Any[]
grb && push!(semi_solvers, Gurobi.GurobiSolver(OutputFlag=0))
Expand Down

0 comments on commit 5735b54

Please sign in to comment.