Skip to content

Commit 6222c56

Browse files
authored
[Test] add test for open Interval sets (#1969)
1 parent 300600a commit 6222c56

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/Test/test_linear.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4020,3 +4020,49 @@ function setup_test(
40204020
)
40214021
return
40224022
end
4023+
4024+
"""
4025+
test_linear_open_intervals(
4026+
model::MOI.ModelLike,
4027+
config::Config{T},
4028+
) where {T}
4029+
4030+
Test that the solver supports open-intervals like `(-Inf, u]`, `[l, Inf)`, and
4031+
`(-Inf, Inf)`.
4032+
"""
4033+
function test_linear_open_intervals(
4034+
model::MOI.ModelLike,
4035+
config::Config{T},
4036+
) where {T}
4037+
@requires _supports(config, MOI.optimize!)
4038+
@requires MOI.supports_constraint(
4039+
model,
4040+
MOI.ScalarAffineFunction{T},
4041+
MOI.Interval{T},
4042+
)
4043+
x = MOI.add_variables(model, 3)
4044+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
4045+
f = T(1) * x[1] + T(-1) * x[2] + T(1) * x[3]
4046+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
4047+
MOI.add_constraint(model, T(1) * x[1], MOI.Interval(typemin(T), T(1)))
4048+
MOI.add_constraint(model, T(1) * x[2], MOI.Interval(T(-1), typemax(T)))
4049+
MOI.add_constraint(model, T(1) * x[3], MOI.Interval(typemin(T), typemax(T)))
4050+
MOI.add_constraint(model, x[3], MOI.LessThan(T(1)))
4051+
MOI.optimize!(model)
4052+
@test (MOI.get(model, MOI.VariablePrimal(), x), T[1, -1, 1], config)
4053+
return
4054+
end
4055+
4056+
function setup_test(
4057+
::typeof(test_linear_open_intervals),
4058+
model::MOIU.MockOptimizer,
4059+
::Config{T},
4060+
) where {T}
4061+
MOIU.set_mock_optimize!(
4062+
model,
4063+
(mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, T[1, -1, 1]),
4064+
)
4065+
return
4066+
end
4067+
4068+
version_added(::typeof(test_linear_open_intervals)) = v"1.7.0"

0 commit comments

Comments
 (0)