Skip to content

Commit 35a5689

Browse files
committed
supports_constrained_variable -> supports_add_constrained_variable
1 parent 061f093 commit 35a5689

File tree

6 files changed

+41
-31
lines changed

6 files changed

+41
-31
lines changed

docs/src/apimanual.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ The `Bridges.Variable.Vectorize` is the bridge optimizer that applies the
10521052
the optimizer
10531053
```jldoctest; setup=:(optimizer = MOI.Utilities.Model{Float64}())
10541054
bridged_optimizer = MOI.Bridges.Variable.Vectorize{Float64}(optimizer)
1055-
MOI.supports_constrained_variable(bridged_optimizer, MOI.GreaterThan{Float64})
1055+
MOI.supports_add_constrained_variable(bridged_optimizer, MOI.GreaterThan{Float64})
10561056
10571057
# output
10581058
@@ -1143,9 +1143,9 @@ if `model` supports creating free variables. However, if `model` does not
11431143
support creating free variables, then it should only implement
11441144
[`add_constrained_variable`](@ref) and not [`add_variable`](@ref) nor
11451145
[`add_constraint`](@ref) for [`SingleVariable`](@ref)-in-`typeof(set)`.
1146-
In addition, it should implement `supports_constrained_variables(::Optimizer,
1146+
In addition, it should implement `supports_add_constrained_variables(::Optimizer,
11471147
::Type{Reals})` and return `false` so that free variables are bridged,
1148-
see [`supports_constrained_variables`](@ref).
1148+
see [`supports_add_constrained_variables`](@ref).
11491149

11501150
### Handling duplicate coefficients
11511151

docs/src/apireference.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ add_variable
224224
add_variables
225225
add_constrained_variable
226226
add_constrained_variables
227-
supports_constrained_variable
228-
supports_constrained_variables
227+
supports_add_constrained_variable
228+
supports_add_constrained_variables
229229
```
230230

231231
List of attributes associated with variables. [category AbstractVariableAttribute]
@@ -816,7 +816,7 @@ Bridges.added_constraint_types
816816
```
817817
Additionally, variable bridges should implement:
818818
```@docs
819-
Bridges.Variable.supports_constrained_variable
819+
Bridges.Variable.supports_add_constrained_variable
820820
Bridges.Variable.concrete_bridge_type
821821
Bridges.Variable.bridge_constrained_variable
822822
```

src/Test/contconic.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function _lin2test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool)
103103
@test MOI.supports(model, MOI.ObjectiveSense())
104104
if vecofvars
105105
@test MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.Nonnegatives)
106-
@test MOI.supports_constrained_variables(model, MOI.Nonpositives)
106+
@test MOI.supports_add_constrained_variables(model, MOI.Nonpositives)
107107
@test MOI.supports_constraint(model, MOI.VectorOfVariables, MOI.Zeros)
108108
else
109109
@test MOI.supports_constraint(model, MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives)
@@ -258,7 +258,7 @@ function lin4test(model::MOI.ModelLike, config::TestConfig)
258258
@test MOI.supports(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}())
259259
@test MOI.supports(model, MOI.ObjectiveSense())
260260
@test MOI.supports_constraint(model, MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives)
261-
@test MOI.supports_constrained_variables(model, MOI.Nonpositives)
261+
@test MOI.supports_add_constrained_variables(model, MOI.Nonpositives)
262262

