@@ -1891,31 +1891,37 @@ Base.:(==)(a::SOS2{T}, b::SOS2{T}) where {T} = a.weights == b.weights
1891
1891
""" ,
1892
1892
ActivationCondition,
1893
1893
"""
1894
- The indicator constraint holds whhen the binary variable is zero.
1894
+ The indicator constraint holds when the binary variable is zero.
1895
1895
""" ,
1896
1896
ACTIVATE_ON_ZERO,
1897
1897
"""
1898
- The indicator constraint holds whhen the binary variable is one.
1898
+ The indicator constraint holds when the binary variable is one.
1899
1899
""" ,
1900
1900
ACTIVATE_ON_ONE,
1901
1901
)
1902
1902
1903
1903
"""
1904
- Indicator{A<:ActivationCondition,S<:AbstractScalarSet}(set::S)
1904
+ Indicator{ACTIVATE_ON_ZERO}(set::AbstractScalarSet)
1905
+ Indicator{ACTIVATE_ON_ONE}(set::AbstractScalarSet)
1905
1906
1906
1907
The set corresponding to an indicator constraint.
1907
1908
1908
- When `A` is [`ACTIVATE_ON_ZERO`](@ref), this means:
1909
- ``\\ {(y, x) \\ in \\ {0, 1\\ } \\ times \\ mathbb{R}^n : y = 0 \\ implies x \\ in set\\ }``
1909
+ The type parameter must be an [`ActivationCondition`](@ref).
1910
1910
1911
- When `A` is [`ACTIVATE_ON_ONE`](@ref), this means:
1912
- ``\\ {(y, x) \\ in \\ {0, 1\\ } \\ times \\ mathbb{R}^n : y = 1 \\ implies x \\ in set\\ }``
1911
+ When the type parameter is [`ACTIVATE_ON_ZERO`](@ref), this means:
1912
+
1913
+ ``\\ {(y, x) \\ in \\ {0, 1\\ } \\ times \\ mathbb{R} : y = 0 \\ implies x \\ in set\\ }``
1914
+
1915
+ When the type parameter is [`ACTIVATE_ON_ONE`](@ref), this means:
1916
+
1917
+ ``\\ {(y, x) \\ in \\ {0, 1\\ } \\ times \\ mathbb{R} : y = 1 \\ implies x \\ in set\\ }``
1913
1918
1914
1919
## Notes
1915
1920
1916
1921
Most solvers expect that the first row of the function is interpretable as a
1917
- variable index `x_i` (for example, `1.0 * x + 0.0`). An error will be thrown if this is
1918
- not the case.
1922
+ [`VariableIndex`](@ref) (for example, `1.0 * x + 0.0`), and that the variable is
1923
+ constrained to the [`ZeroOne`](@ref) set. An error will be thrown if this is not
1924
+ the case.
1919
1925
1920
1926
## Example
1921
1927
@@ -1927,22 +1933,11 @@ julia> import MathOptInterface as MOI
1927
1933
1928
1934
julia> model = MOI.Utilities.Model{Float64}();
1929
1935
1930
- julia> x = MOI.add_variables(model, 2)
1931
- 2-element Vector{MathOptInterface.VariableIndex}:
1932
- MOI.VariableIndex(1)
1933
- MOI.VariableIndex(2)
1936
+ julia> x = MOI.add_variables(model, 2);
1934
1937
1935
- julia> y, _ = MOI.add_constrained_variable(model, MOI.ZeroOne())
1936
- (MOI.VariableIndex(3), MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex, MathOptInterface.ZeroOne}(3))
1938
+ julia> y, _ = MOI.add_constrained_variable(model, MOI.ZeroOne());
1937
1939
1938
- julia> f = MOI.VectorAffineFunction(
1939
- [
1940
- MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, y)),
1941
- MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, x[1])),
1942
- MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(1.0, x[2])),
1943
- ],
1944
- [0.0, 0.0],
1945
- )
1940
+ julia> f = MOI.Utilities.vectorize([y, 1.0 * x[1] + 1.0 * x[2]])
1946
1941
┌ ┐
1947
1942
│0.0 + 1.0 MOI.VariableIndex(3) │
1948
1943
│0.0 + 1.0 MOI.VariableIndex(1) + 1.0 MOI.VariableIndex(2)│
@@ -1954,10 +1949,37 @@ MathOptInterface.Indicator{MathOptInterface.ACTIVATE_ON_ONE, MathOptInterface.Le
1954
1949
julia> MOI.add_constraint(model, f, s)
1955
1950
MathOptInterface.ConstraintIndex{MathOptInterface.VectorAffineFunction{Float64}, MathOptInterface.Indicator{MathOptInterface.ACTIVATE_ON_ONE, MathOptInterface.LessThan{Float64}}}(1)
1956
1951
```
1952
+
1953
+ The constraint
1954
+ ``\\ {(y, x) \\ in \\ {0, 1\\ } \\ times \\ mathbb{R} : y = 0 \\ implies x = 0 \\ }``
1955
+ is defined as
1956
+ ```jldoctest
1957
+ julia> import MathOptInterface as MOI
1958
+
1959
+ julia> model = MOI.Utilities.Model{Float64}();
1960
+
1961
+ julia> x = MOI.add_variable(model);
1962
+
1963
+ julia> y, _ = MOI.add_constrained_variable(model, MOI.ZeroOne());
1964
+
1965
+ julia> f = MOI.VectorOfVariables([y, x]);
1966
+
1967
+ julia> s = MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.EqualTo(0.0))
1968
+ MathOptInterface.Indicator{MathOptInterface.ACTIVATE_ON_ZERO, MathOptInterface.EqualTo{Float64}}(MathOptInterface.EqualTo{Float64}(0.0))
1969
+
1970
+ julia> MOI.add_constraint(model, f, s)
1971
+ MathOptInterface.ConstraintIndex{MathOptInterface.VectorOfVariables, MathOptInterface.Indicator{MathOptInterface.ACTIVATE_ON_ZERO, MathOptInterface.EqualTo{Float64}}}(1)
1972
+ ```
1957
1973
"""
1958
1974
struct Indicator{A,S<: AbstractScalarSet } <: AbstractVectorSet
1959
1975
set:: S
1960
- Indicator {A} (set:: S ) where {A,S<: AbstractScalarSet } = new {A,S} (set)
1976
+
1977
+ function Indicator {ACTIVATE_ON_ONE} (set:: S ) where {S<: AbstractScalarSet }
1978
+ return new {ACTIVATE_ON_ONE,S} (set)
1979
+ end
1980
+ function Indicator {ACTIVATE_ON_ZERO} (set:: S ) where {S<: AbstractScalarSet }
1981
+ return new {ACTIVATE_ON_ZERO,S} (set)
1982
+ end
1961
1983
end
1962
1984
1963
1985
dimension (:: Indicator ) = 2
0 commit comments