Skip to content

Commit 4947022

Browse files
committed
Test inactive range constraint
1 parent a38a1d8 commit 4947022

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

src/Test/contlinear.jl

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,63 @@ function linear10test(model::MOI.ModelLike, config::TestConfig)
12351235
end
12361236
end
12371237

1238+
# inactive ranged constraints
1239+
function linear10btest(model::MOI.ModelLike, config::TestConfig)
1240+
atol = config.atol
1241+
rtol = config.rtol
1242+
# minimize x + y
1243+
#
1244+
# s.t. -1 <= x + y <= 10
1245+
# x, y >= 0
1246+
1247+
@test MOIU.supports_default_copy_to(model, #=copy_names=# false)
1248+
@test MOI.supports(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}())
1249+
@test MOI.supports(model, MOI.ObjectiveSense())
1250+
@test MOI.supports_constraint(model, MOI.ScalarAffineFunction{Float64}, MOI.Interval{Float64})
1251+
@test MOI.supports_constraint(model, MOI.SingleVariable, MOI.GreaterThan{Float64})
1252+
1253+
MOI.empty!(model)
1254+
@test MOI.is_empty(model)
1255+
1256+
x = MOI.add_variable(model)
1257+
y = MOI.add_variable(model)
1258+
1259+
vc = MOI.add_constraints(model,
1260+
[MOI.SingleVariable(x), MOI.SingleVariable(y)],
1261+
[MOI.GreaterThan(0.0), MOI.GreaterThan(0.0)]
1262+
)
1263+
1264+
c = MOI.add_constraint(model, MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.0], [x,y]), 0.0), MOI.Interval(-1.0, 10.0))
1265+
1266+
MOI.set(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.0], [x, y]), 0.0))
1267+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
1268+
1269+
if config.solve
1270+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED
1271+
1272+
MOI.optimize!(model)
1273+
1274+
@test MOI.get(model, MOI.TerminationStatus()) == config.optimal_status
1275+
@test MOI.get(model, MOI.PrimalStatus()) == MOI.FEASIBLE_POINT
1276+
@test MOI.get(model, MOI.ObjectiveValue()) 0.0 atol=atol rtol=rtol
1277+
@test MOI.get(model, MOI.ConstraintPrimal(), c) 0.0 atol=atol rtol=rtol
1278+
1279+
if config.duals
1280+
@test MOI.get(model, MOI.ResultCount()) >= 1
1281+
@test MOI.get(model, MOI.DualStatus()) == MOI.FEASIBLE_POINT
1282+
@test MOI.get(model, MOI.ConstraintDual(), c) 0.0 atol=atol rtol=rtol
1283+
@test MOI.get(model, MOI.ConstraintDual(), vc[1]) 1.0 atol=atol rtol=rtol
1284+
@test MOI.get(model, MOI.ConstraintDual(), vc[2]) 1.0 atol=atol rtol=rtol
1285+
end
1286+
1287+
if config.basis
1288+
@test (MOI.get(model, MOI.ConstraintBasisStatus(), vc[1]) == MOI.NONBASIC)
1289+
@test (MOI.get(model, MOI.ConstraintBasisStatus(), vc[1]) == MOI.NONBASIC)
1290+
@test MOI.get(model, MOI.ConstraintBasisStatus(), c) == MOI.BASIC
1291+
end
1292+
end
1293+
end
1294+
12381295
# changing constraint sense
12391296
function linear11test(model::MOI.ModelLike, config::TestConfig)
12401297
atol = config.atol
@@ -1611,6 +1668,7 @@ const contlineartests = Dict("linear1" => linear1test,
16111668
"linear8c" => linear8ctest,
16121669
"linear9" => linear9test,
16131670
"linear10" => linear10test,
1671+
"linear10b" => linear10btest,
16141672
"linear11" => linear11test,
16151673
"linear12" => linear12test,
16161674
"linear13" => linear13test,

test/Test/contlinear.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@
112112
[(MOI.ScalarAffineFunction{Float64}, MOI.Interval{Float64}) => [MOI.NONBASIC_AT_UPPER],
113113
(MOI.SingleVariable, MOI.GreaterThan{Float64}) => [MOI.BASIC, MOI.BASIC]]))
114114
MOIT.linear10test(mock, config)
115+
MOIU.set_mock_optimize!(mock,
116+
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, [0.0, 0.0], con_basis =
117+
[(MOI.ScalarAffineFunction{Float64}, MOI.Interval{Float64}) => [MOI.BASIC],
118+
(MOI.SingleVariable, MOI.GreaterThan{Float64}) => [MOI.NONBASIC, MOI.NONBASIC]],
119+
(MOI.ScalarAffineFunction{Float64}, MOI.Interval{Float64}) => [0]))
120+
MOIT.linear10btest(mock, config)
121+
115122
MOIU.set_mock_optimize!(mock,
116123
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, [1.0, 1.0]),
117124
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, [0.5, 0.5]))

test/bridge.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,19 @@ end
518518
(MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}) => [MOI.NONBASIC],
519519
(MOI.SingleVariable, MOI.GreaterThan{Float64}) => [MOI.BASIC, MOI.BASIC]]))
520520
MOIT.linear10test(bridged_mock, config_with_basis)
521+
MOIU.set_mock_optimize!(mock,
522+
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, [0.0, 0.0], con_basis =
523+
[(MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) => [MOI.BASIC],
524+
(MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}) => [MOI.BASIC],
525+
(MOI.SingleVariable, MOI.GreaterThan{Float64}) => [MOI.NONBASIC, MOI.NONBASIC]],
526+
(MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) => [0],
527+
(MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}) => [0]))
528+
MOIT.linear10btest(bridged_mock, config_with_basis)
529+
521530
ci = first(MOI.get(bridged_mock, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{Float64}, MOI.Interval{Float64}}()))
522531
newf = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, -1.0], MOI.get(bridged_mock, MOI.ListOfVariableIndices())), 0.0)
523532
MOI.set(bridged_mock, MOI.ConstraintFunction(), ci, newf)
524533
@test MOI.get(bridged_mock, MOI.ConstraintFunction(), ci) newf
525-
@test MOI.get(bridged_mock, MOI.ConstraintBasisStatus(), ci) == MOI.NONBASIC_AT_UPPER
526534
test_delete_bridge(bridged_mock, ci, 2, ((MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}, 0),
527535
(MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}, 0)))
528536
end

0 commit comments

Comments
 (0)