diff --git a/test/conicinterface.jl b/test/conicinterface.jl index fa5d50b..a89cb5d 100644 --- a/test/conicinterface.jl +++ b/test/conicinterface.jl @@ -26,17 +26,17 @@ function coniclineartest(solver::MathProgBase.AbstractMathProgSolver;duals=false MathProgBase.loadproblem!(m, c, A, b, [(:Zero,1:2)], [(:NonNeg, 1:3)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -11 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 0.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 2.0 tol + @test isapprox(MathProgBase.getobjval(m), -11, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 0.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 2.0, atol=tol) if duals d = MathProgBase.getdual(m) - @test_approx_eq_eps d[1] 3.0 tol - @test_approx_eq_eps d[2] 1.0 tol + @test isapprox(d[1], 3.0, atol=tol) + @test isapprox(d[2], 1.0, atol=tol) vardual = c + A'd var = MathProgBase.getvardual(m) - @test_approx_eq_eps vardual var tol + @test isapprox(vardual, var, atol=tol) end # Problem LIN1A - same as Problem LIN1, but with variable bounds @@ -62,20 +62,20 @@ function coniclineartest(solver::MathProgBase.AbstractMathProgSolver;duals=false [(:Free, 1:3)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -11 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 0.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 2.0 tol + @test isapprox(MathProgBase.getobjval(m), -11, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 0.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 2.0, atol=tol) if duals d = MathProgBase.getdual(m) - @test_approx_eq_eps d[1] 3.0 tol - @test_approx_eq_eps d[2] 1.0 tol - @test_approx_eq_eps d[3] 0.0 tol - @test_approx_eq_eps d[4] -2.0 tol - @test_approx_eq_eps d[5] 0.0 tol + @test isapprox(d[1], 3.0, atol=tol) + @test isapprox(d[2], 1.0, atol=tol) + @test isapprox(d[3], 0.0, atol=tol) + @test isapprox(d[4], -2.0, atol=tol) + @test isapprox(d[5], 0.0, atol=tol) vardual = c + A'd var = MathProgBase.getvardual(m) - @test_approx_eq_eps vardual var tol + @test isapprox(vardual, var, atol=tol) end # Problem LIN2 - mixed free, nonneg, nonpos, zero, shuffled cones @@ -101,16 +101,16 @@ function coniclineartest(solver::MathProgBase.AbstractMathProgSolver;duals=false [(:Free,1), (:NonNeg,3), (:Zero,4), (:NonPos,2)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -82 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] -4.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] -3.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 16.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[4] 0.0 tol + @test isapprox(MathProgBase.getobjval(m), -82, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], -4.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], -3.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 16.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[4], 0.0, atol=tol) if duals d = MathProgBase.getdual(m) - @test_approx_eq_eps d[1] -7.0 tol - @test_approx_eq_eps d[2] -2.0 tol - @test_approx_eq_eps d[3] 4.0 tol + @test isapprox(d[1], -7.0, atol=tol) + @test isapprox(d[2], -2.0, atol=tol) + @test isapprox(d[3], 4.0, atol=tol) end # Problem LIN2A - Problem LIN2 but with y,z variable bounds as constraints @@ -138,18 +138,18 @@ function coniclineartest(solver::MathProgBase.AbstractMathProgSolver;duals=false [(:Free,1), (:NonNeg,3), (:Zero,4), (:NonPos,2)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -82 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] -4.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] -3.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 16.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[4] 0.0 tol + @test isapprox(MathProgBase.getobjval(m), -82, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], -4.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], -3.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 16.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[4], 0.0, atol=tol) if duals d = MathProgBase.getdual(m) - @test_approx_eq_eps d[1] -7.0 tol - @test_approx_eq_eps d[2] -2.0 tol - @test_approx_eq_eps d[3] 4.0 tol - @test_approx_eq_eps d[4] 0.0 tol - @test_approx_eq_eps d[5] 0.0 tol + @test isapprox(d[1], -7.0, atol=tol) + @test isapprox(d[2], -2.0, atol=tol) + @test isapprox(d[3], 4.0, atol=tol) + @test isapprox(d[4], 0.0, atol=tol) + @test isapprox(d[5], 0.0, atol=tol) end # Problem LIN3 - Infeasible LP @@ -176,7 +176,7 @@ function coniclineartest(solver::MathProgBase.AbstractMathProgSolver;duals=false y = MathProgBase.getdual(m) @test y[1] > 0 @test y[2] < 0 - @test_approx_eq_eps A'y zeros(1) tol + @test isapprox((A'y)[1], 0.0, atol=tol) @test -dot(b,y) > 0 end @@ -223,13 +223,13 @@ function conicSOCtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t [(:SOC,1:3)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -sqrt(2.0) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 1.0/sqrt(2.0) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 1.0/sqrt(2.0) tol + @test isapprox(MathProgBase.getobjval(m), -sqrt(2.0), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 1.0/sqrt(2.0), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 1.0/sqrt(2.0), atol=tol) if duals d = MathProgBase.getdual(m) - @test_approx_eq_eps d[1] sqrt(2.0) tol + @test isapprox(d[1], sqrt(2.0), atol=tol) end @@ -252,16 +252,16 @@ function conicSOCtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t [(:Free,1:3)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -sqrt(2.0) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 1.0/sqrt(2.0) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 1.0/sqrt(2.0) tol + @test isapprox(MathProgBase.getobjval(m), -sqrt(2.0), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 1.0/sqrt(2.0), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 1.0/sqrt(2.0), atol=tol) if duals d = MathProgBase.getdual(m) - @test_approx_eq_eps d[1] sqrt(2.0) tol - @test_approx_eq_eps d[2] sqrt(2.0) tol - @test_approx_eq_eps d[3] -1.0 tol - @test_approx_eq_eps d[4] -1.0 tol + @test isapprox(d[1], sqrt(2.0), atol=tol) + @test isapprox(d[2], sqrt(2.0), atol=tol) + @test isapprox(d[3], -1.0, atol=tol) + @test isapprox(d[4], -1.0, atol=tol) end # Problem SOC2 @@ -289,17 +289,17 @@ function conicSOCtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t MathProgBase.loadproblem!(m, c, A, b, constr_cones, var_cones) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -1/sqrt(2) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] -1/sqrt(2) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 1/sqrt(2) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 1.0 tol + @test isapprox(MathProgBase.getobjval(m), -1/sqrt(2), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], -1/sqrt(2), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 1/sqrt(2), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 1.0, atol=tol) if duals y = MathProgBase.getdual(m) - @test_approx_eq_eps -dot(b,y) -1/sqrt(2) tol - @test_approx_eq_eps c + A'y zeros(3) tol + @test isapprox(-dot(b,y), -1/sqrt(2), atol=tol) + @test isapprox(norm(c + A'y), 0.0, atol=tol) s = MathProgBase.getvardual(m) - @test_approx_eq_eps s zeros(3) tol + @test isapprox(norm(s), 0.0, atol=tol) end # Problem SOC2A @@ -324,17 +324,17 @@ function conicSOCtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t MathProgBase.loadproblem!(m, c, A, b, constr_cones, var_cones) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -1/sqrt(2) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] -1/sqrt(2) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 1/sqrt(2) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 1.0 tol + @test isapprox(MathProgBase.getobjval(m), -1/sqrt(2), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], -1/sqrt(2), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 1/sqrt(2), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 1.0, atol=tol) if duals y = MathProgBase.getdual(m) - @test_approx_eq_eps -dot(b,y) -1/sqrt(2) tol - @test_approx_eq_eps c + A'y zeros(3) tol + @test isapprox(-dot(b,y), -1/sqrt(2), atol=tol) + @test isapprox(norm(c + A'y), 0.0, atol=tol) s = MathProgBase.getvardual(m) - @test_approx_eq_eps s zeros(3) tol + @test isapprox(norm(s), 0.0, atol=tol) end # Problem SOC3 - Infeasible @@ -389,12 +389,12 @@ function conicSOCtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t y = MathProgBase.getdual(m) s = MathProgBase.getvardual(m) - @test_approx_eq_eps dot(c,x) -dot(y,b) tol + @test isapprox(dot(c,x), -dot(y,b), atol=tol) @test x[1]^2 ≥ x[4]^2 + x[5]^2 - tol @test s[1]^2 ≥ s[4]^2 + s[5]^2 - tol - @test_approx_eq_eps s[2] 0.0 tol - @test_approx_eq_eps s[3] 0.0 tol - @test_approx_eq_eps (c+A'y) s tol + @test isapprox(s[2], 0.0, atol=tol) + @test isapprox(s[3], 0.0, atol=tol) + @test isapprox(norm((c+A'y) - s), 0.0, atol=tol) end end @@ -413,18 +413,18 @@ function conicSOCRotatedtest(solver::MathProgBase.AbstractMathProgSolver;duals=f MathProgBase.loadproblem!(m,c,A,b,[(:Zero,1:2)],[(:SOCRotated,1:4)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -sqrt(2.0) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 0.5 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 1.0/sqrt(2.0) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[4] 1.0/sqrt(2.0) tol + @test isapprox(MathProgBase.getobjval(m), -sqrt(2.0), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 0.5, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 1.0/sqrt(2.0), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[4], 1.0/sqrt(2.0), atol=tol) if duals d = MathProgBase.getdual(m) dualobj = -dot(b,d) - @test_approx_eq_eps dualobj -sqrt(2.0) tol + @test isapprox(dualobj, -sqrt(2.0), atol=tol) @test all(d .>= 0) vardual = MathProgBase.getvardual(m) - @test_approx_eq_eps vardual (c+ A'd) tol + @test isapprox(norm(vardual - (c+ A'd)), 0.0, atol=tol) @test 2*vardual[1]*vardual[2] ≥ vardual[3]^2 + vardual[4]^2 - tol end @@ -445,18 +445,18 @@ function conicSOCRotatedtest(solver::MathProgBase.AbstractMathProgSolver;duals=f [(:Free,1:2)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -sqrt(2.0) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 1.0/sqrt(2.0) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 1.0/sqrt(2.0) tol + @test isapprox(MathProgBase.getobjval(m), -sqrt(2.0), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 1.0/sqrt(2.0), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 1.0/sqrt(2.0), atol=tol) if duals d = MathProgBase.getdual(m) @test 2*d[1]*d[2] ≥ d[3]^2 + d[4]^2 - tol dualobj = -dot(b,d) - @test_approx_eq_eps dualobj -sqrt(2.0) tol + @test isapprox(dualobj, -sqrt(2.0), atol=tol) vardual = MathProgBase.getvardual(m) - @test_approx_eq_eps vardual (c+ A'd) tol - @test_approx_eq_eps vardual zeros(2) tol + @test isapprox(norm(vardual - (c+ A'd)), 0.0, atol=tol) + @test isapprox(norm(vardual), 0.0, atol=tol) end # Problem SOCRotated2 - Infeasible @@ -488,7 +488,7 @@ function conicSOCRotatedtest(solver::MathProgBase.AbstractMathProgSolver;duals=f @test y[1] > 0 @test y[2] < 0 vardual = MathProgBase.getvardual(m) - @test_approx_eq_eps A'y vardual tol + @test isapprox(norm(A'y-vardual), 0.0, atol=tol) @test 2*vardual[1]*vardual[2] ≥ vardual[3]^2 @test -dot(b,y) > 0 end @@ -512,10 +512,10 @@ function conicSOCINTtest(solver::MathProgBase.AbstractMathProgSolver;tol=1e-6) MathProgBase.setvartype!(m, [:Cont,:Bin,:Bin]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) -2 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 0.0 tol + @test isapprox(MathProgBase.getobjval(m), -2, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 0.0, atol=tol) end @@ -537,20 +537,20 @@ function conicEXPtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t [(:ExpPrimal, 1:3)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) (2*exp(1/2)+3) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 2.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 2*exp(1/2) tol + @test isapprox(MathProgBase.getobjval(m), (2*exp(1/2)+3), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 2.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 2*exp(1/2), atol=tol) if duals d = MathProgBase.getdual(m) - @test_approx_eq_eps -dot(b,d) MathProgBase.getobjval(m) tol + @test isapprox(-dot(b,d), MathProgBase.getobjval(m), atol=tol) u,v,w = c+A'd # should belong to the ExpDual cone @test u < 0 @test -u*exp(v/w) ≤ exp(1)*w + tol s = MathProgBase.getvardual(m) - @test_approx_eq_eps s c+A'd tol + @test isapprox(norm(s - (c+A'd)), 0.0, atol=tol) end # Problem EXP1A - ExpPrimal @@ -569,21 +569,21 @@ function conicEXPtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t [(:Free, 1:3)]) MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal - @test_approx_eq_eps MathProgBase.getobjval(m) (2*exp(1/2)+3) tol - @test_approx_eq_eps MathProgBase.getsolution(m)[1] 1.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[2] 2.0 tol - @test_approx_eq_eps MathProgBase.getsolution(m)[3] 2*exp(1/2) tol + @test isapprox(MathProgBase.getobjval(m), (2*exp(1/2)+3), atol=tol) + @test isapprox(MathProgBase.getsolution(m)[1], 1.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[2], 2.0, atol=tol) + @test isapprox(MathProgBase.getsolution(m)[3], 2*exp(1/2), atol=tol) if duals d = MathProgBase.getdual(m) - @test_approx_eq_eps -dot(b,d) MathProgBase.getobjval(m) tol - @test_approx_eq_eps c+A'd zeros(3) tol + @test isapprox(-dot(b,d), MathProgBase.getobjval(m), atol=tol) + @test isapprox(norm(c+A'd), 0.0, atol=tol) u,v,w = d[3:5] # should belong to the ExpDual cone @test u < 0 @test -u*exp(v/w) ≤ exp(1)*w + tol s = MathProgBase.getvardual(m) - @test_approx_eq_eps s zeros(3) tol + @test isapprox(norm(s), 0.0, atol=tol) end # Problem EXP2 @@ -610,21 +610,21 @@ function conicEXPtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t conval = b-A*primalsol @test conval[3] + tol ≥ conval[2]*exp(conval[1]/conval[2]) @test conval[6] + tol ≥ conval[5]*exp(conval[4]/conval[5]) - @test_approx_eq_eps conval[7] 0.0 tol + @test isapprox(conval[7], 0.0, atol=tol) for i in 8:14 @test conval[i] ≥ -tol end - @test_approx_eq_eps conval[15] 0.0 tol + @test isapprox(conval[15], 0.0, atol=tol) y = MathProgBase.getdual(m) dualobj = -dot(b,y) - @test_approx_eq_eps primalobj dualobj tol + @test isapprox(primalobj, dualobj, atol=tol) dualconval = c + A'*y var = MathProgBase.getvardual(m) - @test_approx_eq_eps dualconval var tol + @test isapprox(dualconval, var, atol=tol) for i in 1:9 - @test_approx_eq_eps dualconval[i] 0.0 tol + @test isapprox(dualconval[i], 0.0, atol=tol) end if y[1] == 0.0 @test y[2] ≥ -tol @@ -674,12 +674,12 @@ function conicEXPtest(solver::MathProgBase.AbstractMathProgSolver;duals=false, t y = MathProgBase.getdual(m) dualobj = -dot(b,y) - @test_approx_eq_eps primalobj dualobj tol + @test isapprox(primalobj, dualobj, atol=tol) dualconval = c + A'*y var = MathProgBase.getvardual(m) - @test_approx_eq_eps dualconval var tol + @test isapprox(norm(dualconval - var), 0.0, atol=tol) for i in 1:2 - @test_approx_eq_eps dualconval[1] 0.0 tol + @test isapprox(dualconval[1], 0.0, atol=tol) end @test y[1] ≥ -tol @test -y[2]*log(-y[2]/y[4]) + y[2] - y[3] ≤ tol @@ -731,7 +731,7 @@ function conicSDPtest(solver::MathProgBase.AbstractMathProgSolver;duals=true, to MathProgBase.optimize!(m) @test MathProgBase.status(m) == :Optimal pobj = MathProgBase.getobjval(m) - @test_approx_eq_eps pobj 7.05710509e-01 tol + @test isapprox(pobj, 7.05710509e-01, atol=tol) xx = MathProgBase.getsolution(m) x123 = xx[1:3] @@ -743,12 +743,12 @@ function conicSDPtest(solver::MathProgBase.AbstractMathProgSolver;duals=true, to comp_pobj = dot(X,[2.0,s2,0.0, 2.0,s2, 2.0]) + x123[1] # Check dual objective comp_dobj = -dot(y,b) - @test_approx_eq_eps comp_pobj comp_dobj tol + @test isapprox(comp_pobj, comp_dobj, atol=tol) var = c + A' * y @test (var[2]^2 + var[3]^2 - var[1]^2) < tol # (var[1],var[2],var[3]) in SOC s = MathProgBase.getvardual(m) - @test_approx_eq_eps var s tol + @test isapprox(norm(var - s), 0.0, atol=tol) M = [s[4] s[5]/s2 s[6]/s2 s[5]/s2 s[7] s[8]/s2 @@ -784,7 +784,7 @@ function conicSDPtest(solver::MathProgBase.AbstractMathProgSolver;duals=true, to @test eigmin([con[8] con[9]/s2 ; con[9]/s2 con[10]]) > -tol @test con[1] >= -tol @test all(con[2:7] .<= tol) - @test_approx_eq_eps con[11] 0. tol + @test isapprox(con[11], 0.0, atol=tol) if duals y = MathProgBase.getdual(m) @@ -793,10 +793,10 @@ function conicSDPtest(solver::MathProgBase.AbstractMathProgSolver;duals=true, to @test all(y[2:7] .<= tol) var = c + A' * y @test all(var[1:6] .>= -tol) - @test_approx_eq_eps var[7] 0.0 tol + @test isapprox(var[7], 0.0, atol=tol) dobj = -dot(y,b) - @test_approx_eq_eps pobj dobj tol + @test isapprox(pobj, dobj, atol=tol) s = MathProgBase.getvardual(m) - @test_approx_eq_eps s var tol + @test isapprox(norm(s - var), 0.0, atol=tol) end end diff --git a/test/linprog.jl b/test/linprog.jl index f72c4ff..a0de3cb 100644 --- a/test/linprog.jl +++ b/test/linprog.jl @@ -1,7 +1,7 @@ using Base.Test using MathProgBase -function linprogtest(solver=MathProgBase.defaultLPsolver; objtol = 1e-7, primaltol = 1e-6) +function linprogtest(solver; objtol = 1e-7, primaltol = 1e-6) println("Testing linprog and subfunctions with solver ", string(typeof(solver))) # min -x # s.t. 2x + y <= 1.5 @@ -12,27 +12,27 @@ function linprogtest(solver=MathProgBase.defaultLPsolver; objtol = 1e-7, primalt m = buildlp([-1,0],[2 1],'<',1.5,solver) sol = solvelp(m) @test sol.status == :Optimal - @test_approx_eq_eps sol.objval -0.75 objtol - @test_approx_eq_eps norm(sol.sol - [0.75,0.0]) 0 primaltol + @test isapprox(sol.objval, -0.75, atol=objtol) + @test isapprox(norm(sol.sol - [0.75,0.0]), 0.0, atol=primaltol) # test linprog sol = linprog([-1,0],[2 1],'<',1.5,solver) @test sol.status == :Optimal - @test_approx_eq_eps sol.objval -0.75 objtol - @test_approx_eq_eps norm(sol.sol - [0.75,0.0]) 0 primaltol + @test isapprox(sol.objval, -0.75, atol=objtol) + @test isapprox(norm(sol.sol - [0.75,0.0]), 0.0, atol=primaltol) # test buildlp and solvelp m = buildlp([-1,0],[2 1],'<',1.5,solver) sol = solvelp(m) @test sol.status == :Optimal - @test_approx_eq_eps sol.objval -0.75 objtol - @test_approx_eq_eps norm(sol.sol - [0.75,0.0]) 0 primaltol + @test isapprox(sol.objval, -0.75, atol=objtol) + @test isapprox(norm(sol.sol - [0.75,0.0]), 0.0, atol=primaltol) # test linprog sol = linprog([-1,0],sparse([2 1]),'<',1.5,solver) @test sol.status == :Optimal - @test_approx_eq_eps sol.objval -0.75 objtol - @test_approx_eq_eps norm(sol.sol - [0.75,0.0]) 0 primaltol + @test isapprox(sol.objval, -0.75, atol=objtol) + @test isapprox(norm(sol.sol - [0.75,0.0]), 0.0, atol=primaltol) # test infeasible problem: # min x @@ -45,14 +45,14 @@ function linprogtest(solver=MathProgBase.defaultLPsolver; objtol = 1e-7, primalt @test sol.status == :Infeasible r = sol.attrs[:infeasibilityray][1] - @test_approx_eq r/abs(r) -1.0 + @test isapprox(r/abs(r), -1.0) # test linprog sol = linprog([1,0],[2 1],'<',-1,solver) @test sol.status == :Infeasible r = sol.attrs[:infeasibilityray][1] - @test_approx_eq r/abs(r) -1.0 + @test isapprox(r/abs(r), -1.0) # test unbounded problem: # min -x-y @@ -78,13 +78,13 @@ function linprogtest(solver=MathProgBase.defaultLPsolver; objtol = 1e-7, primalt sol = solvelp(m) @test sol.status == :Unbounded @test sol.attrs[:unboundedray][1] > 1e-7 - @test_approx_eq sol.attrs[:unboundedray][1] sol.attrs[:unboundedray][2] + @test isapprox(sol.attrs[:unboundedray][1], sol.attrs[:unboundedray][2]) # test linprog sol = linprog([-1,-1],[1 -1],'=',0,solver) @test sol.status == :Unbounded @test sol.attrs[:unboundedray][1] > 1e-7 - @test_approx_eq sol.attrs[:unboundedray][1] sol.attrs[:unboundedray][2] + @test isapprox(sol.attrs[:unboundedray][1], sol.attrs[:unboundedray][2]) println("Passed") diff --git a/test/linproginterface.jl b/test/linproginterface.jl index 40057f3..5e150af 100644 --- a/test/linproginterface.jl +++ b/test/linproginterface.jl @@ -22,11 +22,11 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) -1 eps - @test_approx_eq_eps getsolution(m) [1.0, 0.0] eps - @test_approx_eq_eps getconstrsolution(m) [1.0] eps - @test_approx_eq_eps getconstrduals(m) [-1.0] eps - @test_approx_eq_eps getreducedcosts(m) [0.0, 1.0] eps + @test isapprox(getobjval(m), -1, atol=eps) + @test isapprox(norm(getsolution(m) - [1.0, 0.0]), 0.0, atol=eps) + @test isapprox(getconstrsolution(m)[1], 1.0, atol=eps) + @test isapprox(getconstrduals(m)[1], -1.0, atol=eps) + @test isapprox(norm(getreducedcosts(m) - [0.0, 1.0]), 0.0, atol=eps) setsense!(m, :Max) # max x @@ -34,11 +34,11 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 1 eps - @test_approx_eq_eps getsolution(m) [1.0, 0.0] eps - @test_approx_eq_eps getconstrsolution(m) [1.0] eps - @test_approx_eq_eps getconstrduals(m) [1.0] eps - @test_approx_eq_eps getreducedcosts(m) [0.0, -1.0] eps + @test isapprox(getobjval(m), 1, atol=eps) + @test isapprox(norm(getsolution(m) - [1.0, 0.0]), 0.0, atol=eps) + @test isapprox(getconstrsolution(m)[1], 1.0, atol=eps) + @test isapprox(getconstrduals(m)[1], 1.0, atol=eps) + @test isapprox(norm(getreducedcosts(m) - [0.0, -1.0]), 0.0, atol=eps) # add new variable to get: # max x + 2z @@ -52,17 +52,17 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 2 eps - @test_approx_eq_eps getsolution(m) [0.0, 0.0, 1.0] eps - @test_approx_eq_eps getconstrsolution(m) [1.0] eps - @test_approx_eq_eps getconstrduals(m) [2.0] eps - @test_approx_eq_eps getreducedcosts(m) [-1.0, -2.0, 0.0] eps + @test isapprox(getobjval(m), 2, atol=eps) + @test isapprox(norm(getsolution(m) - [0.0, 0.0, 1.0]), 0.0, atol=eps) + @test isapprox(getconstrsolution(m)[1], 1.0, atol=eps) + @test isapprox(getconstrduals(m)[1], 2.0, atol=eps) + @test isapprox(norm(getreducedcosts(m) - [-1.0, -2.0, 0.0]), 0.0, atol=eps) setvarLB!(m, [-1.0,0.0,0.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 3 eps + @test isapprox(getobjval(m), 3, atol=eps) # fix z to zero setvarLB!(m, [0.0,0.0,0.0]) @@ -70,17 +70,17 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 1 eps + @test isapprox(getobjval(m), 1, atol=eps) setconstrUB!(m, [2.0]) setconstrLB!(m, [2.0]) optimize!(m) - @test_approx_eq_eps getobjval(m) 2 eps + @test isapprox(getobjval(m), 2, atol=eps) setobj!(m, [1.0, 2.0, 0.0]) optimize!(m) - @test_approx_eq_eps getobjval(m) 4 eps - @test_approx_eq_eps getsolution(m) [0.0, 2.0, 0.0] eps + @test isapprox(getobjval(m), 4, atol=eps) + @test isapprox(norm(getsolution(m) - [0.0, 2.0, 0.0]), 0.0, atol=eps) # we now have: @@ -93,10 +93,10 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 3 eps - @test_approx_eq_eps getsolution(m) [1.0, 1.0, 0.0] eps - @test_approx_eq_eps getconstrduals(m) [1.5, -0.5] eps - @test_approx_eq_eps getreducedcosts(m) [0.0, 0.0, -1.5] eps + @test isapprox(getobjval(m), 3, atol=eps) + @test isapprox(norm(getsolution(m) - [1.0, 1.0, 0.0]), 0.0, atol=eps) + @test isapprox(norm(getconstrduals(m) - [1.5, -0.5]), 0.0, atol=eps) + @test isapprox(norm(getreducedcosts(m) - [0.0, 0.0, -1.5]), 0.0, atol=eps) # test addvar! interface @@ -121,11 +121,11 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) -1 eps - @test_approx_eq_eps getsolution(m) [1.0, 0.0] eps - @test_approx_eq_eps getconstrsolution(m) [1.0] eps - @test_approx_eq_eps getconstrduals(m) [-1.0] eps - @test_approx_eq_eps getreducedcosts(m) [0.0, 1.0] eps + @test isapprox(getobjval(m), -1, atol=eps) + @test isapprox(norm(getsolution(m) - [1.0, 0.0]), 0.0, atol=eps) + @test isapprox(getconstrsolution(m)[1], 1.0, atol=eps) + @test isapprox(getconstrduals(m)[1], -1.0, atol=eps) + @test isapprox(norm(getreducedcosts(m) - [0.0, 1.0]), 0.0, atol=eps) #################################### @@ -147,8 +147,8 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 0.0 eps - @test_approx_eq_eps getsolution(m) [ 0.0, 0.0 ] eps + @test isapprox(getobjval(m), 0.0, atol=eps) + @test isapprox(norm(getsolution(m)), 0.0, atol=eps) # Min x - y # s.t. 100.0 <= x @@ -157,8 +157,8 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul setconstrLB!(m,[100.0,-Inf]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 100.0 eps - @test_approx_eq_eps getsolution(m) [ 100.0, 0.0 ] eps + @test isapprox(getobjval(m), 100.0, atol=eps) + @test isapprox(norm(getsolution(m) - [ 100.0, 0.0 ]), 0.0, atol=eps) # Min x - y # s.t. 100.0 <= x @@ -167,8 +167,8 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul setconstrUB!(m,[Inf,-100.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 200.0 eps - @test_approx_eq_eps getsolution(m) [ 100.0, -100.0 ] eps + @test isapprox(getobjval(m), 200.0, atol=eps) + @test isapprox(norm(getsolution(m) - [ 100.0, -100.0 ]), 0.0, atol=eps) # Test issue #40 from Gurobi.jl # min x @@ -216,8 +216,8 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 2.6666666666 eps - @test_approx_eq_eps getsolution(m) [1.3333333333, 1.3333333333] eps + @test isapprox(getobjval(m), 2.6666666666, atol=eps) + @test isapprox(norm(getsolution(m) - [1.3333333333, 1.3333333333]), 0.0, atol=eps) # copy and solve again @@ -225,8 +225,8 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul m2 = copy(m) optimize!(m2) @test status(m2) == :Optimal - @test_approx_eq_eps getobjval(m2) 2.6666666666 eps - @test_approx_eq_eps getsolution(m2) [1.3333333333, 1.3333333333] eps + @test isapprox(getobjval(m2), 2.6666666666, atol=eps) + @test isapprox(norm(getsolution(m2) - [1.3333333333, 1.3333333333]), 0.0, atol=eps) end @@ -242,8 +242,8 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul changecoeffs!(m, [1], [2], [2.]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 2.0 eps - @test_approx_eq_eps getsolution(m) [0.0, 2.0] eps + @test isapprox(getobjval(m), 2.0, atol=eps) + @test isapprox(norm(getsolution(m) - [0.0, 2.0]), 0.0, atol=eps) end @@ -258,8 +258,8 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul delconstrs!(m, [1]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 4.0 eps - @test_approx_eq_eps getsolution(m) [4.0, 0.0] eps + @test isapprox(getobjval(m), 4.0, atol=eps) + @test isapprox(norm(getsolution(m) - [4.0, 0.0]), 0.0, atol=eps) end # delvars and solve @@ -273,8 +273,8 @@ function linprogsolvertest(solver::AbstractMathProgSolver, eps = Base.rtoldefaul delvars!(m, [1]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq_eps getobjval(m) 2.0 eps - @test_approx_eq_eps getsolution(m) [2.0] eps + @test isapprox(getobjval(m), 2.0, atol=eps) + @test isapprox(getsolution(m)[1], 2.0, atol=eps) end @@ -300,8 +300,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) 0.0 - @test_approx_eq getsolution(m) [ 0.0, 0.0 ] + @test isapprox(getobjval(m), 0.0) + @test isapprox(norm(getsolution(m)), 0.0) # Min x - y # s.t. 0.0 <= x <= 100.0 @@ -310,8 +310,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold setconstrUB!(m,[100.0,100.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) -100.0 - @test_approx_eq getsolution(m) [ 0.0, 100.0 ] + @test isapprox(getobjval(m), -100.0) + @test isapprox(norm(getsolution(m) - [ 0.0, 100.0 ]), 0.0) # Min x - y # s.t. -100.0 <= x <= 100.0 @@ -320,8 +320,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold setconstrLB!(m,[-100.0,-100.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) -200.0 - @test_approx_eq getsolution(m) [ -100.0, 100.0 ] + @test isapprox(getobjval(m), -200.0) + @test isapprox(norm(getsolution(m) - [ -100.0, 100.0 ]), 0.0) # Min x - y # s.t. -100.0 <= x <= 100.0 @@ -331,8 +331,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold setconstrUB!(m,[10.0,10.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) 0.0 - @test_approx_eq getsolution(m) [ 10.0, 10.0 ] + @test isapprox(getobjval(m), 0.0) + @test isapprox(norm(getsolution(m) - [ 10.0, 10.0 ]), 0.0) # Min x - y # s.t. 0.0 <= x <= Inf @@ -342,8 +342,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold setconstrUB!(m,[Inf,0.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) 0.0 - @test_approx_eq getsolution(m) [ 0.0, 0.0 ] + @test isapprox(getobjval(m), 0.0) + @test isapprox(norm(getsolution(m)), 0.0) # Min x - y # s.t. -Inf <= x <= Inf @@ -388,8 +388,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) 0.0 - @test_approx_eq getsolution(m) [ 0.0, 0.0 ] + @test isapprox(getobjval(m), 0.0) + @test isapprox(norm(getsolution(m)), 0.0) @@ -403,8 +403,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold setvarUB!(m,[100.0,100.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) -100.0 - @test_approx_eq getsolution(m) [ 0.0, 100.0 ] + @test isapprox(getobjval(m), -100.0) + @test isapprox(norm(getsolution(m) - [ 0.0, 100.0 ]), 0.0) # Min x - y # s.t. -Inf <= x <= Inf @@ -414,8 +414,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold setvarLB!(m,[-100.0,-100.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) -200.0 - @test_approx_eq getsolution(m) [ -100.0, 100.0 ] + @test isapprox(getobjval(m), -200.0) + @test isapprox(norm(getsolution(m) - [ -100.0, 100.0 ]), 0.0) # Min x - y # s.t. -Inf <= x <= Inf @@ -426,8 +426,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold setvarUB!(m,[10.0,10.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) 0.0 - @test_approx_eq getsolution(m) [ 10.0, 10.0 ] + @test isapprox(getobjval(m), 0.0) + @test isapprox(norm(getsolution(m) - [ 10.0, 10.0 ]), 0.0) # Min x - y # s.t. -Inf <= x <= Inf @@ -439,8 +439,8 @@ function linprogsolvertestextra(solver::AbstractMathProgSolver; eps = Base.rtold setvarUB!(m,[Inf,0.0]) optimize!(m) @test status(m) == :Optimal - @test_approx_eq getobjval(m) 0.0 - @test_approx_eq getsolution(m) [ 0.0, 0.0 ] + @test isapprox(getobjval(m), 0.0) + @test isapprox(norm(getsolution(m)), 0.0) # Min x - y # s.t. -Inf <= x <= Inf diff --git a/test/mixintprog.jl b/test/mixintprog.jl index 9acdf95..14b5e0f 100644 --- a/test/mixintprog.jl +++ b/test/mixintprog.jl @@ -1,14 +1,14 @@ using Base.Test using MathProgBase -function mixintprogtest(solver=MathProgBase.defaultMIPsolver) +function mixintprogtest(solver) println("Testing mixintprog with solver ", string(typeof(solver))) # integer knapsack problem sol = mixintprog(-[5,3,2,7,4],Float64[2 8 4 2 5],'<',10,:Int,0,1,solver) @test sol.status == :Optimal - @test_approx_eq_eps sol.objval -16.0 1e-6 - @test_approx_eq_eps norm(sol.sol - [1.0, 0.0, 0.0, 1.0, 1.0]) 0.0 1e-4 + @test isapprox(sol.objval, -16.0, atol=1e-6) + @test isapprox(norm(sol.sol - [1.0, 0.0, 0.0, 1.0, 1.0]), 0.0, atol=1e-4) println("Done") end diff --git a/test/nlp.jl b/test/nlp.jl index db0e91d..ef99fde 100644 --- a/test/nlp.jl +++ b/test/nlp.jl @@ -88,7 +88,7 @@ function MathProgBase.eval_hesslag(d::HS071, H, x, σ, μ) end -function nlptest(solver=MathProgBase.defaultNLPsolver) +function nlptest(solver) m = MathProgBase.NonlinearModel(solver) l = [1,1,1,1] @@ -103,11 +103,11 @@ function nlptest(solver=MathProgBase.defaultNLPsolver) @test stat == :Optimal x = MathProgBase.getsolution(m) - @test_approx_eq_eps x[1] 1.0000000000000000 1e-5 - @test_approx_eq_eps x[2] 4.7429996418092970 1e-5 - @test_approx_eq_eps x[3] 3.8211499817883077 1e-5 - @test_approx_eq_eps x[4] 1.3794082897556983 1e-5 - @test_approx_eq_eps MathProgBase.getobjval(m) 17.014017145179164 1e-5 + @test isapprox(x[1], 1.0000000000000000, atol=1e-5) + @test isapprox(x[2], 4.7429996418092970, atol=1e-5) + @test isapprox(x[3], 3.8211499817883077, atol=1e-5) + @test isapprox(x[4], 1.3794082897556983, atol=1e-5) + @test isapprox(MathProgBase.getobjval(m), 17.014017145179164, atol=1e-5) # Test that a second call to optimize! works MathProgBase.setwarmstart!(m,[1,5,5,1]) @@ -150,7 +150,7 @@ MathProgBase.jac_structure(d::HS071_2) = MathProgBase.jac_structure(HS071()) MathProgBase.eval_jac_g(d::HS071_2, J, x) = MathProgBase.eval_jac_g(HS071(), J, x) -function nlptest_nohessian(solver=MathProgBase.defaultNLPsolver) +function nlptest_nohessian(solver) m = MathProgBase.NonlinearModel(solver) l = [1,1,1,1] @@ -165,11 +165,11 @@ function nlptest_nohessian(solver=MathProgBase.defaultNLPsolver) @test stat == :Optimal x = MathProgBase.getsolution(m) - @test_approx_eq_eps x[1] 1.0000000000000000 1e-5 - @test_approx_eq_eps x[2] 4.7429996418092970 1e-5 - @test_approx_eq_eps x[3] 3.8211499817883077 1e-5 - @test_approx_eq_eps x[4] 1.3794082897556983 1e-5 - @test_approx_eq_eps MathProgBase.getobjval(m) 17.014017145179164 1e-5 + @test isapprox(x[1], 1.0000000000000000, atol=1e-5) + @test isapprox(x[2], 4.7429996418092970, atol=1e-5) + @test isapprox(x[3], 3.8211499817883077, atol=1e-5) + @test isapprox(x[4], 1.3794082897556983, atol=1e-5) + @test isapprox(MathProgBase.getobjval(m), 17.014017145179164, atol=1e-5) # Test that a second call to optimize! works MathProgBase.setwarmstart!(m,[1,5,5,1]) @@ -233,7 +233,7 @@ function MathProgBase.eval_hesslag(d::QCQP, H, x, σ, μ) end -function convexnlptest(solver=MathProgBase.defaultNLPsolver) +function convexnlptest(solver) m = MathProgBase.NonlinearModel(solver) l = [-2,-2] @@ -247,8 +247,8 @@ function convexnlptest(solver=MathProgBase.defaultNLPsolver) @test stat == :Optimal x = MathProgBase.getsolution(m) - @test_approx_eq_eps (x[1]+x[2]) -1/3 1e-3 - @test_approx_eq_eps MathProgBase.getobjval(m) -1-4/sqrt(3) 1e-5 + @test isapprox(x[1]+x[2], -1/3, atol=1e-3) + @test isapprox(MathProgBase.getobjval(m), -1-4/sqrt(3), atol=1e-5) # Test that a second call to optimize! works MathProgBase.optimize!(m) @@ -298,7 +298,7 @@ function MathProgBase.eval_hesslag(d::Rosenbrock, H, x, σ, μ) end -function rosenbrocktest(solver=MathProgBase.defaultNLPsolver) +function rosenbrocktest(solver) m = MathProgBase.NonlinearModel(solver) l = [-Inf,-Inf] @@ -313,9 +313,9 @@ function rosenbrocktest(solver=MathProgBase.defaultNLPsolver) @test stat == :Optimal x = MathProgBase.getsolution(m) - @test_approx_eq_eps x[1] 1.0 1e-5 - @test_approx_eq_eps x[2] 1.0 1e-5 - @test_approx_eq_eps MathProgBase.getobjval(m) 0.0 1e-5 + @test isapprox(x[1], 1.0, atol=1e-5) + @test isapprox(x[2], 1.0, atol=1e-5) + @test isapprox(MathProgBase.getobjval(m), 0.0, atol=1e-5) # Test that a second call to optimize! works MathProgBase.optimize!(m) diff --git a/test/quadprog.jl b/test/quadprog.jl index 29e315b..a88a377 100644 --- a/test/quadprog.jl +++ b/test/quadprog.jl @@ -2,13 +2,13 @@ using Base.Test using MathProgBase using MathProgBase.SolverInterface -function quadprogtest(solver=MathProgBase.defaultQPsolver) +function quadprogtest(solver) println("Testing quadprog with solver ", string(typeof(solver))) sol = quadprog([0., 0., 0.],[2. 1. 0.; 1. 2. 1.; 0. 1. 2.],[1. 2. 3.; 1. 1. 0.],'>',[4., 1.],-Inf,Inf,solver) @test sol.status == :Optimal - @test_approx_eq_eps sol.objval 130/70 1e-6 - @test_approx_eq_eps norm(sol.sol[1:3] - [0.5714285714285715,0.4285714285714285,0.8571428571428572]) 0.0 1e-6 + @test isapprox(sol.objval, 130/70, atol=1e-6) + @test isapprox(norm(sol.sol[1:3] - [0.5714285714285715,0.4285714285714285,0.8571428571428572]), 0.0, atol=1e-6) let m = LinearQuadraticModel(solver) @@ -22,8 +22,8 @@ function quadprogtest(solver=MathProgBase.defaultQPsolver) optimize!(m) stat = status(m) @test stat == :Optimal - @test_approx_eq_eps getobjval(m) 130/70 1e-6 - @test_approx_eq_eps norm(getsolution(m) - [0.5714285714285715,0.4285714285714285,0.8571428571428572]) 0.0 1e-6 + @test isapprox(getobjval(m), 130/70, atol=1e-6) + @test isapprox(norm(getsolution(m) - [0.5714285714285715,0.4285714285714285,0.8571428571428572]), 0.0, atol=1e-6) end let @@ -33,13 +33,13 @@ function quadprogtest(solver=MathProgBase.defaultQPsolver) optimize!(m) stat = status(m) @test stat == :Optimal - @test_approx_eq_eps getobjval(m) 2.25 1e-6 - @test_approx_eq_eps norm(getsolution(m) - [0.5,1.75]) 0.0 1e-3 + @test isapprox(getobjval(m), 2.25, atol=1e-6) + @test isapprox(norm(getsolution(m) - [0.5,1.75]), 0.0, atol=1e-3) end println("Done") end -function qpdualtest(solver=MathProgBase.defaultQPsolver) +function qpdualtest(solver) println("Testing QP duals with solver ", string(typeof(solver))) # max x # s.t. x^2 <= 2 @@ -53,9 +53,9 @@ function qpdualtest(solver=MathProgBase.defaultQPsolver) @test numquadconstr(m) == 1 @test numconstr(m) == 1 @test stat == :Optimal - @test_approx_eq_eps getobjval(m) sqrt(2) 1e-6 - @test_approx_eq_eps getsolution(m)[1] sqrt(2) 1e-6 - @test_approx_eq_eps getquadconstrduals(m)[1] 0.5/sqrt(2) 1e-6 + @test isapprox(getobjval(m), sqrt(2), atol=1e-6) + @test isapprox(getsolution(m)[1], sqrt(2), atol=1e-6) + @test isapprox(getquadconstrduals(m)[1], 0.5/sqrt(2), atol=1e-6) # min -x # s.t. x^2 <= 2 @@ -69,14 +69,14 @@ function qpdualtest(solver=MathProgBase.defaultQPsolver) @test numquadconstr(m) == 1 @test numconstr(m) == 1 @test stat == :Optimal - @test_approx_eq_eps getobjval(m) -sqrt(2) 1e-6 - @test_approx_eq_eps getsolution(m)[1] sqrt(2) 1e-6 - @test_approx_eq_eps getquadconstrduals(m)[1] -0.5/sqrt(2) 1e-6 + @test isapprox(getobjval(m), -sqrt(2), atol=1e-6) + @test isapprox(getsolution(m)[1], sqrt(2), atol=1e-6) + @test isapprox(getquadconstrduals(m)[1], -0.5/sqrt(2), atol=1e-6) println("Done") end -function socptest(solver=MathProgBase.defaultQPsolver) +function socptest(solver) println("Testing SOCP interface with solver ", string(typeof(solver))) # min t @@ -90,8 +90,8 @@ function socptest(solver=MathProgBase.defaultQPsolver) stat = status(m) @test stat == :Optimal - @test_approx_eq_eps getobjval(m) sqrt(1/2) 1e-6 - @test_approx_eq_eps norm(getsolution(m) - [0.5,0.5,sqrt(1/2)]) 0.0 1e-3 + @test isapprox(getobjval(m), sqrt(1/2), atol=1e-6) + @test isapprox(norm(getsolution(m) - [0.5,0.5,sqrt(1/2)]), 0.0, atol=1e-3) println("Done") diff --git a/test/runtests.jl b/test/runtests.jl index 531bcbd..e010b38 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -8,6 +8,14 @@ mixintprogtest(GLPKSolverMIP()) include("quadprog.jl") quadprogtest(IpoptSolver()) +qpdualtest(IpoptSolver()) +socptest(ECOSSolver()) + +include("nlp.jl") +nlptest(IpoptSolver()) +nlptest_nohessian(IpoptSolver()) +convexnlptest(IpoptSolver()) +rosenbrocktest(IpoptSolver()) include("conicinterface.jl") coniclineartest(ECOSSolver(), duals=true) @@ -16,5 +24,6 @@ coniclineartest(GLPKSolverLP(), duals=true) include("linproginterface.jl") linprogsolvertest(GLPKSolverLP()) +linprogsolvertestextra(GLPKSolverLP()) # Test LP fallback for conics linprogsolvertest(ECOSSolver())