Skip to content

Commit fadc3ee

Browse files
committed
Simplify test_conic_linear with forced bridging
1 parent e4ce984 commit fadc3ee

File tree

1 file changed

+19
-55
lines changed

1 file changed

+19
-55
lines changed

src/Test/test_conic.jl

Lines changed: 19 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,33 @@
55
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
66

77
"""
8-
_test_conic_linear_helper(
9-
model::MOI.ModelLike,
10-
config::Config,
11-
use_VectorOfVariables::Bool,
12-
)
13-
14-
A helper function for writing other conic tests.
8+
test_conic_linear_VectorOfVariables(model::MOI.ModelLike, config::Config)
159
16-
Constructs the problem:
10+
Test a conic formulation of a linear program using standard conic form of the problem:
1711
```
1812
min -3x - 2y - 4z
1913
st x + y + z == 3
2014
y + z == 2
2115
x>=0 y>=0 z>=0
2216
Opt obj = -11, soln x = 1, y = 0, z = 2
2317
```
18+
2419
"""
25-
function _test_conic_linear_helper(
20+
function test_conic_linear_VectorOfVariables(
2621
model::MOI.ModelLike,
27-
config::Config{T},
28-
use_VectorOfVariables::Bool,
29-
) where {T<:Real}
22+
config::Config,
23+
)
3024
@requires MOI.supports_incremental_interface(model)
3125
@requires MOI.supports(
3226
model,
3327
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(),
3428
)
3529
@requires MOI.supports(model, MOI.ObjectiveSense())
36-
if use_VectorOfVariables
37-
@requires MOI.supports_constraint(
38-
model,
39-
MOI.VectorOfVariables,
40-
MOI.Nonnegatives,
41-
)
42-
else
43-
@requires MOI.supports_constraint(
44-
model,
45-
MOI.VectorAffineFunction{T},
46-
MOI.Nonnegatives,
47-
)
48-
end
30+
@requires MOI.supports_constraint(
31+
model,
32+
MOI.VectorOfVariables,
33+
MOI.Nonnegatives,
34+
)
4935
@requires MOI.supports_constraint(
5036
model,
5137
MOI.VectorAffineFunction{T},
@@ -54,15 +40,7 @@ function _test_conic_linear_helper(
5440
v = MOI.add_variables(model, 3)
5541
@test MOI.get(model, MOI.NumberOfVariables()) == 3
5642
vov = MOI.VectorOfVariables(v)
57-
if use_VectorOfVariables
58-
vc = MOI.add_constraint(model, vov, MOI.Nonnegatives(3))
59-
else
60-
vc = MOI.add_constraint(
61-
model,
62-
MOI.VectorAffineFunction{T}(vov),
63-
MOI.Nonnegatives(3),
64-
)
65-
end
43+
vc = MOI.add_constraint(model, vov, MOI.Nonnegatives(3))
6644
c = MOI.add_constraint(
6745
model,
6846
MOI.VectorAffineFunction(
@@ -78,8 +56,7 @@ function _test_conic_linear_helper(
7856
@test MOI.get(
7957
model,
8058
MOI.NumberOfConstraints{
81-
use_VectorOfVariables ? MOI.VectorOfVariables :
82-
MOI.VectorAffineFunction{T},
59+
MOI.VectorOfVariables,
8360
MOI.Nonnegatives,
8461
}(),
8562
) == 1
@@ -91,8 +68,7 @@ function _test_conic_linear_helper(
9168
loc = MOI.get(model, MOI.ListOfConstraintTypesPresent())
9269
@test length(loc) == 2
9370
@test (
94-
use_VectorOfVariables ? MOI.VectorOfVariables :
95-
MOI.VectorAffineFunction{T},
71+
MOI.VectorOfVariables,
9672
MOI.Nonnegatives,
9773
) in loc
9874
@test (MOI.VectorAffineFunction{T}, MOI.Zeros) in loc
@@ -129,19 +105,6 @@ function _test_conic_linear_helper(
129105
return
130106
end
131107

132-
"""
133-
test_conic_linear_VectorOfVariables(model::MOI.ModelLike, config::Config)
134-
135-
Test a conic formulation of a linear program using standard conic form.
136-
"""
137-
function test_conic_linear_VectorOfVariables(
138-
model::MOI.ModelLike,
139-
config::Config,
140-
)
141-
_test_conic_linear_helper(model, config, true)
142-
return
143-
end
144-
145108
function setup_test(
146109
::typeof(test_conic_linear_VectorOfVariables),
147110
model::MOIU.MockOptimizer,
@@ -161,13 +124,14 @@ end
161124
"""
162125
test_conic_linear_VectorAffineFunction(model::MOI.ModelLike, config::Config)
163126
164-
Test a conic formulation of a linear program using geometric conic form.
127+
Test a conic formulation of a linear program using geometric conic form of
128+
the same problem as [`test_conic_linear_VectorOfVariables`](@ref).
165129
"""
166130
function test_conic_linear_VectorAffineFunction(
167131
model::MOI.ModelLike,
168-
config::Config,
169-
)
170-
_test_conic_linear_helper(model, config, false)
132+
config::Config{T},
133+
) where {T}
134+
test_conic_linear_VectorOfVariables(MOI.Bridges.Constraint.VectorFunctionize{T}(model), config)
171135
return
172136
end
173137

0 commit comments

Comments
 (0)