Skip to content

Commit

Permalink
Merge pull request #241 from tkoolen/tk/feasibility-problem
Browse files Browse the repository at this point in the history
Add test for a feasibility problem
  • Loading branch information
blegat authored Feb 20, 2018
2 parents 35d6a77 + e40391e commit 572b5ae
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion src/Test/contlinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,64 @@ function linear12test(model::MOI.ModelLike, config::TestConfig)
end
end

# feasibility problem
function linear13test(model::MOI.ModelLike, config::TestConfig)
atol = config.atol
rtol = config.rtol
# find x, y
# s.t. 2x + 3y >= 1
# x - y == 0

MOI.empty!(model)
@test MOI.isempty(model)
@test MOI.canaddvariable(model)
x = MOI.addvariable!(model)
@test MOI.canaddvariable(model)
y = MOI.addvariable!(model)
@test MOI.canaddconstraint(model, MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64})
c1 = MOI.addconstraint!(model, MOI.ScalarAffineFunction([x,y], [2.0,3.0], 0.0), MOI.GreaterThan(1.0))
@test MOI.canaddconstraint(model, MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64})
c2 = MOI.addconstraint!(model, MOI.ScalarAffineFunction([x,y], [1.0,-1.0], 0.0), MOI.EqualTo(0.0))
@test MOI.canset(model, MOI.ObjectiveSense())
MOI.set!(model, MOI.ObjectiveSense(), MOI.FeasibilitySense)
@test MOI.get(model, MOI.ObjectiveSense()) == MOI.FeasibilitySense

if config.solve
MOI.optimize!(model)
@test MOI.canget(model, MOI.ResultCount())
@test MOI.get(model, MOI.ResultCount()) > 0

@test MOI.canget(model, MOI.TerminationStatus())
@test MOI.get(model, MOI.TerminationStatus()) == MOI.Success

@test MOI.canget(model, MOI.PrimalStatus())
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FeasiblePoint

@test MOI.canget(model, MOI.VariablePrimal(), MOI.VariableIndex)
xsol = MOI.get(model, MOI.VariablePrimal(), x)
ysol = MOI.get(model, MOI.VariablePrimal(), y)

c1sol = 2 * xsol + 3 * ysol
@test c1sol >= 1 || isapprox(c1sol, 1.0, atol=atol, rtol=rtol)
@test xsol - ysol 0 atol=atol rtol=rtol

@test MOI.canget(model, MOI.ConstraintPrimal(), typeof(c1))
c1primval = MOI.get(model, MOI.ConstraintPrimal(), c1)
@test c1primval >= 1 || isapprox(c1sol, 1.0, atol=atol, rtol=rtol)

@test MOI.canget(model, MOI.ConstraintPrimal(), typeof(c2))
@test MOI.get(model, MOI.ConstraintPrimal(), c2) 0 atol=atol rtol=rtol

if config.duals
@test MOI.canget(model, MOI.DualStatus())
@test MOI.get(model, MOI.DualStatus()) == MOI.FeasiblePoint
@test MOI.canget(model, MOI.ConstraintDual(), typeof(c1))
@test MOI.get(model, MOI.ConstraintDual(), c1) 0 atol=atol rtol=rtol
@test MOI.get(model, MOI.ConstraintDual(), c2) 0 atol=atol rtol=rtol
end
end
end

const contlineartests = Dict("linear1" => linear1test,
"linear2" => linear2test,
"linear3" => linear3test,
Expand All @@ -1381,6 +1439,7 @@ const contlineartests = Dict("linear1" => linear1test,
"linear9" => linear9test,
"linear10" => linear10test,
"linear11" => linear11test,
"linear12" => linear12test)
"linear12" => linear12test,
"linear13" => linear13test)

@moitestset contlinear

0 comments on commit 572b5ae

Please sign in to comment.