263263
MOI.empty!(model)
264264
@test MOI.is_empty(model)
@@ -586,7 +586,7 @@ function _soc1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool)
586586
@test MOI.supports(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}())
587587
@test MOI.supports(model, MOI.ObjectiveSense())
588588
if vecofvars
589-
@test MOI.supports_constrained_variables(model, MOI.SecondOrderCone)
589+
@test MOI.supports_add_constrained_variables(model, MOI.SecondOrderCone)
590590
else
591591
@test MOI.supports_constraint(model, MOI.VectorAffineFunction{Float64}, MOI.SecondOrderCone)
592592
end
@@ -875,7 +875,7 @@ function _rotatedsoc1test(model::MOI.ModelLike, config::TestConfig, abvars::Bool
875875
@test MOI.supports(model, MOI.ObjectiveSense())
876876
if abvars
877877
@test MOI.supports_constraint(model, MOI.SingleVariable, MOI.EqualTo{Float64})
878-
@test MOI.supports_constrained_variables(model, MOI.RotatedSecondOrderCone)
878+
@test MOI.supports_add_constrained_variables(model, MOI.RotatedSecondOrderCone)
879879
else
880880
@test MOI.supports_constraint(model, MOI.VectorAffineFunction{Float64}, MOI.RotatedSecondOrderCone)
881881
end
@@ -977,7 +977,7 @@ function rotatedsoc2test(model::MOI.ModelLike, config::TestConfig)
977977
@test MOI.supports_constraint(model, MOI.SingleVariable,MOI.EqualTo{Float64})
978978
@test MOI.supports_constraint(model, MOI.SingleVariable,MOI.LessThan{Float64})
979979
@test MOI.supports_constraint(model, MOI.SingleVariable,MOI.GreaterThan{Float64})
980-
@test MOI.supports_constrained_variables(model, MOI.RotatedSecondOrderCone)
980+
@test MOI.supports_add_constrained_variables(model, MOI.RotatedSecondOrderCone)
981981

982982
MOI.empty!(model)
983983
@test MOI.is_empty(model)
@@ -1045,7 +1045,7 @@ function rotatedsoc3test(model::MOI.ModelLike, config::TestConfig; n=2, ub=3.0)
10451045
@test MOI.supports(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}())
10461046
@test MOI.supports(model, MOI.ObjectiveSense())
10471047
@test MOI.supports_constraint(model, MOI.SingleVariable, MOI.EqualTo{Float64})
1048-
@test MOI.supports_constrained_variables(model, MOI.Nonnegatives)
1048+
@test MOI.supports_add_constrained_variables(model, MOI.Nonnegatives)
10491049
@test MOI.supports_constraint(model, MOI.SingleVariable, MOI.GreaterThan{Float64})
10501050
@test MOI.supports_constraint(model, MOI.SingleVariable, MOI.LessThan{Float64})
10511051
@test MOI.supports_constraint(model, MOI.VectorAffineFunction{Float64}, MOI.RotatedSecondOrderCone)
@@ -1152,7 +1152,7 @@ function rotatedsoc4test(model::MOI.ModelLike, config::TestConfig; n=2, ub=3.0)
11521152
@test MOI.supports(model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}())
11531153
@test MOI.supports(model, MOI.ObjectiveSense())
11541154
@test MOI.supports_constraint(model, MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64})
1155-
@test MOI.supports_constrained_variables(model, MOI.RotatedSecondOrderCone)
1155+
@test MOI.supports_add_constrained_variables(model, MOI.RotatedSecondOrderCone)
11561156

11571157
MOI.empty!(model)
11581158
@test MOI.is_empty(model)

