From 2a616df514ecfed173113d192791c5ed64604911 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 18 Jul 2021 04:57:58 +0200 Subject: [PATCH 01/11] Rename IndicatorSet to Indicator. This is more consistent with the naming of the other sets. --- NEWS.md | 3 ++- docs/src/manual/constraints.md | 2 +- docs/src/manual/standard_form.md | 2 +- docs/src/reference/standard_form.md | 2 +- .../Constraint/indicator_activate_on_zero.jl | 14 ++++++------ src/Bridges/Constraint/indicator_sos.jl | 10 ++++----- .../UnitTests/basic_constraint_tests.jl | 8 +++---- src/DeprecatedTest/intlinear.jl | 22 +++++++++---------- src/FileFormats/MOF/MOF.jl | 2 +- src/FileFormats/MOF/mof.0.6.schema.json | 4 ++-- src/FileFormats/MOF/read.jl | 6 ++--- src/FileFormats/MOF/write.jl | 4 ++-- src/Test/test_basic_constraint.jl | 12 +++++----- src/Test/test_linear.jl | 22 +++++++++---------- src/Utilities/model.jl | 4 ++-- src/sets.jl | 22 +++++++++---------- .../Constraint/indicator_activate_on_zero.jl | 2 +- test/Bridges/Constraint/indicator_sos.jl | 12 +++++----- test/Bridges/lazy_bridge_optimizer.jl | 18 +++++++-------- test/FileFormats/MOF/MOF.jl | 4 ++-- test/sets.jl | 14 ++++++------ 21 files changed, 95 insertions(+), 94 deletions(-) diff --git a/NEWS.md b/NEWS.md index b941676ecf..39f73214e3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,7 +18,8 @@ Breaking renames and type changes: - `Constraint.SOCRBridge` has been renamed to `Constraint.SOCtoRSOCBridge` - `RawParameter` has been renamed to `RawOptimizerAttribute` and now takes `String` instead of `Any` as the only argument -- `Test.TestConfig` has been renamed to `Test.Config` +- `Test.TestConfig` has been renamed to `Test.Config` +- `IndicatorSet` has been renamed to `Indicator` Breaking behavior changes: diff --git a/docs/src/manual/constraints.md b/docs/src/manual/constraints.md index b7a3df04e2..64bc478bda 100644 --- a/docs/src/manual/constraints.md +++ b/docs/src/manual/constraints.md @@ -172,7 +172,7 @@ where ``\mathcal{E}`` is the exponential cone (see [`ExponentialCone`](@ref)), | ``x_i \in \{0\} \cup \{l,l+1,\ldots,u-1,u\}`` | `SingleVariable` | `Semiinteger` | | At most one component of ``x`` can be nonzero | `VectorOfVariables` | `SOS1` | | At most two components of ``x`` can be nonzero, and if so they must be adjacent components | `VectorOfVariables` | `SOS2` | -| ``y = 1 \implies a^T x \in S`` | `VectorAffineFunction` | `IndicatorSet` | +| ``y = 1 \implies a^T x \in S`` | `VectorAffineFunction` | `Indicator` | ## JuMP mapping diff --git a/docs/src/manual/standard_form.md b/docs/src/manual/standard_form.md index e4600da18f..4a0fcc9343 100644 --- a/docs/src/manual/standard_form.md +++ b/docs/src/manual/standard_form.md @@ -149,7 +149,7 @@ or solver developers. A special ordered set of Type I. * [`SOS2(weights)`](@ref MathOptInterface.SOS2): A special ordered set of Type II. -* [`IndicatorSet(set)`](@ref MathOptInterface.IndicatorSet): +* [`Indicator(set)`](@ref MathOptInterface.Indicator): A set to specify indicator constraints. * [`Complements`](@ref MathOptInterface.Complements): A set for mixed complementarity constraints. diff --git a/docs/src/reference/standard_form.md b/docs/src/reference/standard_form.md index d3ad803b4f..c0b33bfad3 100644 --- a/docs/src/reference/standard_form.md +++ b/docs/src/reference/standard_form.md @@ -91,7 +91,7 @@ NormSpectralCone NormNuclearCone SOS1 SOS2 -IndicatorSet +Indicator Complements ``` diff --git a/src/Bridges/Constraint/indicator_activate_on_zero.jl b/src/Bridges/Constraint/indicator_activate_on_zero.jl index f787e1f86b..4c943866eb 100644 --- a/src/Bridges/Constraint/indicator_activate_on_zero.jl +++ b/src/Bridges/Constraint/indicator_activate_on_zero.jl @@ -21,7 +21,7 @@ struct IndicatorActiveOnFalseBridge{ } indicator_cons_index::MOI.ConstraintIndex{ F, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,S}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,S}, } end @@ -34,7 +34,7 @@ function bridge_constraint( S<:MOI.AbstractScalarSet, T<:Real, F, - IS<:MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO,S}, + IS<:MOI.Indicator{MOI.ACTIVATE_ON_ZERO,S}, } f_scalars = MOIU.eachscalar(f) z2, zo_cons = MOI.add_constrained_variable(model, MOI.ZeroOne()) @@ -45,7 +45,7 @@ function bridge_constraint( ci = MOI.add_constraint( model, f2, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(s.set), + MOI.Indicator{MOI.ACTIVATE_ON_ONE}(s.set), ) return IndicatorActiveOnFalseBridge{T,F,S}(z2, zo_cons, dcons, ci) end @@ -53,7 +53,7 @@ end function MOI.supports_constraint( ::Type{<:IndicatorActiveOnFalseBridge{T}}, ::Type{<:MOI.VectorAffineFunction}, - ::Type{<:MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO}}, + ::Type{<:MOI.Indicator{MOI.ACTIVATE_ON_ZERO}}, ) where {T} return true end @@ -69,14 +69,14 @@ function MOIB.added_constraint_types( ) where {T,F,S} return [ (MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}), - (F, MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,S}), + (F, MOI.Indicator{MOI.ACTIVATE_ON_ONE,S}), ] end function concrete_bridge_type( ::Type{<:IndicatorActiveOnFalseBridge{T}}, ::Type{F}, - ::Type{MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO,S}}, + ::Type{MOI.Indicator{MOI.ACTIVATE_ON_ZERO,S}}, ) where {T,F<:MOI.VectorAffineFunction,S<:MOI.AbstractScalarSet} return IndicatorActiveOnFalseBridge{T,F,S} end @@ -84,7 +84,7 @@ end function concrete_bridge_type( ::Type{<:IndicatorActiveOnFalseBridge}, ::Type{F}, - ::Type{MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO,S}}, + ::Type{MOI.Indicator{MOI.ACTIVATE_ON_ZERO,S}}, ) where {F<:MOI.VectorAffineFunction,S<:MOI.AbstractScalarSet} return IndicatorActiveOnFalseBridge{Float64,F,S} end diff --git a/src/Bridges/Constraint/indicator_sos.jl b/src/Bridges/Constraint/indicator_sos.jl index 2f74789e7a..266263e821 100644 --- a/src/Bridges/Constraint/indicator_sos.jl +++ b/src/Bridges/Constraint/indicator_sos.jl @@ -30,7 +30,7 @@ function bridge_constraint( ::Type{IndicatorSOS1Bridge{T,BC,MaybeBC}}, model::MOI.ModelLike, f::MOI.VectorAffineFunction{T}, - s::MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,BC}, + s::MOI.Indicator{MOI.ACTIVATE_ON_ONE,BC}, ) where {T<:Real,BC,MaybeBC} f_scalars = MOIU.eachscalar(f) (w, bound_constraint) = _add_bound_constraint!(model, BC) @@ -68,7 +68,7 @@ end function MOI.supports_constraint( ::Type{<:IndicatorSOS1Bridge}, ::Type{<:MOI.AbstractVectorFunction}, - ::Type{<:MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,<:MOI.AbstractScalarSet}}, + ::Type{<:MOI.Indicator{MOI.ACTIVATE_ON_ONE,<:MOI.AbstractScalarSet}}, ) return true end @@ -78,7 +78,7 @@ function MOI.get( attr::MOI.ConstraintSet, b::IndicatorSOS1Bridge, ) - return MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}( + return MOI.Indicator{MOI.ACTIVATE_ON_ONE}( MOI.get(model, attr, b.linear_constraint_index), ) end @@ -139,7 +139,7 @@ end function concrete_bridge_type( ::Type{<:IndicatorSOS1Bridge{T}}, ::Type{<:MOI.AbstractVectorFunction}, - ::Type{MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,S}}, + ::Type{MOI.Indicator{MOI.ACTIVATE_ON_ONE,S}}, ) where {T,S<:Union{MOI.LessThan,MOI.GreaterThan}} return IndicatorSOS1Bridge{T,S,MOI.ConstraintIndex{MOI.SingleVariable,S}} end @@ -147,7 +147,7 @@ end function concrete_bridge_type( ::Type{<:IndicatorSOS1Bridge{T}}, ::Type{<:MOI.AbstractVectorFunction}, - ::Type{MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,S}}, + ::Type{MOI.Indicator{MOI.ACTIVATE_ON_ONE,S}}, ) where {T,S<:MOI.AbstractScalarSet} return IndicatorSOS1Bridge{T,S,Nothing} end diff --git a/src/DeprecatedTest/UnitTests/basic_constraint_tests.jl b/src/DeprecatedTest/UnitTests/basic_constraint_tests.jl index eebe5d891a..bc3422e7da 100644 --- a/src/DeprecatedTest/UnitTests/basic_constraint_tests.jl +++ b/src/DeprecatedTest/UnitTests/basic_constraint_tests.jl @@ -143,19 +143,19 @@ const BasicConstraintTests = Dict( (MOI.VectorAffineFunction{Float64}, MOI.PositiveSemidefiniteConeSquare) => (dummy_vector_affine, 9, MOI.PositiveSemidefiniteConeSquare(3)), ( MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) => ( dummy_vector_affine, 2, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(3.0)), + MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(3.0)), ), ( MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.GreaterThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.GreaterThan{Float64}}, ) => ( dummy_vector_affine, 2, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(3.0)), + MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(3.0)), ), (MOI.VectorQuadraticFunction{Float64}, MOI.Zeros) => (dummy_vector_quadratic, 2, MOI.Zeros(2)), diff --git a/src/DeprecatedTest/intlinear.jl b/src/DeprecatedTest/intlinear.jl index 852ae5e7a9..be9d998617 100644 --- a/src/DeprecatedTest/intlinear.jl +++ b/src/DeprecatedTest/intlinear.jl @@ -551,7 +551,7 @@ function indicator1_test(model::MOI.ModelLike, config::Config) @test MOI.supports_constraint( model, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) x1 = MOI.add_variable(model) x2 = MOI.add_variable(model) @@ -566,7 +566,7 @@ function indicator1_test(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) MOI.add_constraint(model, f1, iset1) f2 = MOI.VectorAffineFunction( [ @@ -576,7 +576,7 @@ function indicator1_test(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) MOI.add_constraint(model, f2, iset2) # Additional regular constraint. MOI.add_constraint( @@ -648,7 +648,7 @@ function indicator2_test(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) MOI.add_constraint(model, f1, iset1) f2 = MOI.VectorAffineFunction( [ @@ -658,7 +658,7 @@ function indicator2_test(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) MOI.add_constraint(model, f2, iset2) # additional regular constraint MOI.add_constraint( @@ -737,7 +737,7 @@ function indicator3_test(model::MOI.ModelLike, config::Config) @test MOI.supports_constraint( model, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) x1 = MOI.add_variable(model) x2 = MOI.add_variable(model) @@ -754,7 +754,7 @@ function indicator3_test(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO}(MOI.LessThan(8.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.LessThan(8.0)) MOI.add_constraint(model, f1, iset1) f2 = MOI.VectorAffineFunction( [ @@ -764,7 +764,7 @@ function indicator3_test(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) MOI.add_constraint(model, f2, iset2) # Additional regular constraint. MOI.add_constraint( @@ -842,7 +842,7 @@ function indicator4_test(model::MOI.ModelLike, config::Config) @test MOI.supports_constraint( model, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) x1 = MOI.add_variable(model) x2 = MOI.add_variable(model) @@ -857,7 +857,7 @@ function indicator4_test(model::MOI.ModelLike, config::Config) ], [0.0, -1.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(7.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(7.0)) MOI.add_constraint(model, f1, iset1) f2 = MOI.VectorAffineFunction( [ @@ -867,7 +867,7 @@ function indicator4_test(model::MOI.ModelLike, config::Config) ], [0.0, 1.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(10.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(10.0)) MOI.add_constraint(model, f2, iset2) # Additional regular constraint. MOI.add_constraint( diff --git a/src/FileFormats/MOF/MOF.jl b/src/FileFormats/MOF/MOF.jl index 6aa24518ac..a42c86dd04 100644 --- a/src/FileFormats/MOF/MOF.jl +++ b/src/FileFormats/MOF/MOF.jl @@ -64,7 +64,7 @@ MOI.Utilities.@model( (MOI.VectorAffineFunction, MOI.VectorQuadraticFunction) ) -# IndicatorSet is handled by UniversalFallback. +# Indicator is handled by UniversalFallback. const Model = MOI.Utilities.UniversalFallback{InnerModel{Float64}} diff --git a/src/FileFormats/MOF/mof.0.6.schema.json b/src/FileFormats/MOF/mof.0.6.schema.json index 031e10ab37..a5d1615950 100644 --- a/src/FileFormats/MOF/mof.0.6.schema.json +++ b/src/FileFormats/MOF/mof.0.6.schema.json @@ -769,11 +769,11 @@ } }, { "description": "If `activate_on=one`: (y, x) ∈ {0,1}×Rᴺ: y = 0 ⟹ x ∈ S, otherwise when `activate_on=zero`: (y, x) ∈ {0,1}×Rᴺ: y = 1 ⟹ x ∈ S.", - "examples": ["{\"type\": \"IndicatorSet\", \"set\": {\"type\": \"LessThan\", \"upper\": 2.0}, \"activate_on\": \"one\"}"], + "examples": ["{\"type\": \"Indicator\", \"set\": {\"type\": \"LessThan\", \"upper\": 2.0}, \"activate_on\": \"one\"}"], "required": ["set", "activate_on"], "properties": { "type": { - "const": "IndicatorSet" + "const": "Indicator" }, "set": { "oneOf": [{ diff --git a/src/FileFormats/MOF/read.jl b/src/FileFormats/MOF/read.jl index 15f9bbafb9..e35c464b7c 100644 --- a/src/FileFormats/MOF/read.jl +++ b/src/FileFormats/MOF/read.jl @@ -311,7 +311,7 @@ end DualPowerCone, SOS1, SOS2, - IndicatorSet, + Indicator, Complements, ) @@ -469,7 +469,7 @@ function set_to_moi(::Val{:SOS2}, object::Object) return MOI.SOS2(Float64.(object["weights"])) end -function set_to_moi(::Val{:IndicatorSet}, object::Object) +function set_to_moi(::Val{:Indicator}, object::Object) set = set_to_moi(object["set"]::typeof(object)) indicator = if object["activate_on"]::String == "one" MOI.ACTIVATE_ON_ONE @@ -477,5 +477,5 @@ function set_to_moi(::Val{:IndicatorSet}, object::Object) @assert object["activate_on"]::String == "zero" MOI.ACTIVATE_ON_ZERO end - return MOI.IndicatorSet{indicator}(set) + return MOI.Indicator{indicator}(set) end diff --git a/src/FileFormats/MOF/write.jl b/src/FileFormats/MOF/write.jl index 675eb3f3c8..7d3354e36f 100644 --- a/src/FileFormats/MOF/write.jl +++ b/src/FileFormats/MOF/write.jl @@ -295,12 +295,12 @@ head_name(::Type{<:MOI.SOS1}) = "SOS1" head_name(::Type{<:MOI.SOS2}) = "SOS2" function moi_to_object( - set::MOI.IndicatorSet{I,S}, + set::MOI.Indicator{I,S}, name_map::Dict{MOI.VariableIndex,String}, ) where {I,S} @assert I == MOI.ACTIVATE_ON_ONE || I == MOI.ACTIVATE_ON_ZERO return OrderedObject( - "type" => "IndicatorSet", + "type" => "Indicator", "set" => moi_to_object(set.set, name_map), "activate_on" => (I == MOI.ACTIVATE_ON_ONE) ? "one" : "zero", ) diff --git a/src/Test/test_basic_constraint.jl b/src/Test/test_basic_constraint.jl index 494a22a3bc..4dd815b443 100644 --- a/src/Test/test_basic_constraint.jl +++ b/src/Test/test_basic_constraint.jl @@ -105,15 +105,15 @@ _set(::Type{MOI.RootDetConeSquare}) = MOI.RootDetConeSquare(3) _set(::Type{MOI.Complements}) = MOI.Complements(2) function _set( - ::Type{MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}}, + ::Type{MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}}, ) - return MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(3.0)) + return MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(3.0)) end function _set( - ::Type{MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.GreaterThan{Float64}}}, + ::Type{MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.GreaterThan{Float64}}}, ) - return MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(3.0)) + return MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(3.0)) end function _basic_constraint_test_helper( @@ -281,7 +281,7 @@ function test_basic_VectorAffineFunction_Indicator_LessThan( model, config, MOI.VectorAffineFunction, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) return end @@ -294,7 +294,7 @@ function test_basic_VectorAffineFunction_Indicator_GreaterThan( model, config, MOI.VectorAffineFunction, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.GreaterThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.GreaterThan{Float64}}, ) return end diff --git a/src/Test/test_linear.jl b/src/Test/test_linear.jl index 045ab03889..f71ea70f27 100644 --- a/src/Test/test_linear.jl +++ b/src/Test/test_linear.jl @@ -3497,7 +3497,7 @@ function test_linear_Indicator_integration(model::MOI.ModelLike, config::Config) @requires MOI.supports_constraint( model, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) x1 = MOI.add_variable(model) x2 = MOI.add_variable(model) @@ -3512,7 +3512,7 @@ function test_linear_Indicator_integration(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) MOI.add_constraint(model, f1, iset1) f2 = MOI.VectorAffineFunction( [ @@ -3522,7 +3522,7 @@ function test_linear_Indicator_integration(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) MOI.add_constraint(model, f2, iset2) # Additional regular constraint. MOI.add_constraint( @@ -3604,7 +3604,7 @@ function test_linear_Indicator_ON_ONE(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) MOI.add_constraint(model, f1, iset1) f2 = MOI.VectorAffineFunction( [ @@ -3614,7 +3614,7 @@ function test_linear_Indicator_ON_ONE(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) MOI.add_constraint(model, f2, iset2) # additional regular constraint MOI.add_constraint( @@ -3703,7 +3703,7 @@ function test_linear_Indicator_ON_ZERO(model::MOI.ModelLike, config::Config) @requires MOI.supports_constraint( model, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) x1 = MOI.add_variable(model) x2 = MOI.add_variable(model) @@ -3720,7 +3720,7 @@ function test_linear_Indicator_ON_ZERO(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO}(MOI.LessThan(8.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.LessThan(8.0)) MOI.add_constraint(model, f1, iset1) f2 = MOI.VectorAffineFunction( [ @@ -3730,7 +3730,7 @@ function test_linear_Indicator_ON_ZERO(model::MOI.ModelLike, config::Config) ], [0.0, 0.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) MOI.add_constraint(model, f2, iset2) # Additional regular constraint. MOI.add_constraint( @@ -3822,7 +3822,7 @@ function test_linear_Indicator_constant_term( @requires MOI.supports_constraint( model, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) x1 = MOI.add_variable(model) x2 = MOI.add_variable(model) @@ -3837,7 +3837,7 @@ function test_linear_Indicator_constant_term( ], [0.0, -1.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(7.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(7.0)) MOI.add_constraint(model, f1, iset1) f2 = MOI.VectorAffineFunction( [ @@ -3847,7 +3847,7 @@ function test_linear_Indicator_constant_term( ], [0.0, 1.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(10.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(10.0)) MOI.add_constraint(model, f2, iset2) # Additional regular constraint. MOI.add_constraint( diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index bb7d389217..39f6952010 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -887,9 +887,9 @@ for (loop_name, loop_super_type) in [ end const LessThanIndicatorSetOne{T} = - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{T}} + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{T}} const LessThanIndicatorSetZero{T} = - MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO,MOI.LessThan{T}} + MOI.Indicator{MOI.ACTIVATE_ON_ZERO,MOI.LessThan{T}} @model( Model, diff --git a/src/sets.jl b/src/sets.jl index f94a94c13e..39f7477e66 100644 --- a/src/sets.jl +++ b/src/sets.jl @@ -986,7 +986,7 @@ dimension(s::Union{SOS1,SOS2}) = length(s.weights) ActivationCondition Activation condition for an indicator constraint. -The enum value is used as first type parameter of `IndicatorSet{A,S}`. +The enum value is used as first type parameter of `Indicator{A,S}`. """ @enum ActivationCondition begin ACTIVATE_ON_ZERO @@ -994,7 +994,7 @@ The enum value is used as first type parameter of `IndicatorSet{A,S}`. end """ - IndicatorSet{A, S <: AbstractScalarSet}(set::S) + Indicator{A, S <: AbstractScalarSet}(set::S) ``\\{(y, x) \\in \\{0, 1\\} \\times \\mathbb{R}^n : y = 0 \\implies x \\in set\\}`` when `A` is `ACTIVATE_ON_ZERO` and @@ -1003,7 +1003,7 @@ when `A` is `ACTIVATE_ON_ONE`. `S` has to be a sub-type of `AbstractScalarSet`. `A` is one of the value of the `ActivationCond` enum. -`IndicatorSet` is used with a `VectorAffineFunction` holding +`Indicator` is used with a `VectorAffineFunction` holding the indicator variable first. Example: ``\\{(y, x) \\in \\{0, 1\\} \\times \\mathbb{R}^2 : y = 1 \\implies x_1 + x_2 \\leq 9 \\} `` @@ -1017,25 +1017,25 @@ f = MOI.VectorAffineFunction( [0.0, 0.0], ) -indicator_set = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) +indicator_set = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(9.0)) MOI.add_constraint(model, f, indicator_set) ``` """ -struct IndicatorSet{A,S<:AbstractScalarSet} <: AbstractVectorSet +struct Indicator{A,S<:AbstractScalarSet} <: AbstractVectorSet set::S - IndicatorSet{A}(set::S) where {A,S<:AbstractScalarSet} = new{A,S}(set) + Indicator{A}(set::S) where {A,S<:AbstractScalarSet} = new{A,S}(set) end -dimension(::IndicatorSet) = 2 +dimension(::Indicator) = 2 -function Base.copy(set::IndicatorSet{A,S}) where {A,S} - return IndicatorSet{A}(copy(set.set)) +function Base.copy(set::Indicator{A,S}) where {A,S} + return Indicator{A}(copy(set.set)) end function Base.:(==)( - set1::IndicatorSet{A,S}, - set2::IndicatorSet{A,S}, + set1::Indicator{A,S}, + set2::Indicator{A,S}, ) where {A,S} return set1.set == set2.set end diff --git a/test/Bridges/Constraint/indicator_activate_on_zero.jl b/test/Bridges/Constraint/indicator_activate_on_zero.jl index 82e8954d17..d61175b825 100644 --- a/test/Bridges/Constraint/indicator_activate_on_zero.jl +++ b/test/Bridges/Constraint/indicator_activate_on_zero.jl @@ -48,7 +48,7 @@ function test_indicator_activate_on_zero() ], [0.0, 0.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO}(MOI.LessThan(8.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.LessThan(8.0)) BT = MOI.Bridges.Constraint.concrete_bridge_type( MOI.Bridges.Constraint.IndicatorActiveOnFalseBridge{Float64}, typeof(f1), diff --git a/test/Bridges/Constraint/indicator_sos.jl b/test/Bridges/Constraint/indicator_sos.jl index c87294dfd9..1495a0e497 100644 --- a/test/Bridges/Constraint/indicator_sos.jl +++ b/test/Bridges/Constraint/indicator_sos.jl @@ -43,7 +43,7 @@ function test_indicator_by_SOS1() ], [0.0, 0.0], ) - iset1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) + iset1 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) f2 = MOI.VectorAffineFunction( [ @@ -53,7 +53,7 @@ function test_indicator_by_SOS1() ], [0.0, 0.0], ) - iset2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.EqualTo(9.0)) + iset2 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.EqualTo(9.0)) f3 = MOI.VectorAffineFunction( [ @@ -62,7 +62,7 @@ function test_indicator_by_SOS1() ], [0.0, 0.0], ) - iset3 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(5.0)) + iset3 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(5.0)) BT1 = MOI.Bridges.Constraint.concrete_bridge_type( MOI.Bridges.Constraint.IndicatorSOS1Bridge{Float64}, @@ -217,7 +217,7 @@ function test_model_equality() ], [0.0, 0.0], ) - iset = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) + iset = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) ci = MOI.add_constraint(bridged_mock, f, iset) @test length(MOI.get(mock, MOI.ListOfVariableIndices())) == 3 MOI.set( @@ -315,7 +315,7 @@ function test_getting_primal_attributes() ], [0.0, 0.0], ) - iset = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) + iset = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(8.0)) BT = MOI.Bridges.Constraint.concrete_bridge_type( MOI.Bridges.Constraint.IndicatorSOS1Bridge{Float64}, typeof(f), @@ -341,7 +341,7 @@ function test_getting_primal_attributes() MOI.get(mock, MOI.ConstraintPrimalStart(), bridge1) .≈ (1.0, affine_value - w_value), ) - iseteq = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.EqualTo(8.0)) + iseteq = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.EqualTo(8.0)) BT = MOI.Bridges.Constraint.concrete_bridge_type( MOI.Bridges.Constraint.IndicatorSOS1Bridge{Float64}, typeof(f), diff --git a/test/Bridges/lazy_bridge_optimizer.jl b/test/Bridges/lazy_bridge_optimizer.jl index cf12e89532..e46ef84c57 100644 --- a/test/Bridges/lazy_bridge_optimizer.jl +++ b/test/Bridges/lazy_bridge_optimizer.jl @@ -1535,8 +1535,8 @@ function MOI.Bridges.Constraint.concrete_bridge_type( return BridgeAddingNoConstraint{T} end -const LessThanIndicatorSetOne{T} = - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{T}} +const LessThanIndicatorOne{T} = + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{T}} MOI.Utilities.@model( ModelNoZeroIndicator, @@ -1576,7 +1576,7 @@ MOI.Utilities.@model( MOI.DualPowerCone, MOI.SOS1, MOI.SOS2, - LessThanIndicatorSetOne, + LessThanIndicatorOne, ), (), (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction), @@ -1865,12 +1865,12 @@ function test_supports() @test !MOI.supports_constraint( mock_indicator, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ZERO,MOI.LessThan{Float64}}, ) @test MOI.supports_constraint( full_bridged_mock_indicator, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ZERO,MOI.LessThan{Float64}}, ) mock_sos_indicator = @@ -1880,22 +1880,22 @@ function test_supports() @test !MOI.supports_constraint( mock_sos_indicator, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) @test !MOI.supports_constraint( mock_sos_indicator, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.EqualTo{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.EqualTo{Float64}}, ) @test MOI.supports_constraint( full_bridged_mock_sos_indicator, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}, ) @test MOI.supports_constraint( full_bridged_mock_sos_indicator, MOI.VectorAffineFunction{Float64}, - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE,MOI.EqualTo{Float64}}, + MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.EqualTo{Float64}}, ) for T in [Float64, Int] no_variable_mock = MOI.Utilities.MockOptimizer(NoVariableModel{T}()) diff --git a/test/FileFormats/MOF/MOF.jl b/test/FileFormats/MOF/MOF.jl index 13142ca2a0..8c46145ceb 100644 --- a/test/FileFormats/MOF/MOF.jl +++ b/test/FileFormats/MOF/MOF.jl @@ -768,7 +768,7 @@ function test_IndicatorSet() """ variables: x, y minobjective: x -c1: [x, y] in IndicatorSet{ACTIVATE_ON_ONE}(GreaterThan(1.0)) +c1: [x, y] in Indicator{ACTIVATE_ON_ONE}(GreaterThan(1.0)) """, ["x", "y"], ["c1"], @@ -778,7 +778,7 @@ c1: [x, y] in IndicatorSet{ACTIVATE_ON_ONE}(GreaterThan(1.0)) """ variables: x, y minobjective: x -c1: [x, y] in IndicatorSet{ACTIVATE_ON_ZERO}(GreaterThan(1.0)) +c1: [x, y] in Indicator{ACTIVATE_ON_ZERO}(GreaterThan(1.0)) """, ["x", "y"], ["c1"], diff --git a/test/sets.jl b/test/sets.jl index 7f8fcab254..b2c5a16ca2 100644 --- a/test/sets.jl +++ b/test/sets.jl @@ -46,7 +46,7 @@ function test_sets_equals() @test S(a(), a()) != S(b(), b()) @test S(a(), a()) == S(a(), a()) end - S = MOI.IndicatorSet + S = MOI.Indicator A() = MOI.LessThan(a()) B() = MOI.LessThan(b()) @test S{MOI.ACTIVATE_ON_ZERO}(A()) == S{MOI.ACTIVATE_ON_ZERO}(A()) @@ -70,15 +70,15 @@ function test_sets_sos2_copy() end function test_sets_indicator_copy() - s1 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(4.0)) - s2 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO}(MOI.GreaterThan(4.0)) + s1 = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(4.0)) + s2 = MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.GreaterThan(4.0)) s1_copy = copy(s1) s2_copy = copy(s2) - @test s1_copy isa MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE} + @test s1_copy isa MOI.Indicator{MOI.ACTIVATE_ON_ONE} @test s1 == s1_copy - @test s2_copy isa MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO} + @test s2_copy isa MOI.Indicator{MOI.ACTIVATE_ON_ZERO} @test s2 == s2_copy - s3 = MOI.IndicatorSet{MOI.ACTIVATE_ON_ZERO}(MutLessThan(4.0)) + s3 = MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MutLessThan(4.0)) s3_copy = copy(s3) @test s3.set.upper ≈ 4.0 s3_copy.set.upper = 5.0 @@ -109,7 +109,7 @@ function test_sets_dimension() @test MOI.dimension(MOI.SOS1([1.0, 2.0])) == 2 @test MOI.dimension(MOI.SOS2([1.0, 2.0])) == 2 @test MOI.dimension( - MOI.IndicatorSet{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(1.0)), + MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(1.0)), ) == 2 @test MOI.dimension(MOI.Complements(10)) == 10 end From ceb52e4d2a83b7e46ed3528cfccc87d0c7ab8b4f Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 18 Jul 2021 05:15:05 +0200 Subject: [PATCH 02/11] Use JuliaFormatter. --- src/Bridges/Constraint/indicator_activate_on_zero.jl | 7 ++----- src/Bridges/Variable/free.jl | 4 ++-- src/FileFormats/CBF/read.jl | 3 ++- src/sets.jl | 5 +---- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Bridges/Constraint/indicator_activate_on_zero.jl b/src/Bridges/Constraint/indicator_activate_on_zero.jl index 4c943866eb..44d3081bbb 100644 --- a/src/Bridges/Constraint/indicator_activate_on_zero.jl +++ b/src/Bridges/Constraint/indicator_activate_on_zero.jl @@ -42,11 +42,8 @@ function bridge_constraint( z1_z2 = MOIU.operate(+, T, f_scalars[1], MOI.SingleVariable(z2)) dcons = MOIU.normalize_and_add_constraint(model, z1_z2, MOI.EqualTo(one(T))) f2 = MOIU.operate(vcat, T, MOI.SingleVariable(z2), f_scalars[2]) - ci = MOI.add_constraint( - model, - f2, - MOI.Indicator{MOI.ACTIVATE_ON_ONE}(s.set), - ) + ci = + MOI.add_constraint(model, f2, MOI.Indicator{MOI.ACTIVATE_ON_ONE}(s.set)) return IndicatorActiveOnFalseBridge{T,F,S}(z2, zo_cons, dcons, ci) end diff --git a/src/Bridges/Variable/free.jl b/src/Bridges/Variable/free.jl index 60720e79d9..c451fb056a 100644 --- a/src/Bridges/Variable/free.jl +++ b/src/Bridges/Variable/free.jl @@ -136,8 +136,8 @@ function unbridged_map( # `unbridged_map` is required to return a `MOI.ScalarAffineFunction`. func = convert(MOI.ScalarAffineFunction{T}, sv) n = div(length(bridge.variables), 2) - return bridge.variables[i.value] => func, - bridge.variables[n+i.value] => zero(MOI.ScalarAffineFunction{T}) + return bridge.variables[i.value] => + func, bridge.variables[n+i.value] => zero(MOI.ScalarAffineFunction{T}) end function MOI.supports( diff --git a/src/FileFormats/CBF/read.jl b/src/FileFormats/CBF/read.jl index 854606330b..c59366d2ca 100644 --- a/src/FileFormats/CBF/read.jl +++ b/src/FileFormats/CBF/read.jl @@ -360,7 +360,8 @@ function Base.read!(io::IO, model::Model) # Reverse order of indices. MOI.VectorAffineFunction( [ - MOI.VectorAffineTerm{Float64}(4 - l, t) for l in 1:cone_dim for t in data.row_terms[row_idx+l] + MOI.VectorAffineTerm{Float64}(4 - l, t) for + l in 1:cone_dim for t in data.row_terms[row_idx+l] ], data.row_constants[row_idx.+(3:-1:1)], ) diff --git a/src/sets.jl b/src/sets.jl index 39f7477e66..9485006643 100644 --- a/src/sets.jl +++ b/src/sets.jl @@ -1033,10 +1033,7 @@ function Base.copy(set::Indicator{A,S}) where {A,S} return Indicator{A}(copy(set.set)) end -function Base.:(==)( - set1::Indicator{A,S}, - set2::Indicator{A,S}, -) where {A,S} +function Base.:(==)(set1::Indicator{A,S}, set2::Indicator{A,S}) where {A,S} return set1.set == set2.set end From e6f5b8779422c48de77d50a7dc82d20d92cdf708 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sun, 18 Jul 2021 18:55:51 +0200 Subject: [PATCH 03/11] Undo MOF changes. --- src/FileFormats/MOF/mof.0.6.schema.json | 4 ++-- src/FileFormats/MOF/read.jl | 2 +- src/FileFormats/MOF/write.jl | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/FileFormats/MOF/mof.0.6.schema.json b/src/FileFormats/MOF/mof.0.6.schema.json index a5d1615950..031e10ab37 100644 --- a/src/FileFormats/MOF/mof.0.6.schema.json +++ b/src/FileFormats/MOF/mof.0.6.schema.json @@ -769,11 +769,11 @@ } }, { "description": "If `activate_on=one`: (y, x) ∈ {0,1}×Rᴺ: y = 0 ⟹ x ∈ S, otherwise when `activate_on=zero`: (y, x) ∈ {0,1}×Rᴺ: y = 1 ⟹ x ∈ S.", - "examples": ["{\"type\": \"Indicator\", \"set\": {\"type\": \"LessThan\", \"upper\": 2.0}, \"activate_on\": \"one\"}"], + "examples": ["{\"type\": \"IndicatorSet\", \"set\": {\"type\": \"LessThan\", \"upper\": 2.0}, \"activate_on\": \"one\"}"], "required": ["set", "activate_on"], "properties": { "type": { - "const": "Indicator" + "const": "IndicatorSet" }, "set": { "oneOf": [{ diff --git a/src/FileFormats/MOF/read.jl b/src/FileFormats/MOF/read.jl index e35c464b7c..b8c6cd32a8 100644 --- a/src/FileFormats/MOF/read.jl +++ b/src/FileFormats/MOF/read.jl @@ -469,7 +469,7 @@ function set_to_moi(::Val{:SOS2}, object::Object) return MOI.SOS2(Float64.(object["weights"])) end -function set_to_moi(::Val{:Indicator}, object::Object) +function set_to_moi(::Val{:IndicatorSet}, object::Object) set = set_to_moi(object["set"]::typeof(object)) indicator = if object["activate_on"]::String == "one" MOI.ACTIVATE_ON_ONE diff --git a/src/FileFormats/MOF/write.jl b/src/FileFormats/MOF/write.jl index 7d3354e36f..05c971a67e 100644 --- a/src/FileFormats/MOF/write.jl +++ b/src/FileFormats/MOF/write.jl @@ -300,7 +300,7 @@ function moi_to_object( ) where {I,S} @assert I == MOI.ACTIVATE_ON_ONE || I == MOI.ACTIVATE_ON_ZERO return OrderedObject( - "type" => "Indicator", + "type" => "IndicatorSet", "set" => moi_to_object(set.set, name_map), "activate_on" => (I == MOI.ACTIVATE_ON_ONE) ? "one" : "zero", ) From eb81912f3d7b710a22f11d52f22d677d3f66be27 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Fri, 23 Jul 2021 02:23:19 +0200 Subject: [PATCH 04/11] This should fix tests. --- src/FileFormats/MOF/read.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FileFormats/MOF/read.jl b/src/FileFormats/MOF/read.jl index b8c6cd32a8..e35c464b7c 100644 --- a/src/FileFormats/MOF/read.jl +++ b/src/FileFormats/MOF/read.jl @@ -469,7 +469,7 @@ function set_to_moi(::Val{:SOS2}, object::Object) return MOI.SOS2(Float64.(object["weights"])) end -function set_to_moi(::Val{:IndicatorSet}, object::Object) +function set_to_moi(::Val{:Indicator}, object::Object) set = set_to_moi(object["set"]::typeof(object)) indicator = if object["activate_on"]::String == "one" MOI.ACTIVATE_ON_ONE From 9aceb362f44a2e7f4e782a0a29059dd8c8ba3c65 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Fri, 23 Jul 2021 02:35:01 +0200 Subject: [PATCH 05/11] Rename test functions. --- test/FileFormats/MOF/MOF.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/FileFormats/MOF/MOF.jl b/test/FileFormats/MOF/MOF.jl index 8c46145ceb..9d8e5f4718 100644 --- a/test/FileFormats/MOF/MOF.jl +++ b/test/FileFormats/MOF/MOF.jl @@ -763,7 +763,7 @@ c1: [t, x1, x2, x3, x4] in RootDetConeSquare(2) ) end -function test_IndicatorSet() +function test_Indicator() _test_model_equality( """ variables: x, y From 39d86d72d0d89eaacdf0c02835354e7456dac96e Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sat, 24 Jul 2021 06:09:08 +0200 Subject: [PATCH 06/11] New tentative to fix tests. --- src/FileFormats/MOF/read.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/FileFormats/MOF/read.jl b/src/FileFormats/MOF/read.jl index e35c464b7c..ee4b15f0af 100644 --- a/src/FileFormats/MOF/read.jl +++ b/src/FileFormats/MOF/read.jl @@ -311,7 +311,7 @@ end DualPowerCone, SOS1, SOS2, - Indicator, + IndicatorSet, Complements, ) @@ -469,7 +469,7 @@ function set_to_moi(::Val{:SOS2}, object::Object) return MOI.SOS2(Float64.(object["weights"])) end -function set_to_moi(::Val{:Indicator}, object::Object) +function set_to_moi(::Val{:IndicatorSet}, object::Object) set = set_to_moi(object["set"]::typeof(object)) indicator = if object["activate_on"]::String == "one" MOI.ACTIVATE_ON_ONE From ba860d38916fa494595220ea727892d7ecd9465e Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Sat, 24 Jul 2021 17:19:24 +0200 Subject: [PATCH 07/11] JuliaFormatter. --- src/Test/test_basic_constraint.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Test/test_basic_constraint.jl b/src/Test/test_basic_constraint.jl index 4dd815b443..e37c4c4d5b 100644 --- a/src/Test/test_basic_constraint.jl +++ b/src/Test/test_basic_constraint.jl @@ -104,9 +104,7 @@ _set(::Type{MOI.RootDetConeTriangle}) = MOI.RootDetConeTriangle(3) _set(::Type{MOI.RootDetConeSquare}) = MOI.RootDetConeSquare(3) _set(::Type{MOI.Complements}) = MOI.Complements(2) -function _set( - ::Type{MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}}, -) +function _set(::Type{MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{Float64}}}) return MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.LessThan(3.0)) end From 746b2450eec9e45c42e2ebf75f949fd715de844f Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Mon, 26 Jul 2021 21:54:16 +0200 Subject: [PATCH 08/11] JuliaFormatter, all. --- src/Bridges/Variable/free.jl | 2 +- src/FileFormats/CBF/read.jl | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Bridges/Variable/free.jl b/src/Bridges/Variable/free.jl index c451fb056a..5130ec8fdb 100644 --- a/src/Bridges/Variable/free.jl +++ b/src/Bridges/Variable/free.jl @@ -137,7 +137,7 @@ function unbridged_map( func = convert(MOI.ScalarAffineFunction{T}, sv) n = div(length(bridge.variables), 2) return bridge.variables[i.value] => - func, bridge.variables[n+i.value] => zero(MOI.ScalarAffineFunction{T}) + func, bridge.variables[n+i.value] => zero(MOI.ScalarAffineFunction{T}) end function MOI.supports( diff --git a/src/FileFormats/CBF/read.jl b/src/FileFormats/CBF/read.jl index c59366d2ca..854606330b 100644 --- a/src/FileFormats/CBF/read.jl +++ b/src/FileFormats/CBF/read.jl @@ -360,8 +360,7 @@ function Base.read!(io::IO, model::Model) # Reverse order of indices. MOI.VectorAffineFunction( [ - MOI.VectorAffineTerm{Float64}(4 - l, t) for - l in 1:cone_dim for t in data.row_terms[row_idx+l] + MOI.VectorAffineTerm{Float64}(4 - l, t) for l in 1:cone_dim for t in data.row_terms[row_idx+l] ], data.row_constants[row_idx.+(3:-1:1)], ) From 5c1a4ae301934dbdc8e40057b987183aa2df5efa Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Mon, 26 Jul 2021 21:56:30 +0200 Subject: [PATCH 09/11] Update free.jl --- src/Bridges/Variable/free.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/Variable/free.jl b/src/Bridges/Variable/free.jl index 5130ec8fdb..4ca27b7845 100644 --- a/src/Bridges/Variable/free.jl +++ b/src/Bridges/Variable/free.jl @@ -137,7 +137,7 @@ function unbridged_map( func = convert(MOI.ScalarAffineFunction{T}, sv) n = div(length(bridge.variables), 2) return bridge.variables[i.value] => - func, bridge.variables[n+i.value] => zero(MOI.ScalarAffineFunction{T}) + func, bridge.variables[n+i.value] => zero(MOI.ScalarAffineFunction{T}) end function MOI.supports( From 9d8d20979209e1db995c6b047434139f8eb8aa09 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Mon, 26 Jul 2021 21:59:17 +0200 Subject: [PATCH 10/11] Update free.jl --- src/Bridges/Variable/free.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bridges/Variable/free.jl b/src/Bridges/Variable/free.jl index 4ca27b7845..60720e79d9 100644 --- a/src/Bridges/Variable/free.jl +++ b/src/Bridges/Variable/free.jl @@ -136,8 +136,8 @@ function unbridged_map( # `unbridged_map` is required to return a `MOI.ScalarAffineFunction`. func = convert(MOI.ScalarAffineFunction{T}, sv) n = div(length(bridge.variables), 2) - return bridge.variables[i.value] => - func, bridge.variables[n+i.value] => zero(MOI.ScalarAffineFunction{T}) + return bridge.variables[i.value] => func, + bridge.variables[n+i.value] => zero(MOI.ScalarAffineFunction{T}) end function MOI.supports( From 2b63a945c7702bf7be7ef29c8954b06df7424baa Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Mon, 2 Aug 2021 12:07:16 +0200 Subject: [PATCH 11/11] Missing renames. --- src/Utilities/model.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index 39f6952010..4abfb856de 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -886,9 +886,9 @@ for (loop_name, loop_super_type) in [ end end -const LessThanIndicatorSetOne{T} = +const LessThanIndicatorOne{T} = MOI.Indicator{MOI.ACTIVATE_ON_ONE,MOI.LessThan{T}} -const LessThanIndicatorSetZero{T} = +const LessThanIndicatorZero{T} = MOI.Indicator{MOI.ACTIVATE_ON_ZERO,MOI.LessThan{T}} @model( @@ -930,8 +930,8 @@ const LessThanIndicatorSetZero{T} = MOI.DualPowerCone, MOI.SOS1, MOI.SOS2, - LessThanIndicatorSetOne, - LessThanIndicatorSetZero, + LessThanIndicatorOne, + LessThanIndicatorZero, ), (), (MOI.ScalarAffineFunction, MOI.ScalarQuadraticFunction),