Skip to content

Commit 7ce48e2

Browse files
IssamTmlubin
authored andcommitted
added a new test of infeas. prob. with 2 constraints (#159)
* added a new test of infeas. prob. with 2 constraints * updated linear12test * minor fix * fixes some errors * 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)
1 parent 7a2fb1a commit 7ce48e2

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/contlinear.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,50 @@ function linear11test(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64)
10631063
end
10641064
end
10651065

1066+
function linear12test(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64))
1067+
@testset "test infeasible problem with 2 linear constraints" begin
1068+
# min x
1069+
# s.t. 2x-3y <= -7
1070+
# y <= 2
1071+
# x,y >= 0
1072+
@test MOI.supportsproblem(solver, MOI.ScalarAffineFunction{Float64}, [(MOI.ScalarAffineFunction{Float64},MOI.GreaterThan{Float64}),(MOI.SingleVariable,MOI.GreaterThan{Float64})])
1073+
1074+
m = MOI.SolverInstance(solver)
1075+
x = MOI.addvariable!(m)
1076+
y = MOI.addvariable!(m)
1077+
c1 = MOI.addconstraint!(m, MOI.ScalarAffineFunction([x,y], [2.0,-3.0], 0.0), MOI.LessThan(-7.0))
1078+
c2 = MOI.addconstraint!(m, MOI.ScalarAffineFunction([y], [1.0], 0.0), MOI.LessThan(2.0))
1079+
bndx = MOI.addconstraint!(m, MOI.SingleVariable(x), MOI.GreaterThan(0.0))
1080+
bndy = MOI.addconstraint!(m, MOI.SingleVariable(y), MOI.GreaterThan(0.0))
1081+
MOI.set!(m, MOI.ObjectiveFunction(), MOI.ScalarAffineFunction([x], [1.0], 0.0))
1082+
MOI.set!(m, MOI.ObjectiveSense(), MOI.MinSense)
1083+
MOI.optimize!(m)
1084+
1085+
@test MOI.canget(m, MOI.ResultCount())
1086+
if MOI.get(m, MOI.ResultCount()) >= 1
1087+
# solver returned an infeasibility ray
1088+
@test MOI.get(m, MOI.TerminationStatus()) == MOI.Success
1089+
@test MOI.get(m, MOI.DualStatus()) == MOI.InfeasibilityCertificate
1090+
@test MOI.canget(m, MOI.ConstraintDual(), c1)
1091+
cd1 = MOI.get(m, MOI.ConstraintDual(), c1)
1092+
cd2 = MOI.get(m, MOI.ConstraintDual(), c2)
1093+
bndxd = MOI.get(m, MOI.ConstraintDual(), bndx)
1094+
bndyd = MOI.get(m, MOI.ConstraintDual(), bndy)
1095+
@test cd1 < - atol
1096+
@test cd2 < - atol
1097+
@test - 3 * cd1 + cd2 -bndyd atol=atol rtol=rtol
1098+
@test 2 * cd1 -bndxd atol=atol rtol=rtol
1099+
@test -7 * cd1 + 2 * cd2 > atol
1100+
else
1101+
# solver returned nothing
1102+
@test MOI.get(m, MOI.ResultCount()) == 0
1103+
@test MOI.canget(m, MOI.PrimalStatus(1)) == false
1104+
@test MOI.get(m, MOI.TerminationStatus()) == MOI.InfeasibleNoResult ||
1105+
MOI.get(m, MOI.TerminationStatus()) == MOI.InfeasibleOrUnbounded
1106+
end
1107+
end
1108+
end
1109+
10661110
function contlineartest(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float64), rtol=Base.rtoldefault(Float64))
10671111
linear1test(solver, atol=atol, rtol=rtol)
10681112
linear2test(solver, atol=atol, rtol=rtol)
@@ -1075,4 +1119,5 @@ function contlineartest(solver::MOI.AbstractSolver; atol=Base.rtoldefault(Float6
10751119
linear9test(solver, atol=atol, rtol=rtol)
10761120
linear10test(solver, atol=atol, rtol=rtol)
10771121
linear11test(solver, atol=atol, rtol=rtol)
1122+
linear12test(solver, atol=atol, rtol=rtol)
10781123
end

0 commit comments

Comments
 (0)