Skip to content

Commit 4ea435d

Browse files
authored
Add test for infinite bounds on variable (#2133)
1 parent ee9643e commit 4ea435d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/Test/test_linear.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4064,6 +4064,47 @@ end
40644064

40654065
version_added(::typeof(test_linear_open_intervals)) = v"1.7.0"
40664066

4067+
"""
4068+
test_linear_variable_open_intervals(
4069+
model::MOI.ModelLike,
4070+
config::Config{T},
4071+
) where {T}
4072+
4073+
Test that the solver supports open-intervals like `(-Inf, u]`, `[l, Inf)`, and
4074+
`(-Inf, Inf)`.
4075+
"""
4076+
function test_linear_variable_open_intervals(
4077+
model::MOI.ModelLike,
4078+
config::Config{T},
4079+
) where {T}
4080+
@requires _supports(config, MOI.optimize!)
4081+
@requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.Interval{T})
4082+
x = MOI.add_variables(model, 3)
4083+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
4084+
f = T(1) * x[1] + T(-1) * x[2] + T(1) * x[3]
4085+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
4086+
MOI.add_constraint(model, x[1], MOI.Interval(typemin(T), T(1)))
4087+
MOI.add_constraint(model, x[2], MOI.Interval(T(-1), typemax(T)))
4088+
MOI.add_constraint(model, x[3], MOI.Interval(T(-1), T(1)))
4089+
MOI.optimize!(model)
4090+
@test (MOI.get(model, MOI.VariablePrimal(), x), T[1, -1, 1], config)
4091+
return
4092+
end
4093+
4094+
function setup_test(
4095+
::typeof(test_linear_variable_open_intervals),
4096+
model::MOIU.MockOptimizer,
4097+
::Config{T},
4098+
) where {T}
4099+
MOIU.set_mock_optimize!(
4100+
model,
4101+
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, T[1, -1, 1]),
4102+
)
4103+
return
4104+
end
4105+
4106+
version_added(::typeof(test_linear_variable_open_intervals)) = v"1.14.0"
4107+
40674108
"""
40684109
test_linear_HyperRectangle_VectorOfVariables(
40694110
model::MOI.ModelLike,

0 commit comments

Comments
 (0)