From 8021b7053bed50dbd5159418f0e730711fab7d2f Mon Sep 17 00:00:00 2001 From: Issam Tahiri Date: Thu, 2 Nov 2017 11:55:07 +0100 Subject: [PATCH 1/5] added a new test of infeas. prob. with 2 constraints --- test/contlinear.jl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/contlinear.jl b/test/contlinear.jl index c92ae9c39d..fc033bfb7b 100644 --- a/test/contlinear.jl +++ b/test/contlinear.jl @@ -1063,6 +1063,45 @@ function linear11test(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64) end end +function linear12test(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64)) + @testset "test infeasible problem with 2 linear constraints" begin + # min x + # s.t. 2x-3y <= -7 + # y <= 2 + # x,y >= 0 + @test MOI.supportsproblem(solver, MOI.ScalarAffineFunction{Float64}, [(MOI.ScalarAffineFunction{Float64},MOI.GreaterThan{Float64}),(MOI.SingleVariable,MOI.GreaterThan{Float64})]) + + m = MOI.SolverInstance(solver) + x = MOI.addvariable!(m) + y = MOI.addvariable!(m) + c1 = MOI.addconstraint!(m, MOI.ScalarAffineFunction([x,y], [2.0,-3.0], 0.0), MOI.LessThan(-7.0)) + c2 = MOI.addconstraint!(m, MOI.ScalarAffineFunction([y], [1.0], 0.0), MOI.LessThan(2.0)) + bndx = MOI.addconstraint!(m, MOI.SingleVariable(x), MOI.GreaterThan(0.0)) + bndy = MOI.addconstraint!(m, MOI.SingleVariable(y), MOI.GreaterThan(0.0)) + MOI.set!(m, MOI.ObjectiveFunction(), MOI.ScalarAffineFunction([x], [1.0], 0.0)) + MOI.set!(m, MOI.ObjectiveSense(), MOI.MinSense) + MOI.optimize!(m) + + @test MOI.canget(m, MOI.ResultCount()) + if MOI.get(m, MOI.ResultCount()) >= 1 + # solver returned an infeasibility ray + @test MOI.get(m, MOI.TerminationStatus()) == MOI.Success + @test MOI.get(m, MOI.DualStatus()) == MOI.InfeasibilityCertificate + @test MOI.canget(m, MOI.ConstraintDual(), c1) + cd1 = MOI.get(m, MOI.ConstraintDual(), c1) + cd2 = MOI.get(m, MOI.ConstraintDual(), c2) + bndyd = MOI.get(m, MOI.ConstraintDual(), bndy) + @test (cd2-bndyd)/cd1 ≈ 3 atol=atol rtol=rtol + else + # solver returned nothing + @test MOI.get(m, MOI.ResultCount()) == 0 + @test MOI.canget(m, MOI.PrimalStatus(1)) == false + @test MOI.get(m, MOI.TerminationStatus()) == MOI.InfeasibleNoResult || + MOI.get(m, MOI.TerminationStatus()) == MOI.InfeasibleOrUnbounded + end + end +end + function contlineartest(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64)) linear1test(solver, atol=atol, rtol=rtol) linear2test(solver, atol=atol, rtol=rtol) From 5b010041e3e03946d5ea76717f19f014cf2ff4ff Mon Sep 17 00:00:00 2001 From: Issam Tahiri Date: Thu, 2 Nov 2017 13:48:24 +0100 Subject: [PATCH 2/5] updated linear12test --- test/contlinear.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/contlinear.jl b/test/contlinear.jl index fc033bfb7b..d8bbeb7d05 100644 --- a/test/contlinear.jl +++ b/test/contlinear.jl @@ -1091,7 +1091,11 @@ function linear12test(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64) cd1 = MOI.get(m, MOI.ConstraintDual(), c1) cd2 = MOI.get(m, MOI.ConstraintDual(), c2) bndyd = MOI.get(m, MOI.ConstraintDual(), bndy) - @test (cd2-bndyd)/cd1 ≈ 3 atol=atol rtol=rtol + @test cd1 < atol + @test cd2 < atol + @test - 3 cd1 + cd2 ≈ bndyd atol=atol rtol=rtol + @test 2 cd1 ≈ bndxd atol=atol rtol=rtol + @test cd1 + cd2 > -atol else # solver returned nothing @test MOI.get(m, MOI.ResultCount()) == 0 From 07e2c1ea368885bca37d647e870c3782b0c2e840 Mon Sep 17 00:00:00 2001 From: Issam Tahiri Date: Thu, 2 Nov 2017 13:50:53 +0100 Subject: [PATCH 3/5] minor fix --- test/contlinear.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/contlinear.jl b/test/contlinear.jl index d8bbeb7d05..e249af30ac 100644 --- a/test/contlinear.jl +++ b/test/contlinear.jl @@ -1093,9 +1093,9 @@ function linear12test(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64) bndyd = MOI.get(m, MOI.ConstraintDual(), bndy) @test cd1 < atol @test cd2 < atol - @test - 3 cd1 + cd2 ≈ bndyd atol=atol rtol=rtol - @test 2 cd1 ≈ bndxd atol=atol rtol=rtol - @test cd1 + cd2 > -atol + @test - 3 * cd1 + cd2 ≈ bndyd atol=atol rtol=rtol + @test 2 * cd1 ≈ bndxd atol=atol rtol=rtol + @test -7 * cd1 + 2 * cd2 > -atol else # solver returned nothing @test MOI.get(m, MOI.ResultCount()) == 0 From be267c886387768616ac658683104ffa893580f5 Mon Sep 17 00:00:00 2001 From: Issam Tahiri Date: Thu, 2 Nov 2017 16:20:32 +0100 Subject: [PATCH 4/5] fixes some errors --- test/contlinear.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/contlinear.jl b/test/contlinear.jl index e249af30ac..467b1a9016 100644 --- a/test/contlinear.jl +++ b/test/contlinear.jl @@ -1090,11 +1090,12 @@ function linear12test(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64) @test MOI.canget(m, MOI.ConstraintDual(), c1) cd1 = MOI.get(m, MOI.ConstraintDual(), c1) cd2 = MOI.get(m, MOI.ConstraintDual(), c2) + bndxd = MOI.get(m, MOI.ConstraintDual(), bndx) bndyd = MOI.get(m, MOI.ConstraintDual(), bndy) @test cd1 < atol @test cd2 < atol - @test - 3 * cd1 + cd2 ≈ bndyd atol=atol rtol=rtol - @test 2 * cd1 ≈ bndxd atol=atol rtol=rtol + @test - 3 * cd1 + cd2 ≈ -bndyd atol=atol rtol=rtol + @test 2 * cd1 ≈ -bndxd atol=atol rtol=rtol @test -7 * cd1 + 2 * cd2 > -atol else # solver returned nothing @@ -1118,4 +1119,5 @@ function contlineartest(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float6 linear9test(solver, atol=atol, rtol=rtol) linear10test(solver, atol=atol, rtol=rtol) linear11test(solver, atol=atol, rtol=rtol) + linear12test(solver, atol=atol, rtol=rtol) end From 401c4e225a3b3bf678243e3f21e3ad30917ef65b Mon Sep 17 00:00:00 2001 From: Issam Tahiri Date: Fri, 3 Nov 2017 17:15:04 +0100 Subject: [PATCH 5/5] using atol outside of its purpose. (this is IMO not the right solution to avoid the 0 vector being an accepted ray, but mlubin and blegat agrees on it) --- test/contlinear.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/contlinear.jl b/test/contlinear.jl index 467b1a9016..fcbd7a2418 100644 --- a/test/contlinear.jl +++ b/test/contlinear.jl @@ -1092,11 +1092,11 @@ function linear12test(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64) cd2 = MOI.get(m, MOI.ConstraintDual(), c2) bndxd = MOI.get(m, MOI.ConstraintDual(), bndx) bndyd = MOI.get(m, MOI.ConstraintDual(), bndy) - @test cd1 < atol - @test cd2 < atol + @test cd1 < - atol + @test cd2 < - atol @test - 3 * cd1 + cd2 ≈ -bndyd atol=atol rtol=rtol @test 2 * cd1 ≈ -bndxd atol=atol rtol=rtol - @test -7 * cd1 + 2 * cd2 > -atol + @test -7 * cd1 + 2 * cd2 > atol else # solver returned nothing @test MOI.get(m, MOI.ResultCount()) == 0