src/constraints.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ sum of a nonnegative and a nonpositive variables.
2929
""" # Implemented as only one method to avoid ambiguity
3030
function supports_constraint(model::ModelLike, F::Type{<:AbstractFunction},
3131
S::Type{<:AbstractSet})
32-
# TODO removed this condition, as `supports_constrained_variables(model, Reals)`
32+
# TODO removed this condition, as `supports_add_constrained_variables(model, Reals)`
3333
# should be called instead of
3434
# `supports_constraint(model, ::VectorOfVariables, ::Reals)
3535
if F === VectorOfVariables && S === Reals
36-
return supports_constrained_variables(model, Reals)
36+
return supports_add_constrained_variables(model, Reals)
3737
else
3838
return false
3939
end

src/variables.jl

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ done in the current state of the model `model`.
3535
add_variable(model::ModelLike) = throw(AddVariableNotAllowed())
3636

3737
"""
38-
supports_constrained_variable(
38+
supports_add_constrained_variable(
3939
model::ModelLike,
4040
S::Type{<:AbstractScalarSet}
4141
)::Bool
@@ -46,7 +46,7 @@ to belong to a set of type `S` either on creation of the variable with
4646
[`add_constraint`](@ref).
4747
4848
By default, this function falls back to
49-
`supports_constrained_variables(model, Reals) &&
49+
`supports_add_constrained_variables(model, Reals) &&
5050
supports_constraint(model, MOI.SingleVariable, S)` which is the correct
5151
definition for most models.
5252
@@ -61,9 +61,9 @@ lower bound on the same variable. Moreover, if the user adds a
6161
`SingleVariable`-in-`GreaterThan` constraint, it will transparently be bridged
6262
into a supported constraint.
6363
"""
64-
function supports_constrained_variable(model::ModelLike,
64+
function supports_add_constrained_variable(model::ModelLike,
6565
S::Type{<:AbstractScalarSet})
66-
return supports_constrained_variables(model, Reals) &&
66+
return supports_add_constrained_variables(model, Reals) &&
6767
supports_constraint(model, SingleVariable, S)
6868
end
6969

@@ -89,7 +89,7 @@ function add_constrained_variable(model::ModelLike, set::AbstractScalarSet)
8989
end
9090

9191
"""
92-
supports_constrained_variables(
92+
supports_add_constrained_variables(
9393
model::ModelLike,
9494
S::Type{<:AbstractScalarSet}
9595
)::Bool
@@ -100,7 +100,7 @@ variables with [`add_constrained_variables`](@ref) or after the variable is
100100
created with [`add_constraint`](@ref).
101101
102102
By default, if `S` is `Reals` then this function returns `true` and otherwise,
103-
it falls back to `supports_constrained_variables(model, Reals) &&
103+
it falls back to `supports_add_constrained_variables(model, Reals) &&
104104
supports_constraint(model, MOI.VectorOfVariables, S)` which is the correct
105105
definition for most models.
106106
@@ -109,10 +109,10 @@ definition for most models.
109109
In the standard conic form, the variables are grouped into several cones
110110
and the constraints are affine equality constraints.
111111
If `Reals` is not one of the cones supported by the solvers then it needs
112-
to implement `supports_constrained_variables(::Optimizer, ::Type{Reals}) = false`
112+
to implement `supports_add_constrained_variables(::Optimizer, ::Type{Reals}) = false`
113113
as free variables are not supported.
114114
The solvers should then implement
115-
`supports_constrained_variables(::Optimizer, ::Type{<:SupportedCones}) = true`
115+
`supports_add_constrained_variables(::Optimizer, ::Type{<:SupportedCones}) = true`
116116
where `SupportedCones` is the union of all cone types that are supported
117117
but it should not implement
118118
`supports_constraint(::Type{VectorOfVariables}, Type{<:SupportedCones})`
@@ -123,13 +123,23 @@ have already been created so they already belong to given cones.
123123
The constraint will therefore be bridged by adding slack variables in `S`
124124
and equality constraints ensuring that the slack variables are equal to the
125125
corresponding variables of the given constraint function.
126-
"""
127-
function supports_constrained_variables(model::ModelLike,
128-
S::Type{<:AbstractVectorSet})
129-
return supports_constrained_variables(model, Reals) &&
126+
127+
Note that there may also be sets for which
128+
`!supports_add_constrained_variables(model, S)` and
129+
`supports_constraint(model, MOI.VectorOfVariables, S)`.
130+
For instance, suppose a solver supports positive semidefinite variable
131+
constraints and two types of variables: binary variables and nonnegative
132+
variables. Then the solver should support adding
133+
`VectorOfVariables`-in-`PositiveSemidefiniteConeTriangle` constraints but it
134+
should not support creating variables constrained to belong to the
135+
`PositiveSemidefiniteConeTriangle` as free variables are not supported.
136+
"""
137+
function supports_add_constrained_variables(
138+
model::ModelLike, S::Type{<:AbstractVectorSet})
139+
return supports_add_constrained_variables(model, Reals) &&
130140
supports_constraint(model, VectorOfVariables, S)
131141
end
132-
supports_constrained_variables(::ModelLike, ::Type{Reals}) = true
142+
supports_add_constrained_variables(::ModelLike, ::Type{Reals}) = true
133143

134144
"""
135145
add_constrained_variables(

test/Utilities/model.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ struct DummySet <: MOI.AbstractScalarSet end
6161
@testset "`SingleVariable`-in-`S`" begin
6262
@test !MOI.supports_constraint(model, DummyFunction, DummySet)
6363
@test !MOI.supports_constraint(model, MOI.SingleVariable, DummySet)
64-
@test !MOI.supports_constrained_variable(model, DummySet)
64+
@test !MOI.supports_add_constrained_variable(model, DummySet)
6565
for S in [MOI.EqualTo{T}, MOI.GreaterThan{T}, MOI.LessThan{T},
6666
MOI.Interval{T}, MOI.Integer, MOI.ZeroOne,
6767
MOI.Semicontinuous{T}, MOI.Semiinteger{T}]
6868
@test MOI.supports_constraint(model, MOI.SingleVariable, S)
69-
@test MOI.supports_constrained_variable(model, S)
69+
@test MOI.supports_add_constrained_variable(model, S)
7070
end
7171
U = Float32
7272
for S in [MOI.EqualTo{U}, MOI.GreaterThan{U}, MOI.LessThan{U},
7373
MOI.Interval{U}, MOI.Semicontinuous{U}, MOI.Semiinteger{U}]
7474
@test !MOI.supports_constraint(model, MOI.SingleVariable, S)
75-
@test !MOI.supports_constrained_variable(model, S)
75+
@test !MOI.supports_add_constrained_variable(model, S)
7676
end
7777
end
7878
end

0 commit comments

Comments
 (0)