Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify test_conic_linear with forced bridging #2595

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 18 additions & 54 deletions src/Test/test_conic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,33 @@
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.

"""
_test_conic_linear_helper(
model::MOI.ModelLike,
config::Config,
use_VectorOfVariables::Bool,
)

A helper function for writing other conic tests.
test_conic_linear_VectorOfVariables(model::MOI.ModelLike, config::Config)

Constructs the problem:
Test a conic formulation of a linear program using standard conic form of the problem:
```
min -3x - 2y - 4z
st x + y + z == 3
y + z == 2
x>=0 y>=0 z>=0
Opt obj = -11, soln x = 1, y = 0, z = 2
```

"""
function _test_conic_linear_helper(
function test_conic_linear_VectorOfVariables(
model::MOI.ModelLike,
config::Config{T},
use_VectorOfVariables::Bool,
) where {T<:Real}
) where {T}
@requires MOI.supports_incremental_interface(model)
@requires MOI.supports(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
)
@requires MOI.supports(model, MOI.ObjectiveSense())
if use_VectorOfVariables
@requires MOI.supports_constraint(
model,
MOI.VectorOfVariables,
MOI.Nonnegatives,
)
else
@requires MOI.supports_constraint(
model,
MOI.VectorAffineFunction{T},
MOI.Nonnegatives,
)
end
@requires MOI.supports_constraint(
model,
MOI.VectorOfVariables,
MOI.Nonnegatives,
)
@requires MOI.supports_constraint(
model,
MOI.VectorAffineFunction{T},
Expand All @@ -54,15 +40,7 @@ function _test_conic_linear_helper(
v = MOI.add_variables(model, 3)
@test MOI.get(model, MOI.NumberOfVariables()) == 3
vov = MOI.VectorOfVariables(v)
if use_VectorOfVariables
vc = MOI.add_constraint(model, vov, MOI.Nonnegatives(3))
else
vc = MOI.add_constraint(
model,
MOI.VectorAffineFunction{T}(vov),
MOI.Nonnegatives(3),
)
end
vc = MOI.add_constraint(model, vov, MOI.Nonnegatives(3))
c = MOI.add_constraint(
model,
MOI.VectorAffineFunction(
Expand All @@ -78,8 +56,7 @@ function _test_conic_linear_helper(
@test MOI.get(
model,
MOI.NumberOfConstraints{
use_VectorOfVariables ? MOI.VectorOfVariables :
MOI.VectorAffineFunction{T},
MOI.VectorOfVariables,
MOI.Nonnegatives,
}(),
) == 1
Expand All @@ -91,8 +68,7 @@ function _test_conic_linear_helper(
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
@test length(loc) == 2
@test (
use_VectorOfVariables ? MOI.VectorOfVariables :
MOI.VectorAffineFunction{T},
MOI.VectorOfVariables,
MOI.Nonnegatives,
) in loc
@test (MOI.VectorAffineFunction{T}, MOI.Zeros) in loc
Expand Down Expand Up @@ -129,19 +105,6 @@ function _test_conic_linear_helper(
return
end

"""
test_conic_linear_VectorOfVariables(model::MOI.ModelLike, config::Config)

Test a conic formulation of a linear program using standard conic form.
"""
function test_conic_linear_VectorOfVariables(
model::MOI.ModelLike,
config::Config,
)
_test_conic_linear_helper(model, config, true)
return
end

function setup_test(
::typeof(test_conic_linear_VectorOfVariables),
model::MOIU.MockOptimizer,
Expand All @@ -161,13 +124,14 @@ end
"""
test_conic_linear_VectorAffineFunction(model::MOI.ModelLike, config::Config)

Test a conic formulation of a linear program using geometric conic form.
Test a conic formulation of a linear program using geometric conic form of
the same problem as [`test_conic_linear_VectorOfVariables`](@ref).
"""
function test_conic_linear_VectorAffineFunction(
model::MOI.ModelLike,
config::Config,
)
_test_conic_linear_helper(model, config, false)
config::Config{T},
) where {T}
test_conic_linear_VectorOfVariables(MOI.Bridges.Constraint.VectorFunctionize{T}(model), config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Because we can't nest SingleBridgeOptimizer and LazyBridgeOptimizer.

return
end

Expand Down
Loading