From 952b7a4b7be89cb42c8938e848a86e8fb498606c Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 11 Mar 2021 14:54:29 +1300 Subject: [PATCH 01/12] Add MOI.attribute_value_type for attributes. --- src/Bridges/Constraint/bridge.jl | 4 +- src/Bridges/Constraint/det.jl | 18 ++-- src/Bridges/Constraint/functionize.jl | 4 +- src/Bridges/Constraint/geomean.jl | 8 +- src/Bridges/Constraint/geomean_to_relentr.jl | 6 +- src/Bridges/Constraint/indicator_sos.jl | 10 +- src/Bridges/Constraint/interval.jl | 4 +- .../Constraint/norm_spec_nuc_to_psd.jl | 8 +- src/Bridges/Constraint/norm_to_lp.jl | 6 +- src/Bridges/Constraint/quad_to_soc.jl | 2 +- src/Bridges/Constraint/relentr_to_exp.jl | 6 +- src/Bridges/Constraint/scalarize.jl | 2 +- src/Bridges/Constraint/semi_to_binary.jl | 10 +- src/Bridges/Constraint/set_map.jl | 2 +- src/Bridges/Constraint/slack.jl | 9 +- .../Constraint/soc_to_nonconvex_quad.jl | 4 +- src/Bridges/Constraint/square.jl | 4 +- src/Bridges/Constraint/vectorize.jl | 2 +- src/Bridges/Constraint/zero_one.jl | 4 +- src/Bridges/Objective/functionize.jl | 2 +- src/Bridges/Objective/slack.jl | 6 +- src/Bridges/Variable/flip_sign.jl | 4 +- src/Bridges/Variable/free.jl | 4 +- src/Bridges/Variable/rsoc_to_psd.jl | 12 ++- src/Bridges/Variable/rsoc_to_soc.jl | 4 +- src/Bridges/Variable/soc_to_rsoc.jl | 4 +- src/Bridges/Variable/vectorize.jl | 6 +- src/Bridges/Variable/zeros.jl | 2 +- src/Bridges/bridge.jl | 2 +- src/Bridges/bridge_optimizer.jl | 4 +- src/Test/UnitTests/attributes.jl | 100 ++++++++++++++++++ src/Test/modellike.jl | 2 +- src/Utilities/cachingoptimizer.jl | 22 ++-- src/Utilities/functions.jl | 12 ++- src/Utilities/model.jl | 7 +- src/Utilities/struct_of_constraints.jl | 4 +- src/Utilities/universalfallback.jl | 4 +- src/Utilities/vector_of_constraints.jl | 2 +- src/attributes.jl | 71 +++++++++++-- test/Utilities/mockoptimizer.jl | 66 ++++++++++++ 40 files changed, 348 insertions(+), 105 deletions(-) diff --git a/src/Bridges/Constraint/bridge.jl b/src/Bridges/Constraint/bridge.jl index c57f39ed90..d4307e5c97 100644 --- a/src/Bridges/Constraint/bridge.jl +++ b/src/Bridges/Constraint/bridge.jl @@ -27,10 +27,10 @@ function bridge_constraint end The number of variables created by the bridge `b` in the model. """ -MOI.get(::AbstractBridge, ::MOI.NumberOfVariables) = 0 +MOI.get(::AbstractBridge, ::MOI.NumberOfVariables) = Int64(0) """ - MOI.get(b::AbstractBridge, ::MOI.NumberOfVariables) + MOI.get(b::AbstractBridge, ::MOI.ListOfVariableIndices) The list of variables created by the bridge `b` in the model. """ diff --git a/src/Bridges/Constraint/det.jl b/src/Bridges/Constraint/det.jl index f6e1ec4fad..0f56f99a57 100644 --- a/src/Bridges/Constraint/det.jl +++ b/src/Bridges/Constraint/det.jl @@ -210,7 +210,10 @@ function subsum( end # Attributes, Bridge acting as a model -MOI.get(b::LogDetBridge, ::MOI.NumberOfVariables) = length(b.Δ) + length(b.l) + +function MOI.get(b::LogDetBridge, ::MOI.NumberOfVariables) + return Int64(length(b.Δ) + length(b.l)) +end MOI.get(b::LogDetBridge, ::MOI.ListOfVariableIndices) = [b.Δ; b.l] @@ -221,21 +224,21 @@ function MOI.get( MOI.PositiveSemidefiniteConeTriangle, }, ) where {T} - return 1 + return Int64(1) end function MOI.get( b::LogDetBridge{T}, ::MOI.NumberOfConstraints{MOI.VectorAffineFunction{T},MOI.ExponentialCone}, ) where {T} - return length(b.lcindex) + return Int64(length(b.lcindex)) end function MOI.get( ::LogDetBridge{T}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}, ) where {T} - return 1 + return Int64(1) end function MOI.get( @@ -407,7 +410,8 @@ function MOIB.added_constraint_types(::Type{RootDetBridge{T}}) where {T} end # Attributes, Bridge acting as a model -MOI.get(b::RootDetBridge, ::MOI.NumberOfVariables) = length(b.Δ) + +MOI.get(b::RootDetBridge, ::MOI.NumberOfVariables) = Int64(length(b.Δ)) MOI.get(b::RootDetBridge, ::MOI.ListOfVariableIndices) = copy(b.Δ) @@ -418,7 +422,7 @@ function MOI.get( MOI.PositiveSemidefiniteConeTriangle, }, ) where {T} - return 1 + return Int64(1) end function MOI.get( @@ -428,7 +432,7 @@ function MOI.get( MOI.GeometricMeanCone, }, ) where {T} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/functionize.jl b/src/Bridges/Constraint/functionize.jl index 86d4a009de..01e94b64f3 100644 --- a/src/Bridges/Constraint/functionize.jl +++ b/src/Bridges/Constraint/functionize.jl @@ -55,7 +55,7 @@ function MOI.get( ::ScalarFunctionizeBridge{T,S}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},S}, ) where {T,S} - return 1 + return Int64(1) end function MOI.get( @@ -152,7 +152,7 @@ function MOI.get( ::VectorFunctionizeBridge{T,S}, ::MOI.NumberOfConstraints{MOI.VectorAffineFunction{T},S}, ) where {T,S} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/geomean.jl b/src/Bridges/Constraint/geomean.jl index cdb06bda08..4537ae660d 100644 --- a/src/Bridges/Constraint/geomean.jl +++ b/src/Bridges/Constraint/geomean.jl @@ -168,7 +168,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(b::GeoMeanBridge, ::MOI.NumberOfVariables) = length(b.xij) +MOI.get(b::GeoMeanBridge, ::MOI.NumberOfVariables) = Int64(length(b.xij)) MOI.get(b::GeoMeanBridge, ::MOI.ListOfVariableIndices) = copy(b.xij) @@ -176,21 +176,21 @@ function MOI.get( ::GeoMeanBridge{T,F}, ::MOI.NumberOfConstraints{F,MOI.LessThan{T}}, ) where {T,F} - return 1 # t ≤ x_{l1}/sqrt(N) + return Int64(1) # t ≤ x_{l1}/sqrt(N) end function MOI.get( b::GeoMeanBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.RotatedSecondOrderCone}, ) where {T,F,G} - return length(b.socrc) + return Int64(length(b.socrc)) end function MOI.get( b::GeoMeanBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.Nonnegatives}, ) where {T,F,G} - return (b.d > 2 ? 0 : 1) + return Int64(b.d > 2 ? 0 : 1) end function MOI.get( diff --git a/src/Bridges/Constraint/geomean_to_relentr.jl b/src/Bridges/Constraint/geomean_to_relentr.jl index 3ed6b5a72a..cd2fac8c5e 100644 --- a/src/Bridges/Constraint/geomean_to_relentr.jl +++ b/src/Bridges/Constraint/geomean_to_relentr.jl @@ -86,7 +86,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(bridge::GeoMeantoRelEntrBridge, ::MOI.NumberOfVariables) = 1 +MOI.get(::GeoMeantoRelEntrBridge, ::MOI.NumberOfVariables) = Int64(1) function MOI.get(bridge::GeoMeantoRelEntrBridge, ::MOI.ListOfVariableIndices) return [bridge.y] @@ -96,14 +96,14 @@ function MOI.get( ::GeoMeantoRelEntrBridge{T,F}, ::MOI.NumberOfConstraints{F,MOI.Nonnegatives}, ) where {T,F} - return 1 + return Int64(1) end function MOI.get( ::GeoMeantoRelEntrBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.RelativeEntropyCone}, ) where {T,F,G} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/indicator_sos.jl b/src/Bridges/Constraint/indicator_sos.jl index 2f74789e7a..d3ff332762 100644 --- a/src/Bridges/Constraint/indicator_sos.jl +++ b/src/Bridges/Constraint/indicator_sos.jl @@ -155,7 +155,7 @@ end # Attributes, Bridge acting as a model function MOI.get(::IndicatorSOS1Bridge, ::MOI.NumberOfVariables) - return 1 + return Int64(1) end function MOI.get(b::IndicatorSOS1Bridge, ::MOI.ListOfVariableIndices) @@ -166,28 +166,28 @@ function MOI.get( ::IndicatorSOS1Bridge{T,BC,Nothing}, ::MOI.NumberOfConstraints{MOI.SingleVariable,BC}, ) where {T,BC} - return 0 + return Int64(0) end function MOI.get( ::IndicatorSOS1Bridge{T,BC,CI}, ::MOI.NumberOfConstraints{MOI.SingleVariable,BC}, ) where {T,BC,CI<:MOI.ConstraintIndex{MOI.SingleVariable,BC}} - return 1 + return Int64(1) end function MOI.get( ::IndicatorSOS1Bridge, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,<:MOI.SOS1}, ) - return 1 + return Int64(1) end function MOI.get( ::IndicatorSOS1Bridge{T,BC}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},BC}, ) where {T,BC,CI<:MOI.ConstraintIndex{MOI.SingleVariable,BC}} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/interval.jl b/src/Bridges/Constraint/interval.jl index 402be7ad43..a148929a81 100644 --- a/src/Bridges/Constraint/interval.jl +++ b/src/Bridges/Constraint/interval.jl @@ -87,14 +87,14 @@ function MOI.get( ::SplitIntervalBridge{T,F,S,LS}, ::MOI.NumberOfConstraints{F,LS}, ) where {T,F,S,LS} - return 1 + return Int64(1) end function MOI.get( ::SplitIntervalBridge{T,F,S,LS,US}, ::MOI.NumberOfConstraints{F,US}, ) where {T,F,S,LS,US} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/norm_spec_nuc_to_psd.jl b/src/Bridges/Constraint/norm_spec_nuc_to_psd.jl index 2284aa3e84..7b49975a62 100644 --- a/src/Bridges/Constraint/norm_spec_nuc_to_psd.jl +++ b/src/Bridges/Constraint/norm_spec_nuc_to_psd.jl @@ -73,7 +73,7 @@ function MOI.get( bridge::NormSpectralBridge{T,F,G}, ::MOI.NumberOfConstraints{F,MOI.PositiveSemidefiniteConeTriangle}, ) where {T,F,G} - return 1 + return Int64(1) end function MOI.get( @@ -281,7 +281,7 @@ end # Attributes, Bridge acting as a model function MOI.get(bridge::NormNuclearBridge, ::MOI.NumberOfVariables) - return length(bridge.U) + length(bridge.V) + return Int64(length(bridge.U) + length(bridge.V)) end function MOI.get(bridge::NormNuclearBridge, ::MOI.ListOfVariableIndices) @@ -292,14 +292,14 @@ function MOI.get( bridge::NormNuclearBridge{T,F,G,H}, ::MOI.NumberOfConstraints{F,MOI.GreaterThan{T}}, ) where {T,F,G,H} - return 1 + return Int64(1) end function MOI.get( bridge::NormNuclearBridge{T,F,G,H}, ::MOI.NumberOfConstraints{G,MOI.PositiveSemidefiniteConeTriangle}, ) where {T,F,G,H} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/norm_to_lp.jl b/src/Bridges/Constraint/norm_to_lp.jl index 120045cb5a..5e76acb2a4 100644 --- a/src/Bridges/Constraint/norm_to_lp.jl +++ b/src/Bridges/Constraint/norm_to_lp.jl @@ -143,13 +143,15 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(b::NormOneBridge, ::MOI.NumberOfVariables) = length(b.y) +MOI.get(b::NormOneBridge, ::MOI.NumberOfVariables) = Int64(length(b.y)) + MOI.get(b::NormOneBridge, ::MOI.ListOfVariableIndices) = copy(b.y) + function MOI.get( b::NormOneBridge{T,F}, ::MOI.NumberOfConstraints{F,MOI.Nonnegatives}, ) where {T,F} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/quad_to_soc.jl b/src/Bridges/Constraint/quad_to_soc.jl index 445f065c91..9346355231 100644 --- a/src/Bridges/Constraint/quad_to_soc.jl +++ b/src/Bridges/Constraint/quad_to_soc.jl @@ -187,7 +187,7 @@ function MOI.get( MOI.RotatedSecondOrderCone, }, ) where {T} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/relentr_to_exp.jl b/src/Bridges/Constraint/relentr_to_exp.jl index 0db07a87f3..f7c88f8f67 100644 --- a/src/Bridges/Constraint/relentr_to_exp.jl +++ b/src/Bridges/Constraint/relentr_to_exp.jl @@ -82,7 +82,7 @@ end # Attributes, Bridge acting as a model function MOI.get(bridge::RelativeEntropyBridge, ::MOI.NumberOfVariables) - return length(bridge.y) + return Int64(length(bridge.y)) end function MOI.get(bridge::RelativeEntropyBridge, ::MOI.ListOfVariableIndices) @@ -93,14 +93,14 @@ function MOI.get( bridge::RelativeEntropyBridge{T,F}, ::MOI.NumberOfConstraints{F,MOI.GreaterThan{T}}, ) where {T,F} - return 1 + return Int64(1) end function MOI.get( bridge::RelativeEntropyBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.ExponentialCone}, ) where {T,F,G} - return length(bridge.y) + return Int64(length(bridge.y)) end function MOI.get( diff --git a/src/Bridges/Constraint/scalarize.jl b/src/Bridges/Constraint/scalarize.jl index 99cbf44b84..305f1f9b12 100644 --- a/src/Bridges/Constraint/scalarize.jl +++ b/src/Bridges/Constraint/scalarize.jl @@ -59,7 +59,7 @@ function MOI.get( bridge::ScalarizeBridge{T,F,S}, ::MOI.NumberOfConstraints{F,S}, ) where {T,F,S} - return length(bridge.scalar_constraints) + return Int64(length(bridge.scalar_constraints)) end function MOI.get( diff --git a/src/Bridges/Constraint/semi_to_binary.jl b/src/Bridges/Constraint/semi_to_binary.jl index 4b53e4a806..386e2a5769 100644 --- a/src/Bridges/Constraint/semi_to_binary.jl +++ b/src/Bridges/Constraint/semi_to_binary.jl @@ -215,7 +215,7 @@ end # Attributes, Bridge acting as a model function MOI.get(::SemiToBinaryBridge, ::MOI.NumberOfVariables) - return 1 + return Int64(1) end function MOI.get(b::SemiToBinaryBridge, ::MOI.ListOfVariableIndices) @@ -226,28 +226,28 @@ function MOI.get( ::SemiToBinaryBridge{T,S}, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.ZeroOne}, ) where {T,S} - return 1 + return Int64(1) end function MOI.get( ::SemiToBinaryBridge{T,S}, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Integer}, ) where {T,S<:MOI.Semiinteger} - return 1 + return Int64(1) end function MOI.get( ::SemiToBinaryBridge{T,S}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.GreaterThan{T}}, ) where {T,S} - return 1 + return Int64(1) end function MOI.get( ::SemiToBinaryBridge{T,S}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}, ) where {T,S} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/set_map.jl b/src/Bridges/Constraint/set_map.jl index a7528e08f4..26b0b43ff9 100644 --- a/src/Bridges/Constraint/set_map.jl +++ b/src/Bridges/Constraint/set_map.jl @@ -42,7 +42,7 @@ function MOI.get( ::SetMapBridge{T,S2,S1,F}, ::MOI.NumberOfConstraints{F,S2}, ) where {T,S2,S1,F} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/slack.jl b/src/Bridges/Constraint/slack.jl index 8bf57e35a0..72539e380e 100644 --- a/src/Bridges/Constraint/slack.jl +++ b/src/Bridges/Constraint/slack.jl @@ -16,14 +16,14 @@ function MOI.get( ::AbstractSlackBridge{T,VF,ZS,F}, ::MOI.NumberOfConstraints{F,ZS}, ) where {T,VF,ZS,F} - return 1 + return Int64(1) end function MOI.get( ::AbstractSlackBridge{T,VF,ZS,F,S}, ::MOI.NumberOfConstraints{VF,S}, ) where {T,VF,ZS,F,S} - return 1 + return Int64(1) end function MOI.get( @@ -217,7 +217,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(b::ScalarSlackBridge, ::MOI.NumberOfVariables) = 1 +MOI.get(b::ScalarSlackBridge, ::MOI.NumberOfVariables) = Int64(1) MOI.get(b::ScalarSlackBridge, ::MOI.ListOfVariableIndices) = [b.slack] # Attributes, Bridge acting as a constraint @@ -312,7 +312,8 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(b::VectorSlackBridge, ::MOI.NumberOfVariables) = length(b.slack) +MOI.get(b::VectorSlackBridge, ::MOI.NumberOfVariables) = Int64(length(b.slack)) + MOI.get(b::VectorSlackBridge, ::MOI.ListOfVariableIndices) = copy(b.slack) # Attributes, Bridge acting as a constraint diff --git a/src/Bridges/Constraint/soc_to_nonconvex_quad.jl b/src/Bridges/Constraint/soc_to_nonconvex_quad.jl index c336bbc750..7f8f5db25f 100644 --- a/src/Bridges/Constraint/soc_to_nonconvex_quad.jl +++ b/src/Bridges/Constraint/soc_to_nonconvex_quad.jl @@ -173,7 +173,7 @@ function MOI.get( ::AbstractSOCtoNonConvexQuadBridge{T}, ::MOI.NumberOfConstraints{MOI.ScalarQuadraticFunction{T},MOI.LessThan{T}}, ) where {T} - return 1 + return Int64(1) end function MOI.get( @@ -190,7 +190,7 @@ function MOI.get( bridge::AbstractSOCtoNonConvexQuadBridge{T}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.GreaterThan{T}}, ) where {T} - return length(bridge.var_pos) + return Int64(length(bridge.var_pos)) end function MOI.get( diff --git a/src/Bridges/Constraint/square.jl b/src/Bridges/Constraint/square.jl index 93740fe9e5..c6243805f1 100644 --- a/src/Bridges/Constraint/square.jl +++ b/src/Bridges/Constraint/square.jl @@ -168,14 +168,14 @@ function MOI.get( ::SquareBridge{T,F,G,TT}, ::MOI.NumberOfConstraints{F,TT}, ) where {T,F,G,TT} - return 1 + return Int64(1) end function MOI.get( bridge::SquareBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.EqualTo{T}}, ) where {T,F,G} - return length(bridge.sym) + return Int64(length(bridge.sym)) end function MOI.get( diff --git a/src/Bridges/Constraint/vectorize.jl b/src/Bridges/Constraint/vectorize.jl index 0426d7c8c3..bbf9dd0803 100644 --- a/src/Bridges/Constraint/vectorize.jl +++ b/src/Bridges/Constraint/vectorize.jl @@ -75,7 +75,7 @@ function MOI.get( ::VectorizeBridge{T,F,S}, ::MOI.NumberOfConstraints{F,S}, ) where {T,F,S} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Constraint/zero_one.jl b/src/Bridges/Constraint/zero_one.jl index 030afdece2..cf78035673 100644 --- a/src/Bridges/Constraint/zero_one.jl +++ b/src/Bridges/Constraint/zero_one.jl @@ -104,14 +104,14 @@ function MOI.get( bridge::ZeroOneBridge{T}, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Interval{T}}, ) where {T} - return 1 + return Int64(1) end function MOI.get( bridge::ZeroOneBridge, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Integer}, ) - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Objective/functionize.jl b/src/Bridges/Objective/functionize.jl index 79749f1e97..3118435869 100644 --- a/src/Bridges/Objective/functionize.jl +++ b/src/Bridges/Objective/functionize.jl @@ -39,7 +39,7 @@ end # Attributes, Bridge acting as a model function MOI.get(::FunctionizeBridge, ::MOI.NumberOfVariables) - return 0 + return Int64(0) end function MOI.get(::FunctionizeBridge, ::MOI.ListOfVariableIndices) diff --git a/src/Bridges/Objective/slack.jl b/src/Bridges/Objective/slack.jl index a395c40b29..35415b9bbb 100644 --- a/src/Bridges/Objective/slack.jl +++ b/src/Bridges/Objective/slack.jl @@ -78,9 +78,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -function MOI.get(::SlackBridge, ::MOI.NumberOfVariables) - return 1 -end +MOI.get(::SlackBridge, ::MOI.NumberOfVariables) = Int64(1) function MOI.get(bridge::SlackBridge, ::MOI.ListOfVariableIndices) return [bridge.slack] @@ -90,7 +88,7 @@ function MOI.get( bridge::SlackBridge{T,F}, ::MOI.NumberOfConstraints{F,S}, ) where {T,F,S<:Union{MOI.GreaterThan{T},MOI.LessThan{T}}} - return bridge.constraint isa MOI.ConstraintIndex{F,S} ? 1 : 0 + return Int64(bridge.constraint isa MOI.ConstraintIndex{F,S} ? 1 : 0) end function MOI.get( diff --git a/src/Bridges/Variable/flip_sign.jl b/src/Bridges/Variable/flip_sign.jl index ff472aba2b..7e7434b1f0 100644 --- a/src/Bridges/Variable/flip_sign.jl +++ b/src/Bridges/Variable/flip_sign.jl @@ -28,7 +28,7 @@ end # Attributes, Bridge acting as a model function MOI.get(bridge::FlipSignBridge, ::MOI.NumberOfVariables) - return length(bridge.flipped_variables) + return Int64(length(bridge.flipped_variables)) end function MOI.get(bridge::FlipSignBridge, ::MOI.ListOfVariableIndices) @@ -39,7 +39,7 @@ function MOI.get( ::FlipSignBridge{T,S1,S2}, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,S2}, ) where {T,S1,S2<:MOI.AbstractVectorSet} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Variable/free.jl b/src/Bridges/Variable/free.jl index 60720e79d9..1b6278b2cd 100644 --- a/src/Bridges/Variable/free.jl +++ b/src/Bridges/Variable/free.jl @@ -35,7 +35,7 @@ end # Attributes, Bridge acting as a model function MOI.get(bridge::FreeBridge, ::MOI.NumberOfVariables) - return length(bridge.variables) + return Int64(length(bridge.variables)) end function MOI.get(bridge::FreeBridge, ::MOI.ListOfVariableIndices) @@ -46,7 +46,7 @@ function MOI.get( ::FreeBridge, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.Nonnegatives}, ) - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Variable/rsoc_to_psd.jl b/src/Bridges/Variable/rsoc_to_psd.jl index 6963bcf4da..48ced6a46c 100644 --- a/src/Bridges/Variable/rsoc_to_psd.jl +++ b/src/Bridges/Variable/rsoc_to_psd.jl @@ -87,7 +87,7 @@ end # Attributes, Bridge acting as a model function MOI.get(bridge::RSOCtoPSDBridge, ::MOI.NumberOfVariables) - return length(bridge.variables) + return Int64(length(bridge.variables)) end function MOI.get(bridge::RSOCtoPSDBridge, ::MOI.ListOfVariableIndices) @@ -98,7 +98,11 @@ function MOI.get( bridge::RSOCtoPSDBridge, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,S}, ) where {S<:Union{MOI.PositiveSemidefiniteConeTriangle,MOI.Nonnegatives}} - return bridge.psd isa MOI.ConstraintIndex{MOI.VectorOfVariables,S} ? 1 : 0 + if bridge.psd isa MOI.ConstraintIndex{MOI.VectorOfVariables,S} + return Int64(1) + else + return Int64(0) + end end function MOI.get( @@ -116,7 +120,7 @@ function MOI.get( bridge::RSOCtoPSDBridge{T}, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{T}}, ) where {T} - return length(bridge.off_diag) + return Int64(length(bridge.off_diag)) end function MOI.get( @@ -130,7 +134,7 @@ function MOI.get( bridge::RSOCtoPSDBridge{T}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.EqualTo{T}}, ) where {T} - return length(bridge.diag) + return Int64(length(bridge.diag)) end function MOI.get( diff --git a/src/Bridges/Variable/rsoc_to_soc.jl b/src/Bridges/Variable/rsoc_to_soc.jl index 4cf5fae02f..e75e68def4 100644 --- a/src/Bridges/Variable/rsoc_to_soc.jl +++ b/src/Bridges/Variable/rsoc_to_soc.jl @@ -105,7 +105,7 @@ end # Attributes, Bridge acting as a model function MOI.get(bridge::RSOCtoSOCBridge, ::MOI.NumberOfVariables) - return length(bridge.variables) + return Int64(length(bridge.variables)) end function MOI.get(bridge::RSOCtoSOCBridge, ::MOI.ListOfVariableIndices) @@ -116,7 +116,7 @@ function MOI.get( ::RSOCtoSOCBridge, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}, ) - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Variable/soc_to_rsoc.jl b/src/Bridges/Variable/soc_to_rsoc.jl index ad76c95f79..d39f912f7e 100644 --- a/src/Bridges/Variable/soc_to_rsoc.jl +++ b/src/Bridges/Variable/soc_to_rsoc.jl @@ -40,7 +40,7 @@ end # Attributes, Bridge acting as a model function MOI.get(bridge::SOCtoRSOCBridge, ::MOI.NumberOfVariables) - return length(bridge.variables) + return Int64(length(bridge.variables)) end function MOI.get(bridge::SOCtoRSOCBridge, ::MOI.ListOfVariableIndices) @@ -51,7 +51,7 @@ function MOI.get( bridge::SOCtoRSOCBridge, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.RotatedSecondOrderCone}, ) - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Variable/vectorize.jl b/src/Bridges/Variable/vectorize.jl index adf5cd5bc6..1492c75e1d 100644 --- a/src/Bridges/Variable/vectorize.jl +++ b/src/Bridges/Variable/vectorize.jl @@ -48,9 +48,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -function MOI.get(::VectorizeBridge, ::MOI.NumberOfVariables) - return 1 -end +MOI.get(::VectorizeBridge, ::MOI.NumberOfVariables) = Int64(1) function MOI.get(bridge::VectorizeBridge, ::MOI.ListOfVariableIndices) return [bridge.variable] @@ -60,7 +58,7 @@ function MOI.get( ::VectorizeBridge{T,S}, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,S}, ) where {T,S} - return 1 + return Int64(1) end function MOI.get( diff --git a/src/Bridges/Variable/zeros.jl b/src/Bridges/Variable/zeros.jl index d0553c9a5e..6014539050 100644 --- a/src/Bridges/Variable/zeros.jl +++ b/src/Bridges/Variable/zeros.jl @@ -40,7 +40,7 @@ function MOIB.added_constraint_types(::Type{<:ZerosBridge}) end # Attributes, Bridge acting as a model -MOI.get(bridge::ZerosBridge, ::MOI.NumberOfVariables) = 0 +MOI.get(::ZerosBridge, ::MOI.NumberOfVariables) = Int64(0) function MOI.get(bridge::ZerosBridge, ::MOI.ListOfVariableIndices) return MOI.VariableIndex[] diff --git a/src/Bridges/bridge.jl b/src/Bridges/bridge.jl index 3b7508f7c2..bf36c80c95 100644 --- a/src/Bridges/bridge.jl +++ b/src/Bridges/bridge.jl @@ -34,7 +34,7 @@ end The number of constraints of the type `F`-in-`S` created by the bridge `b` in the model. """ -MOI.get(::AbstractBridge, ::MOI.NumberOfConstraints) = 0 +MOI.get(::AbstractBridge, ::MOI.NumberOfConstraints) = Int64(0) """ MOI.get(b::AbstractBridge, ::MOI.ListOfConstraintIndices{F, S}) where {F, S} diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index 11e5c0e7ed..9151c7932a 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -718,7 +718,7 @@ function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.NumberOfVariables) for bridge in values(Objective.bridges(b)) s -= MOI.get(bridge, attr) end - return s + return Int64(s) end # Number of all constraints, including those bridged @@ -756,7 +756,7 @@ function MOI.get( for bridge in values(Objective.bridges(b)) s -= MOI.get(bridge, attr) end - return s + return Int64(s) end function MOI.get( diff --git a/src/Test/UnitTests/attributes.jl b/src/Test/UnitTests/attributes.jl index 0de503b44d..dab33b694a 100644 --- a/src/Test/UnitTests/attributes.jl +++ b/src/Test/UnitTests/attributes.jl @@ -128,3 +128,103 @@ function solve_time(model::MOI.ModelLike, config::Config) end end unittests["solve_time"] = solve_time + +# Model and Optimizer attributes. +for attr in ( + :BarrierIterations, + :ConflictStatus, + :DualStatus, + :Name, + :NodeCount, + :NumberOfThreads, + :NumberOfVariables, + :ObjectiveFunctionType, + :ObjectiveSense, + :PrimalStatus, + :RelativeGap, + :ResultCount, + :Silent, + :SimplexIterations, + :SolverName, + :SolveTime, + :TerminationStatus, + :TimeLimitSec, +) + f = Symbol("test_attribute_$(attr)") + @eval begin + function $(f)(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + MOI.optimize!(model) + attribute = MOI.$(attr)() + T = MOI.attribute_value_type(attribute) + @static if VERSION < v"1.5" + @test MOI.get(model, attribute) isa T + else + @test @inferred(T, MOI.get(model, attribute)) isa T + end + end + # unittests["test_attribute_$(attr)"] + end +end + +# Variable attributes. +for attr in (:VariableName,) + f = Symbol("test_attribute_$(attr)") + @eval begin + function $(f)(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + x = MOI.add_variable(model) + MOI.set(model, MOI.VariableName(), x, "x") + MOI.optimize!(model) + attribute = MOI.$(attr)() + T = MOI.attribute_value_type(attribute) + @static if VERSION < v"1.5" + @test MOI.get(model, attribute, x) isa T + else + @test @inferred(T, MOI.get(model, attribute, x)) isa T + end + end + # unittests["test_attribute_$(attr)"] + end +end + +# Constraint attributes. +for attr in ( + :CanonicalConstraintFunction, + :ConstraintFunction, + :ConstraintName, + :ConstraintSet, +) + f = Symbol("test_attribute_$(attr)") + @eval begin + function $(f)(model::MOI.ModelLike, config::TestConfig) + MOI.empty!(model) + x = MOI.add_variable(model) + ci = MOI.add_constraint( + model, + MOI.SingleVariable(x), + MOI.GreaterThan(0.0), + ) + MOI.optimize!(model) + MOI.set(model, MOI.ConstraintName(), ci, "ci") + attribute = MOI.$(attr)() + T = MOI.attribute_value_type(attribute) + @static if VERSION < v"1.5" + @test MOI.get(model, attribute, ci) isa T + else + @test @inferred(T, MOI.get(model, attribute, ci)) isa T + end + end + # unittests["test_attribute_$(attr)"] + end +end + +# TODO(odow): attributes not tested: +# CallbackNodeStatus() +# LazyConstraintCallback() +# NumberOfConstraints{F,S}() +# ObjectiveFunction{F}() +# ConstraintBasisStatus() +# ConstraintConflictStatus() +# VariableBridgingCost() +# ConstraintBridgingCost() diff --git a/src/Test/modellike.jl b/src/Test/modellike.jl index 0fe6b34987..57b093ec94 100644 --- a/src/Test/modellike.jl +++ b/src/Test/modellike.jl @@ -419,7 +419,7 @@ abstract type BadModel <: MOI.ModelLike end function MOI.get(::BadModel, ::MOI.ListOfModelAttributesSet) return MOI.AbstractModelAttribute[] end -MOI.get(::BadModel, ::MOI.NumberOfVariables) = 1 +MOI.get(::BadModel, ::MOI.NumberOfVariables) = Int64(1) MOI.get(::BadModel, ::MOI.ListOfVariableIndices) = [MOI.VariableIndex(1)] function MOI.get(::BadModel, ::MOI.ListOfVariableAttributesSet) return MOI.AbstractVariableAttribute[] diff --git a/src/Utilities/cachingoptimizer.jl b/src/Utilities/cachingoptimizer.jl index 3970cd0e21..0568065237 100644 --- a/src/Utilities/cachingoptimizer.jl +++ b/src/Utilities/cachingoptimizer.jl @@ -786,7 +786,7 @@ function MOI.get(model::CachingOptimizer, attr::MOI.AbstractModelAttribute) end return map_indices( model.optimizer_to_model_map, - MOI.get(model.optimizer, attr), + MOI.get(model.optimizer, attr)::MOI.attribute_value_type(attr), ) else return MOI.get(model.model_cache, attr) @@ -827,7 +827,11 @@ function MOI.get( end return map_indices( model.optimizer_to_model_map, - MOI.get(model.optimizer, attr, model.model_to_optimizer_map[index]), + MOI.get( + model.optimizer, + attr, + model.model_to_optimizer_map[index], + )::MOI.attribute_value_type(attr), ) else return MOI.get(model.model_cache, attr, index) @@ -851,7 +855,7 @@ function MOI.get( model.optimizer, attr, map(index -> model.model_to_optimizer_map[index], indices), - ), + )::Vector{<:MOI.attribute_value_type(attr)}, ) else return MOI.get(model.model_cache, attr, indices) @@ -920,7 +924,7 @@ function MOI.get(model::CachingOptimizer, attr::MOI.AbstractOptimizerAttribute) end return map_indices( model.optimizer_to_model_map, - MOI.get(model.optimizer, attr), + MOI.get(model.optimizer, attr)::MOI.attribute_value_type(attr), ) end @@ -963,7 +967,7 @@ function MOI.get( @assert m.state == ATTACHED_OPTIMIZER return map_indices( m.optimizer_to_model_map, - MOI.get(m.optimizer, attr.attr), + MOI.get(m.optimizer, attr.attr)::MOI.attribute_value_type(attr.attr), ) end @@ -977,7 +981,11 @@ function MOI.get( @assert m.state == ATTACHED_OPTIMIZER return map_indices( m.optimizer_to_model_map, - MOI.get(m.optimizer, attr.attr, m.model_to_optimizer_map[idx]), + MOI.get( + m.optimizer, + attr.attr, + m.model_to_optimizer_map[idx], + )::MOI.attribute_value_type(attr.attr), ) end @@ -995,7 +1003,7 @@ function MOI.get( m.optimizer, attr.attr, getindex.(m.model_to_optimizer_map, idx), - ), + )::Vector{<:MOI.attribute_value_type(attr.attr)}, ) end diff --git a/src/Utilities/functions.jl b/src/Utilities/functions.jl index e4e5b1c061..984e825df9 100644 --- a/src/Utilities/functions.jl +++ b/src/Utilities/functions.jl @@ -63,7 +63,7 @@ function eval_term(varval::Function, t::MOI.ScalarQuadraticTerm) end """ - map_indices(index_map::Function, x) + map_indices(index_map::Function, x::X)::X where {X} Substitute any [`MOI.VariableIndex`](@ref) (resp. [`MOI.ConstraintIndex`](@ref)) in `x` by the [`MOI.VariableIndex`](@ref) (resp. [`MOI.ConstraintIndex`](@ref)) @@ -77,11 +77,17 @@ submittable value. function map_indices end """ - map_indices(variable_map::AbstractDict{T, T}, x) where {T <: MOI.Index} + map_indices( + variable_map::AbstractDict{T,T}, + x::X, + )::X where {T<:MOI.Index,X} Shortcut for `map_indices(vi -> variable_map[vi], x)`. """ -function map_indices(variable_map::AbstractDict{T,T}, x) where {T<:MOI.Index} +function map_indices( + variable_map::AbstractDict{T,T}, + x::X, +)::X where {T<:MOI.Index,X} return map_indices(vi -> variable_map[vi], x) end diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index be7051dc45..3ebb96e4a2 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -649,13 +649,14 @@ function MOI.get( ::MOI.NumberOfConstraints{MOI.SingleVariable,S}, ) where {S} flag = single_variable_flag(S) - return count(mask -> !iszero(flag & mask), model.single_variable_mask) + n = count(mask -> !iszero(flag & mask), model.single_variable_mask) + return Int64(n) end function MOI.get( model::AbstractModel, noc::MOI.NumberOfConstraints{F,S}, ) where {F,S} - return MOI.get(model.constraints, noc) + return Int64(MOI.get(model.constraints, noc)) end function _add_constraint_type( @@ -1100,7 +1101,7 @@ for (loop_name, loop_super_type) in [ MOI.FEASIBILITY_SENSE, false, zero(MOI.ScalarAffineFunction{T}), - 0, + Int64(0), nothing, UInt8[], T[], diff --git a/src/Utilities/struct_of_constraints.jl b/src/Utilities/struct_of_constraints.jl index 619f551d0e..47cded7c7f 100644 --- a/src/Utilities/struct_of_constraints.jl +++ b/src/Utilities/struct_of_constraints.jl @@ -108,9 +108,9 @@ function MOI.get( attr::MOI.NumberOfConstraints{F,S}, ) where {F,S} if !MOI.supports_constraint(model, F, S) - return 0 + return Int64(0) end - return MOI.get(constraints(model, F, S), attr) + return Int64(MOI.get(constraints(model, F, S), attr)) end function MOI.get( diff --git a/src/Utilities/universalfallback.jl b/src/Utilities/universalfallback.jl index afc38fc224..45797fa9b6 100644 --- a/src/Utilities/universalfallback.jl +++ b/src/Utilities/universalfallback.jl @@ -322,7 +322,7 @@ end function MOI.get( uf::UniversalFallback, attr::MOI.NumberOfConstraints{MOI.SingleVariable,S}, -) where {S} +)::Int64 where {S} F = MOI.SingleVariable if MOI.supports_constraint(uf.model, F, S) return MOI.get(uf.model, attr) @@ -335,7 +335,7 @@ end function MOI.get( uf::UniversalFallback, attr::MOI.NumberOfConstraints{F,S}, -) where {F,S} +)::Int64 where {F,S} return MOI.get(constraints(uf, F, S), attr) end function MOI.get( diff --git a/src/Utilities/vector_of_constraints.jl b/src/Utilities/vector_of_constraints.jl index 286a0bbfb6..9376d7d2c6 100644 --- a/src/Utilities/vector_of_constraints.jl +++ b/src/Utilities/vector_of_constraints.jl @@ -125,7 +125,7 @@ function MOI.get( v::VectorOfConstraints{F,S}, ::MOI.NumberOfConstraints{F,S}, ) where {F,S} - return length(v.constraints) + return Int64(length(v.constraints)) end function MOI.get( diff --git a/src/attributes.jl b/src/attributes.jl index 8036b90217..ee86f36b74 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -47,6 +47,19 @@ const AnyAttribute = Union{ # embed it in a `Ref` Base.broadcastable(attribute::AnyAttribute) = Ref(attribute) +""" + attribute_value_type(attr::AnyAttribute) + +Given an attribute `attr`, return the type of value expected by [`get`](@ref), +or returned by [`set`](@ref). + +# Notes + + * Only implement this if it make sense to do so. If un-implemented, the default + is `Any`. +""" +attribute_value_type(::AnyAttribute) = Any + """ struct UnsupportedAttribute{AttrType} <: UnsupportedError attr::AttrType @@ -620,6 +633,7 @@ struct CallbackNodeStatus{CallbackDataType} <: AbstractOptimizerAttribute callback_data::CallbackDataType end is_set_by_optimize(::CallbackNodeStatus) = true +attribute_value_type(::CallbackNodeStatus) = CallbackNodeStatusCode ## Optimizer attributes @@ -636,6 +650,7 @@ struct ListOfOptimizerAttributesSet <: AbstractOptimizerAttribute end An optimizer attribute for the string identifying the solver/optimizer. """ struct SolverName <: AbstractOptimizerAttribute end +attribute_value_type(::SolverName) = String """ Silent() @@ -657,6 +672,7 @@ value given by the user for this solver-specific parameter or `1` if none is given. """ struct Silent <: AbstractOptimizerAttribute end +attribute_value_type(::Silent) = Bool """ TimeLimitSec() @@ -666,6 +682,7 @@ to `nothing`, it deactivates the solver time limit. The default value is `nothing`. The time limit is in seconds. """ # TODO add a test checking if the solver returns TIME_LIMIT status when the time limit is hit struct TimeLimitSec <: AbstractOptimizerAttribute end +attribute_value_type(::TimeLimitSec) = Union{Nothing,Float64} """ RawOptimizerAttribute(name::String) @@ -684,6 +701,7 @@ optimization. When set to `nothing` uses solver default. Values are positive integers. The default value is `nothing`. """ struct NumberOfThreads <: AbstractOptimizerAttribute end +attribute_value_type(::NumberOfThreads) = Union{Nothing,Int} ### Callbacks @@ -729,6 +747,7 @@ commonly called `callback_data`, that can be used for instance in [`UserCutCallback`](@ref). """ abstract type AbstractCallback <: AbstractModelAttribute end +attribute_value_type(::AbstractCallback) = Function """ LazyConstraintCallback() <: AbstractCallback @@ -838,6 +857,9 @@ A model attribute for the string identifying the model. It has a default value of `""` if not set`. """ struct Name <: AbstractModelAttribute end +attribute_value_type(::Name) = String + +@enum OptimizationSense MIN_SENSE MAX_SENSE FEASIBILITY_SENSE """ ObjectiveSense() @@ -847,8 +869,7 @@ must be an `OptimizationSense`: `MIN_SENSE`, `MAX_SENSE`, or `FEASIBILITY_SENSE`. The default is `FEASIBILITY_SENSE`. """ struct ObjectiveSense <: AbstractModelAttribute end - -@enum OptimizationSense MIN_SENSE MAX_SENSE FEASIBILITY_SENSE +attribute_value_type(::ObjectiveSense) = OptimizationSense """ NumberOfVariables() @@ -856,6 +877,7 @@ struct ObjectiveSense <: AbstractModelAttribute end A model attribute for the number of variables in the model. """ struct NumberOfVariables <: AbstractModelAttribute end +attribute_value_type(::NumberOfVariables) = Int64 """ ListOfVariableIndices() @@ -881,6 +903,7 @@ struct ListOfConstraintIndices{F,S} <: AbstractModelAttribute end A model attribute for the number of constraints of the type `F`-in-`S` present in the model. """ struct NumberOfConstraints{F,S} <: AbstractModelAttribute end +attribute_value_type(::NumberOfConstraints) = Int64 """ ListOfConstraintTypesPresent() @@ -902,6 +925,7 @@ e.g. the objective function is quadratic and `F` is `ScalarAffineFunction{Float6 it has non-integer coefficient and `F` is `ScalarAffineFunction{Int}`. """ struct ObjectiveFunction{F<:AbstractScalarFunction} <: AbstractModelAttribute end +attribute_value_type(::ObjectiveFunction{F}) where {F} = F """ ObjectiveFunctionType() @@ -920,6 +944,7 @@ attr = MOI.get(model, MOI.ObjectiveFunctionType()) ``` """ struct ObjectiveFunctionType <: AbstractModelAttribute end +attribute_value_type(::ObjectiveFunctionType) = Type{<:AbstractFunction} ## Optimizer attributes @@ -957,6 +982,7 @@ struct ObjectiveBound <: AbstractModelAttribute end A model attribute for the final relative optimality gap, defined as ``\\frac{|b-f|}{|f|}``, where ``b`` is the best bound and ``f`` is the best feasible objective value. """ struct RelativeGap <: AbstractModelAttribute end +attribute_value_type(::RelativeGap) = Float64 """ SolveTimeSec() @@ -964,6 +990,7 @@ struct RelativeGap <: AbstractModelAttribute end A model attribute for the total elapsed solution time (in seconds) as reported by the optimizer. """ struct SolveTimeSec <: AbstractModelAttribute end +attribute_value_type(::SolveTimeSec) = Float64 @deprecate SolveTime SolveTimeSec @@ -974,6 +1001,7 @@ A model attribute for the cumulative number of simplex iterations during the opt In particular, for a mixed-integer program (MIP), the total simplex iterations for all nodes. """ struct SimplexIterations <: AbstractModelAttribute end +attribute_value_type(::SimplexIterations) = Int """ BarrierIterations() @@ -981,6 +1009,7 @@ struct SimplexIterations <: AbstractModelAttribute end A model attribute for the cumulative number of barrier iterations while solving a problem. """ struct BarrierIterations <: AbstractModelAttribute end +attribute_value_type(::BarrierIterations) = Int """ NodeCount() @@ -988,6 +1017,7 @@ struct BarrierIterations <: AbstractModelAttribute end A model attribute for the total number of branch-and-bound nodes explored while solving a mixed-integer program (MIP). """ struct NodeCount <: AbstractModelAttribute end +attribute_value_type(::NodeCount) = Int """ RawSolver() @@ -1002,6 +1032,7 @@ struct RawSolver <: AbstractModelAttribute end A model attribute for the number of results available. """ struct ResultCount <: AbstractModelAttribute end +attribute_value_type(::ResultCount) = Int """ ConflictStatusCode @@ -1031,6 +1062,7 @@ A model attribute for the [`ConflictStatusCode`](@ref) explaining why the confli refiner stopped when computing the conflict. """ struct ConflictStatus <: AbstractModelAttribute end +attribute_value_type(::ConflictStatus) = ConflictStatusCode ## Variable attributes @@ -1052,6 +1084,7 @@ cannot be looked up using [`get`](@ref). It has a default value of `""` if not set`. """ struct VariableName <: AbstractVariableAttribute end +attribute_value_type(::VariableName) = String """ VariablePrimalStart() @@ -1151,6 +1184,7 @@ regardless of whether they have the same `F`-in-`S` type. You should _not_ implement `ConstraintName` for `SingleVariable` constraints. """ struct ConstraintName <: AbstractConstraintAttribute end +attribute_value_type(::ConstraintName) = String """ SingleVariableConstraintNameError() @@ -1232,6 +1266,7 @@ struct ConstraintBasisStatus <: AbstractConstraintAttribute result_index::Int end ConstraintBasisStatus() = ConstraintBasisStatus(1) +attribute_value_type(::ConstraintBasisStatus) = BasisStatusCode """ CanonicalConstraintFunction() @@ -1253,6 +1288,8 @@ then it returns the function stored internally instead of a copy. """ struct CanonicalConstraintFunction <: AbstractConstraintAttribute end +attribute_value_type(::CanonicalConstraintFunction) = AbstractFunction + function get_fallback( model::ModelLike, ::CanonicalConstraintFunction, @@ -1281,6 +1318,8 @@ It is guaranteed to be equivalent but not necessarily identical to the function """ struct ConstraintFunction <: AbstractConstraintAttribute end +attribute_value_type(::ConstraintFunction) = AbstractFunction + function throw_set_error_fallback( ::ModelLike, attr::ConstraintFunction, @@ -1312,6 +1351,8 @@ A constraint attribute for the `AbstractSet` object used to define the constrain """ struct ConstraintSet <: AbstractConstraintAttribute end +attribute_value_type(::ConstraintSet) = AbstractSet + function throw_set_error_fallback( ::ModelLike, attr::ConstraintSet, @@ -1364,14 +1405,11 @@ A constraint attribute indicating whether the constraint participates in the conflict. Its type is [`ConflictParticipationStatusCode`](@ref). """ struct ConstraintConflictStatus <: AbstractConstraintAttribute end +function attribute_value_type(::ConstraintConflictStatus) + return ConflictParticipationStatusCode +end ## Termination status -""" - TerminationStatus() - -A model attribute for the `TerminationStatusCode` explaining why the optimizer stopped. -""" -struct TerminationStatus <: AbstractModelAttribute end """ TerminationStatusCode @@ -1485,6 +1523,14 @@ This group of statuses means that something unexpected or problematic happened. OTHER_ERROR ) +""" + TerminationStatus() + +A model attribute for the `TerminationStatusCode` explaining why the optimizer stopped. +""" +struct TerminationStatus <: AbstractModelAttribute end +attribute_value_type(::TerminationStatus) = TerminationStatusCode + """ RawStatusString() @@ -1492,6 +1538,7 @@ A model attribute for a solver specific string explaining why the optimizer stopped. """ struct RawStatusString <: AbstractModelAttribute end +attribute_value_type(::RawStatusString) = String ## Result status @@ -1554,6 +1601,7 @@ struct PrimalStatus <: AbstractModelAttribute result_index::Int end PrimalStatus() = PrimalStatus(1) +attribute_value_type(::PrimalStatus) = ResultStatusCode """ DualStatus(result_index) @@ -1569,9 +1617,13 @@ struct DualStatus <: AbstractModelAttribute result_index::Int end DualStatus() = DualStatus(1) +attribute_value_type(::DualStatus) = ResultStatusCode # Cost of bridging constrained variable in S struct VariableBridgingCost{S<:AbstractSet} <: AbstractModelAttribute end + +attribute_value_type(::VariableBridgingCost) = Float64 + function get_fallback( model::ModelLike, ::VariableBridgingCost{S}, @@ -1588,6 +1640,9 @@ end # Cost of bridging F-in-S constraints struct ConstraintBridgingCost{F<:AbstractFunction,S<:AbstractSet} <: AbstractModelAttribute end + +attribute_value_type(::ConstraintBridgingCost) = Float64 + function get_fallback( model::ModelLike, ::ConstraintBridgingCost{F,S}, diff --git a/test/Utilities/mockoptimizer.jl b/test/Utilities/mockoptimizer.jl index 8eed826afc..5a167c24e2 100644 --- a/test/Utilities/mockoptimizer.jl +++ b/test/Utilities/mockoptimizer.jl @@ -236,3 +236,69 @@ end MOI.NOT_IN_CONFLICT @test MOI.get(mock, MOI.ConstraintConflictStatus(), c) == MOI.IN_CONFLICT end + +@testset "test_model_optimizer_attributes" begin + model = MOI.Utilities.MockOptimizer( + MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), + ) + config = MOI.Test.TestConfig() + MOI.set(model, MOI.NumberOfThreads(), 4) + MOI.set(model, MOI.Silent(), true) + MOI.Utilities.set_mock_optimize!( + model, + mock -> MOI.set(mock, MOI.BarrierIterations(), 1), + mock -> nothing, # ConflictStatus + mock -> nothing, # DualStatus + mock -> MOI.set(mock, MOI.Name(), "Mock"), + mock -> MOI.set(mock, MOI.NodeCount(), 1), + mock -> nothing, # NumberOfThreads + mock -> nothing, # NumberOfVariables + mock -> nothing, # ObjectiveFunctionType + mock -> nothing, # ObjectiveSense + mock -> nothing, # PrimalStatus + mock -> MOI.set(mock, MOI.RelativeGap(), 0.0), + mock -> nothing, # ResultCount + mock -> nothing, # Silent + mock -> MOI.set(mock, MOI.SimplexIterations(), 1), + mock -> nothing, + mock -> MOI.set(mock, MOI.SolveTime(), 1.0), + mock -> MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL), + mock -> MOI.set(mock, MOI.TimeLimitSec(), 1.0), + ) + MOI.Test.test_attribute_BarrierIterations(model, config) + MOI.Test.test_attribute_ConflictStatus(model, config) + MOI.Test.test_attribute_DualStatus(model, config) + MOI.Test.test_attribute_Name(model, config) + MOI.Test.test_attribute_NodeCount(model, config) + MOI.Test.test_attribute_NumberOfThreads(model, config) + MOI.Test.test_attribute_NumberOfVariables(model, config) + MOI.Test.test_attribute_ObjectiveFunctionType(model, config) + MOI.Test.test_attribute_ObjectiveSense(model, config) + MOI.Test.test_attribute_PrimalStatus(model, config) + MOI.Test.test_attribute_RelativeGap(model, config) + MOI.Test.test_attribute_ResultCount(model, config) + MOI.Test.test_attribute_Silent(model, config) + MOI.Test.test_attribute_SimplexIterations(model, config) + MOI.Test.test_attribute_SolverName(model, config) + MOI.Test.test_attribute_SolveTime(model, config) + MOI.Test.test_attribute_TerminationStatus(model, config) + MOI.Test.test_attribute_TimeLimitSec(model, config) +end + +@testset "test_variable_attributes" begin + model = MOI.Utilities.MockOptimizer( + MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), + ) + config = MOI.Test.TestConfig() + MOI.Test.test_attribute_VariableName(model, config) +end + +@testset "test_constraint_attributes" begin + model = MOI.Utilities.MockOptimizer( + MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), + ) + config = MOI.Test.TestConfig() + MOI.Test.test_attribute_ConstraintFunction(model, config) + MOI.Test.test_attribute_ConstraintName(model, config) + MOI.Test.test_attribute_ConstraintSet(model, config) +end From f021eab92f5598005b4f3e3c6eaf789ead5e753f Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 11 May 2021 13:53:44 +1200 Subject: [PATCH 02/12] Add docs and breaking tests --- docs/src/manual/implementing.md | 5 ++ docs/src/reference/models.md | 1 + src/Test/UnitTests/attributes.jl | 85 +++++++++++++++++++++-------- test/Test/unit.jl | 22 ++++++++ test/Utilities/cachingoptimizer.jl | 12 +++- test/Utilities/mockoptimizer.jl | 28 ++++------ test/Utilities/universalfallback.jl | 12 +++- 7 files changed, 124 insertions(+), 41 deletions(-) diff --git a/docs/src/manual/implementing.md b/docs/src/manual/implementing.md index 336eca9654..08ea407f8b 100644 --- a/docs/src/manual/implementing.md +++ b/docs/src/manual/implementing.md @@ -271,6 +271,11 @@ For each attribute * [`supports`](@ref) returns a `Bool` indicating whether the solver supports the attribute. +!!! info + Use [`attribute_value_type`](@ref) to check the value expected by a given + attribute. You should make sure that your [`get`](@ref) function correctly + infers to this type (or a subtype of it). + Each column in the table indicates whether you need to implement the particular method for each attribute. diff --git a/docs/src/reference/models.md b/docs/src/reference/models.md index 76f9a9154b..7efc192469 100644 --- a/docs/src/reference/models.md +++ b/docs/src/reference/models.md @@ -18,6 +18,7 @@ get get! set supports +attribute_value_type ``` ## Model interface diff --git a/src/Test/UnitTests/attributes.jl b/src/Test/UnitTests/attributes.jl index dab33b694a..381fc66a97 100644 --- a/src/Test/UnitTests/attributes.jl +++ b/src/Test/UnitTests/attributes.jl @@ -146,37 +146,54 @@ for attr in ( :Silent, :SimplexIterations, :SolverName, - :SolveTime, + :SolveTimeSec, :TerminationStatus, :TimeLimitSec, ) f = Symbol("test_attribute_$(attr)") - @eval begin - function $(f)(model::MOI.ModelLike, config::TestConfig) + unittests["test_attribute_$(attr)"] = @eval begin + function $(f)(model::MOI.ModelLike, config::Config) MOI.empty!(model) - MOI.optimize!(model) attribute = MOI.$(attr)() + if MOI.is_set_by_optimize(attribute) + if !config.solve + return + end + MOI.optimize!(model) + end T = MOI.attribute_value_type(attribute) + try + MOI.get(model, attribute) + catch err + if err isa ArgumentError + return # Solver does not support accessing the attribute. + end + end + @static if VERSION < v"1.5" @test MOI.get(model, attribute) isa T else @test @inferred(T, MOI.get(model, attribute)) isa T end end - # unittests["test_attribute_$(attr)"] end end # Variable attributes. for attr in (:VariableName,) f = Symbol("test_attribute_$(attr)") - @eval begin - function $(f)(model::MOI.ModelLike, config::TestConfig) + unittests["test_attribute_$(attr)"] = @eval begin + function $(f)(model::MOI.ModelLike, config::Config) MOI.empty!(model) x = MOI.add_variable(model) MOI.set(model, MOI.VariableName(), x, "x") - MOI.optimize!(model) attribute = MOI.$(attr)() + if MOI.is_set_by_optimize(attribute) + if !config.solve + return + end + MOI.optimize!(model) + end T = MOI.attribute_value_type(attribute) @static if VERSION < v"1.5" @test MOI.get(model, attribute, x) isa T @@ -184,7 +201,6 @@ for attr in (:VariableName,) @test @inferred(T, MOI.get(model, attribute, x)) isa T end end - # unittests["test_attribute_$(attr)"] end end @@ -196,26 +212,51 @@ for attr in ( :ConstraintSet, ) f = Symbol("test_attribute_$(attr)") - @eval begin - function $(f)(model::MOI.ModelLike, config::TestConfig) + unittests["test_attribute_$(attr)"] = @eval begin + function $(f)(model::MOI.ModelLike, config::Config{T}) where {T} MOI.empty!(model) x = MOI.add_variable(model) - ci = MOI.add_constraint( - model, - MOI.SingleVariable(x), - MOI.GreaterThan(0.0), - ) - MOI.optimize!(model) - MOI.set(model, MOI.ConstraintName(), ci, "ci") + ci = + if MOI.supports_constraint( + model, + MOI.ScalarAffineFunction{T}, + MOI.GreaterThan{T}, + ) + MOI.add_constraint( + model, + MOI.ScalarAffineFunction( + [MOI.ScalarAffineTerm(one(T), x)], + zero(T), + ), + MOI.GreaterThan(zero(T)), + ) + elseif MOI.supports_constraint( + model, + MOI.VectorOfVariables, + MOI.Nonnegatives, + ) + MOI.add_constraint( + model, + MOI.VectorOfVariables([x]), + MOI.Nonnegatives(1), + ) + else + return + end attribute = MOI.$(attr)() - T = MOI.attribute_value_type(attribute) + if MOI.is_set_by_optimize(attribute) + if !config.solve + return + end + MOI.optimize!(model) + end + VT = MOI.attribute_value_type(attribute) @static if VERSION < v"1.5" - @test MOI.get(model, attribute, ci) isa T + @test MOI.get(model, attribute, ci) isa VT else - @test @inferred(T, MOI.get(model, attribute, ci)) isa T + @test @inferred(T, MOI.get(model, attribute, ci)) isa VT end end - # unittests["test_attribute_$(attr)"] end end diff --git a/test/Test/unit.jl b/test/Test/unit.jl index 961b3476bc..a71d007820 100644 --- a/test/Test/unit.jl +++ b/test/Test/unit.jl @@ -67,6 +67,28 @@ end "solve_farkas_variable_lessthan", "solve_farkas_variable_lessthan_max", "solve_twice", + "test_attribute_BarrierIterations", + "test_attribute_ConflictStatus", + "test_attribute_DualStatus", + "test_attribute_Name", + "test_attribute_NodeCount", + "test_attribute_NumberOfThreads", + "test_attribute_NumberOfVariables", + "test_attribute_ObjectiveFunctionType", + "test_attribute_ObjectiveSense", + "test_attribute_PrimalStatus", + "test_attribute_RelativeGap", + "test_attribute_ResultCount", + "test_attribute_Silent", + "test_attribute_SimplexIterations", + "test_attribute_SolverName", + "test_attribute_SolveTimeSec", + "test_attribute_TerminationStatus", + "test_attribute_TimeLimitSec", + "test_attribute_VariableName", + "test_attribute_ConstraintFunction", + "test_attribute_ConstraintName", + "test_attribute_ConstraintSet", ], ) MOI.empty!(model) diff --git a/test/Utilities/cachingoptimizer.jl b/test/Utilities/cachingoptimizer.jl index 9a2f3d0cb2..7b8c82025b 100644 --- a/test/Utilities/cachingoptimizer.jl +++ b/test/Utilities/cachingoptimizer.jl @@ -556,7 +556,17 @@ for state in (MOIU.NO_OPTIMIZER, MOIU.EMPTY_OPTIMIZER, MOIU.ATTACHED_OPTIMIZER) config = MOIT.Config(solve = false) @testset "Unit" begin - MOIT.unittest(m, config) + MOIT.unittest( + m, + config, + # Exclude these tests because no optimizer is attached. + [ + "test_attribute_Silent", + "test_attribute_SolverName", + "test_attribute_NumberOfThreads", + "test_attribute_TimeLimitSec", + ], + ) end @testset "Continuous Linear" begin exclude = ["partial_start"] # VariablePrimalStart not supported. diff --git a/test/Utilities/mockoptimizer.jl b/test/Utilities/mockoptimizer.jl index 5a167c24e2..02ee1e23da 100644 --- a/test/Utilities/mockoptimizer.jl +++ b/test/Utilities/mockoptimizer.jl @@ -241,29 +241,23 @@ end model = MOI.Utilities.MockOptimizer( MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), ) - config = MOI.Test.TestConfig() + config = MOI.Test.Config() MOI.set(model, MOI.NumberOfThreads(), 4) MOI.set(model, MOI.Silent(), true) + MOI.set(model, MOI.Name(), "Mock") + MOI.set(model, MOI.TimeLimitSec(), 1.0) MOI.Utilities.set_mock_optimize!( model, mock -> MOI.set(mock, MOI.BarrierIterations(), 1), - mock -> nothing, # ConflictStatus - mock -> nothing, # DualStatus - mock -> MOI.set(mock, MOI.Name(), "Mock"), + mock -> nothing, + mock -> nothing, mock -> MOI.set(mock, MOI.NodeCount(), 1), - mock -> nothing, # NumberOfThreads - mock -> nothing, # NumberOfVariables - mock -> nothing, # ObjectiveFunctionType - mock -> nothing, # ObjectiveSense - mock -> nothing, # PrimalStatus + mock -> nothing, mock -> MOI.set(mock, MOI.RelativeGap(), 0.0), - mock -> nothing, # ResultCount - mock -> nothing, # Silent - mock -> MOI.set(mock, MOI.SimplexIterations(), 1), mock -> nothing, - mock -> MOI.set(mock, MOI.SolveTime(), 1.0), + mock -> MOI.set(mock, MOI.SimplexIterations(), 1), + mock -> MOI.set(mock, MOI.SolveTimeSec(), 1.0), mock -> MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL), - mock -> MOI.set(mock, MOI.TimeLimitSec(), 1.0), ) MOI.Test.test_attribute_BarrierIterations(model, config) MOI.Test.test_attribute_ConflictStatus(model, config) @@ -280,7 +274,7 @@ end MOI.Test.test_attribute_Silent(model, config) MOI.Test.test_attribute_SimplexIterations(model, config) MOI.Test.test_attribute_SolverName(model, config) - MOI.Test.test_attribute_SolveTime(model, config) + MOI.Test.test_attribute_SolveTimeSec(model, config) MOI.Test.test_attribute_TerminationStatus(model, config) MOI.Test.test_attribute_TimeLimitSec(model, config) end @@ -289,7 +283,7 @@ end model = MOI.Utilities.MockOptimizer( MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), ) - config = MOI.Test.TestConfig() + config = MOI.Test.Config() MOI.Test.test_attribute_VariableName(model, config) end @@ -297,7 +291,7 @@ end model = MOI.Utilities.MockOptimizer( MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()), ) - config = MOI.Test.TestConfig() + config = MOI.Test.Config() MOI.Test.test_attribute_ConstraintFunction(model, config) MOI.Test.test_attribute_ConstraintName(model, config) MOI.Test.test_attribute_ConstraintSet(model, config) diff --git a/test/Utilities/universalfallback.jl b/test/Utilities/universalfallback.jl index 2df241592f..1cb7d3babf 100644 --- a/test/Utilities/universalfallback.jl +++ b/test/Utilities/universalfallback.jl @@ -291,7 +291,17 @@ config = MOIT.Config(solve = false) @test MOI.is_empty(uf) end @testset "Unit" begin - MOIT.unittest(uf, config) + MOIT.unittest( + uf, + config, + # Exclude these tests because no optimizer is attached. + [ + "test_attribute_Silent", + "test_attribute_SolverName", + "test_attribute_NumberOfThreads", + "test_attribute_TimeLimitSec", + ], + ) end @testset "Modification" begin MOIT.modificationtest(uf, config) From f748730e4b3c7de6ddd31e9bda44a0fbec636b9d Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 4 Aug 2021 13:40:59 +1200 Subject: [PATCH 03/12] Fix formatting --- src/Test/test_basic_constraint.jl | 3 ++- src/Test/test_linear.jl | 12 ++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Test/test_basic_constraint.jl b/src/Test/test_basic_constraint.jl index 0eb7c8b8d4..c771f86e8c 100644 --- a/src/Test/test_basic_constraint.jl +++ b/src/Test/test_basic_constraint.jl @@ -167,7 +167,8 @@ function _basic_constraint_test_helper( if _supports(config, MOI.ConstraintFunction) @test MOI.get(model, MOI.ConstraintFunction(), c) ≈ constraint_function _test_attribute_value_type(model, MOI.ConstraintFunction(), c) - @test MOI.get(model, MOI.CanonicalConstraintFunction(), c) ≈ constraint_function + @test MOI.get(model, MOI.CanonicalConstraintFunction(), c) ≈ + constraint_function _test_attribute_value_type(model, MOI.CanonicalConstraintFunction(), c) end ### diff --git a/src/Test/test_linear.jl b/src/Test/test_linear.jl index a35ae7dd56..d1f62edeab 100644 --- a/src/Test/test_linear.jl +++ b/src/Test/test_linear.jl @@ -640,16 +640,8 @@ function test_linear_integration_2( @test MOI.get(model, MOI.VariableBasisStatus(), y) == MOI.NONBASIC_AT_LOWER @test MOI.get(model, MOI.ConstraintBasisStatus(), c) == MOI.NONBASIC - _test_attribute_value_type( - model, - MOI.ConstraintBasisStatus(), - c, - ) - _test_attribute_value_type( - model, - MOI.VariableBasisStatus(), - x, - ) + _test_attribute_value_type(model, MOI.ConstraintBasisStatus(), c) + _test_attribute_value_type(model, MOI.VariableBasisStatus(), x) end end end From a6dbc9f937455c334d6c4e313a6770a42bbd4a9f Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 4 Aug 2021 16:30:29 +1200 Subject: [PATCH 04/12] Test getting CanonicalConstraintFunction --- src/Bridges/Constraint/function_conversion.jl | 12 ++++++++++++ src/Test/test_basic_constraint.jl | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Bridges/Constraint/function_conversion.jl b/src/Bridges/Constraint/function_conversion.jl index 184c9bccc7..dcbd95e29b 100644 --- a/src/Bridges/Constraint/function_conversion.jl +++ b/src/Bridges/Constraint/function_conversion.jl @@ -49,6 +49,18 @@ function MOI.set( return end +function MOI.get( + model::MOI.ModelLike, + ::MOI.CanonicalConstraintFunction, + bridge::AbstractFunctionConversionBridge, +) + f = MOI.get(model, MOI.ConstraintFunction()) + if !MOI.Utilities.is_canonical(f) + return MOI.Utilities.canonical(f) + end + return f +end + """ invariant_under_function_conversion(attr::MOI.AbstractConstraintAttribute) diff --git a/src/Test/test_basic_constraint.jl b/src/Test/test_basic_constraint.jl index c771f86e8c..241ec7965f 100644 --- a/src/Test/test_basic_constraint.jl +++ b/src/Test/test_basic_constraint.jl @@ -166,9 +166,9 @@ function _basic_constraint_test_helper( ### if _supports(config, MOI.ConstraintFunction) @test MOI.get(model, MOI.ConstraintFunction(), c) ≈ constraint_function - _test_attribute_value_type(model, MOI.ConstraintFunction(), c) @test MOI.get(model, MOI.CanonicalConstraintFunction(), c) ≈ constraint_function + _test_attribute_value_type(model, MOI.ConstraintFunction(), c) _test_attribute_value_type(model, MOI.CanonicalConstraintFunction(), c) end ### From e75844bcf65225b16a855d8aa531d1775d24dd9f Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 4 Aug 2021 16:50:28 +1200 Subject: [PATCH 05/12] Fix --- src/Bridges/Constraint/function_conversion.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/Constraint/function_conversion.jl b/src/Bridges/Constraint/function_conversion.jl index dcbd95e29b..a02c2f0a48 100644 --- a/src/Bridges/Constraint/function_conversion.jl +++ b/src/Bridges/Constraint/function_conversion.jl @@ -54,7 +54,7 @@ function MOI.get( ::MOI.CanonicalConstraintFunction, bridge::AbstractFunctionConversionBridge, ) - f = MOI.get(model, MOI.ConstraintFunction()) + f = MOI.get(model, MOI.ConstraintFunction(), bridge) if !MOI.Utilities.is_canonical(f) return MOI.Utilities.canonical(f) end From a4f0fed0f37d51fda57f0c7ab57f46bd0cd658ab Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 5 Aug 2021 11:22:33 +1200 Subject: [PATCH 06/12] Improve coverage --- src/attributes.jl | 33 +++++++++++++++++++++++++++++---- test/attributes.jl | 15 +++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/attributes.jl b/src/attributes.jl index e30d8a2a82..867b38261b 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -671,7 +671,9 @@ Returns a [`CallbackNodeStatusCode`](@ref) Enum. struct CallbackNodeStatus{CallbackDataType} <: AbstractOptimizerAttribute callback_data::CallbackDataType end + is_set_by_optimize(::CallbackNodeStatus) = true + attribute_value_type(::CallbackNodeStatus) = CallbackNodeStatusCode ## Optimizer attributes @@ -689,6 +691,7 @@ struct ListOfOptimizerAttributesSet <: AbstractOptimizerAttribute end An optimizer attribute for the string identifying the solver/optimizer. """ struct SolverName <: AbstractOptimizerAttribute end + attribute_value_type(::SolverName) = String """ @@ -711,6 +714,7 @@ value given by the user for this solver-specific parameter or `1` if none is given. """ struct Silent <: AbstractOptimizerAttribute end + attribute_value_type(::Silent) = Bool """ @@ -721,6 +725,7 @@ to `nothing`, it deactivates the solver time limit. The default value is `nothing`. The time limit is in seconds. """ # TODO add a test checking if the solver returns TIME_LIMIT status when the time limit is hit struct TimeLimitSec <: AbstractOptimizerAttribute end + attribute_value_type(::TimeLimitSec) = Union{Nothing,Float64} """ @@ -740,6 +745,7 @@ optimization. When set to `nothing` uses solver default. Values are positive integers. The default value is `nothing`. """ struct NumberOfThreads <: AbstractOptimizerAttribute end + attribute_value_type(::NumberOfThreads) = Union{Nothing,Int} ### Callbacks @@ -786,6 +792,7 @@ commonly called `callback_data`, that can be used for instance in [`UserCutCallback`](@ref). """ abstract type AbstractCallback <: AbstractModelAttribute end + attribute_value_type(::AbstractCallback) = Function """ @@ -896,6 +903,7 @@ A model attribute for the string identifying the model. It has a default value of `""` if not set`. """ struct Name <: AbstractModelAttribute end + attribute_value_type(::Name) = String @enum OptimizationSense MIN_SENSE MAX_SENSE FEASIBILITY_SENSE @@ -908,6 +916,7 @@ must be an `OptimizationSense`: `MIN_SENSE`, `MAX_SENSE`, or `FEASIBILITY_SENSE`. The default is `FEASIBILITY_SENSE`. """ struct ObjectiveSense <: AbstractModelAttribute end + attribute_value_type(::ObjectiveSense) = OptimizationSense """ @@ -916,6 +925,7 @@ attribute_value_type(::ObjectiveSense) = OptimizationSense A model attribute for the number of variables in the model. """ struct NumberOfVariables <: AbstractModelAttribute end + attribute_value_type(::NumberOfVariables) = Int64 """ @@ -942,6 +952,7 @@ struct ListOfConstraintIndices{F,S} <: AbstractModelAttribute end A model attribute for the number of constraints of the type `F`-in-`S` present in the model. """ struct NumberOfConstraints{F,S} <: AbstractModelAttribute end + attribute_value_type(::NumberOfConstraints) = Int64 """ @@ -964,6 +975,7 @@ e.g. the objective function is quadratic and `F` is `ScalarAffineFunction{Float6 it has non-integer coefficient and `F` is `ScalarAffineFunction{Int}`. """ struct ObjectiveFunction{F<:AbstractScalarFunction} <: AbstractModelAttribute end + attribute_value_type(::ObjectiveFunction{F}) where {F} = F """ @@ -983,6 +995,7 @@ attr = MOI.get(model, MOI.ObjectiveFunctionType()) ``` """ struct ObjectiveFunctionType <: AbstractModelAttribute end + attribute_value_type(::ObjectiveFunctionType) = Type{<:AbstractFunction} ## Optimizer attributes @@ -1025,6 +1038,7 @@ struct ObjectiveBound <: AbstractModelAttribute end A model attribute for the final relative optimality gap, defined as ``\\frac{|b-f|}{|f|}``, where ``b`` is the best bound and ``f`` is the best feasible objective value. """ struct RelativeGap <: AbstractModelAttribute end + attribute_value_type(::RelativeGap) = Float64 """ @@ -1033,6 +1047,7 @@ attribute_value_type(::RelativeGap) = Float64 A model attribute for the total elapsed solution time (in seconds) as reported by the optimizer. """ struct SolveTimeSec <: AbstractModelAttribute end + attribute_value_type(::SolveTimeSec) = Float64 @deprecate SolveTime SolveTimeSec @@ -1044,7 +1059,8 @@ A model attribute for the cumulative number of simplex iterations during the opt In particular, for a mixed-integer program (MIP), the total simplex iterations for all nodes. """ struct SimplexIterations <: AbstractModelAttribute end -attribute_value_type(::SimplexIterations) = Int + +attribute_value_type(::SimplexIterations) = Int64 """ BarrierIterations() @@ -1052,7 +1068,8 @@ attribute_value_type(::SimplexIterations) = Int A model attribute for the cumulative number of barrier iterations while solving a problem. """ struct BarrierIterations <: AbstractModelAttribute end -attribute_value_type(::BarrierIterations) = Int + +attribute_value_type(::BarrierIterations) = Int64 """ NodeCount() @@ -1060,7 +1077,8 @@ attribute_value_type(::BarrierIterations) = Int A model attribute for the total number of branch-and-bound nodes explored while solving a mixed-integer program (MIP). """ struct NodeCount <: AbstractModelAttribute end -attribute_value_type(::NodeCount) = Int + +attribute_value_type(::NodeCount) = Int64 """ RawSolver() @@ -1098,7 +1116,8 @@ corresponding [`PrimalStatus`](@ref) or [`DualStatus`](@ref) is results may be alternate certificates, or infeasible points. """ struct ResultCount <: AbstractModelAttribute end -attribute_value_type(::ResultCount) = Int + +attribute_value_type(::ResultCount) = Int64 """ ConflictStatusCode @@ -1128,6 +1147,7 @@ A model attribute for the [`ConflictStatusCode`](@ref) explaining why the confli refiner stopped when computing the conflict. """ struct ConflictStatus <: AbstractModelAttribute end + attribute_value_type(::ConflictStatus) = ConflictStatusCode ## Variable attributes @@ -1150,6 +1170,7 @@ cannot be looked up using [`get`](@ref). It has a default value of `""` if not set`. """ struct VariableName <: AbstractVariableAttribute end + attribute_value_type(::VariableName) = String """ @@ -1266,6 +1287,7 @@ regardless of whether they have the same `F`-in-`S` type. You should _not_ implement `ConstraintName` for `SingleVariable` constraints. """ struct ConstraintName <: AbstractConstraintAttribute end + attribute_value_type(::ConstraintName) = String """ @@ -1511,6 +1533,7 @@ A constraint attribute indicating whether the constraint participates in the conflict. Its type is [`ConflictParticipationStatusCode`](@ref). """ struct ConstraintConflictStatus <: AbstractConstraintAttribute end + function attribute_value_type(::ConstraintConflictStatus) return ConflictParticipationStatusCode end @@ -1635,6 +1658,7 @@ This group of statuses means that something unexpected or problematic happened. A model attribute for the `TerminationStatusCode` explaining why the optimizer stopped. """ struct TerminationStatus <: AbstractModelAttribute end + attribute_value_type(::TerminationStatus) = TerminationStatusCode """ @@ -1644,6 +1668,7 @@ A model attribute for a solver specific string explaining why the optimizer stopped. """ struct RawStatusString <: AbstractModelAttribute end + attribute_value_type(::RawStatusString) = String ## Result status diff --git a/test/attributes.jl b/test/attributes.jl index c1d9983623..a75dfab24c 100644 --- a/test/attributes.jl +++ b/test/attributes.jl @@ -194,6 +194,21 @@ function test_UnsupportedSubmittable() ) end +function test_attribute_value_type() + @test MOI.attribute_value_type(MOI.CallbackNodeStatus(1)) == + MOI.CallbackNodeStatusCode + @test MOI.attribute_value_type(MOI.LazyConstraintCallback()) == Function + @test MOI.attribute_value_type(MOI.RelativeGap()) == Float64 + @test MOI.attribute_value_type(MOI.SimplexIterations()) == Int64 + @test MOI.attribute_value_type(MOI.BarrierIterations()) == Int64 + @test MOI.attribute_value_type(MOI.NodeCount()) == Int64 + @test MOI.attribute_value_type( + MOI.ConstraintBridgingCost{MOI.SingleVariable,MOI.ZeroOne}(), + ) == Float64 + @test MOI.attribute_value_type(MOI.VariableBridgingCost{MOI.ZeroOne}()) == + Float64 +end + function runtests() for name in names(@__MODULE__; all = true) if startswith("$name", "test_") From a1c138bc078ccc192b3663cce271c67a7104fdfb Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 5 Aug 2021 11:45:42 +1200 Subject: [PATCH 07/12] Fix ResultCount in mockoptimizer --- src/Utilities/mockoptimizer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utilities/mockoptimizer.jl b/src/Utilities/mockoptimizer.jl index dd2c7e80d5..f96a7977dd 100644 --- a/src/Utilities/mockoptimizer.jl +++ b/src/Utilities/mockoptimizer.jl @@ -39,7 +39,7 @@ mutable struct MockOptimizer{MT<:MOI.ModelLike} <: MOI.AbstractOptimizer optimize!::Function optimize_called::Bool termination_status::MOI.TerminationStatusCode - result_count::Int + result_count::Int64 objective_value::Dict{Int,Float64} dual_objective_value::Dict{Int,Float64} # Primal solution From 5d7316bae65941c60413de54ca76bc113dbb53b8 Mon Sep 17 00:00:00 2001 From: odow Date: Thu, 5 Aug 2021 17:48:28 +1200 Subject: [PATCH 08/12] Fix on 32-bit --- src/Utilities/mockoptimizer.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utilities/mockoptimizer.jl b/src/Utilities/mockoptimizer.jl index f96a7977dd..df7df793a5 100644 --- a/src/Utilities/mockoptimizer.jl +++ b/src/Utilities/mockoptimizer.jl @@ -96,7 +96,7 @@ function MockOptimizer( (::MockOptimizer) -> nothing, false, MOI.OPTIMIZE_NOT_CALLED, - 1, + Int64(1), Dict{Int,Float64}(), Dict{Int,Float64}(), # PrimalStatus From fcb3bb193c79d4a481ad611d32899d40680862a0 Mon Sep 17 00:00:00 2001 From: odow Date: Fri, 6 Aug 2021 10:34:39 +1200 Subject: [PATCH 09/12] Fix ResultCount --- src/Utilities/mockoptimizer.jl | 4 ++-- src/attributes.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Utilities/mockoptimizer.jl b/src/Utilities/mockoptimizer.jl index df7df793a5..dd2c7e80d5 100644 --- a/src/Utilities/mockoptimizer.jl +++ b/src/Utilities/mockoptimizer.jl @@ -39,7 +39,7 @@ mutable struct MockOptimizer{MT<:MOI.ModelLike} <: MOI.AbstractOptimizer optimize!::Function optimize_called::Bool termination_status::MOI.TerminationStatusCode - result_count::Int64 + result_count::Int objective_value::Dict{Int,Float64} dual_objective_value::Dict{Int,Float64} # Primal solution @@ -96,7 +96,7 @@ function MockOptimizer( (::MockOptimizer) -> nothing, false, MOI.OPTIMIZE_NOT_CALLED, - Int64(1), + 1, Dict{Int,Float64}(), Dict{Int,Float64}(), # PrimalStatus diff --git a/src/attributes.jl b/src/attributes.jl index 867b38261b..758dab5981 100644 --- a/src/attributes.jl +++ b/src/attributes.jl @@ -1117,7 +1117,7 @@ results may be alternate certificates, or infeasible points. """ struct ResultCount <: AbstractModelAttribute end -attribute_value_type(::ResultCount) = Int64 +attribute_value_type(::ResultCount) = Int """ ConflictStatusCode From 3198b07a0e600cbd262a50e63ca7a7781557aa1a Mon Sep 17 00:00:00 2001 From: odow Date: Sat, 7 Aug 2021 10:33:30 +1200 Subject: [PATCH 10/12] remove old method --- src/Bridges/Constraint/function_conversion.jl | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/Bridges/Constraint/function_conversion.jl b/src/Bridges/Constraint/function_conversion.jl index a02c2f0a48..184c9bccc7 100644 --- a/src/Bridges/Constraint/function_conversion.jl +++ b/src/Bridges/Constraint/function_conversion.jl @@ -49,18 +49,6 @@ function MOI.set( return end -function MOI.get( - model::MOI.ModelLike, - ::MOI.CanonicalConstraintFunction, - bridge::AbstractFunctionConversionBridge, -) - f = MOI.get(model, MOI.ConstraintFunction(), bridge) - if !MOI.Utilities.is_canonical(f) - return MOI.Utilities.canonical(f) - end - return f -end - """ invariant_under_function_conversion(attr::MOI.AbstractConstraintAttribute) From 3cca75408b612ee4079c75655b201253219b6a57 Mon Sep 17 00:00:00 2001 From: odow Date: Sat, 7 Aug 2021 10:46:53 +1200 Subject: [PATCH 11/12] Use return type annotations instead --- src/Bridges/Constraint/det.jl | 24 +++++++++---------- src/Bridges/Constraint/functionize.jl | 8 +++---- src/Bridges/Constraint/geomean.jl | 12 +++++----- src/Bridges/Constraint/geomean_to_relentr.jl | 8 +++---- src/Bridges/Constraint/indicator_sos.jl | 20 +++++++--------- src/Bridges/Constraint/interval.jl | 8 +++---- .../Constraint/norm_spec_nuc_to_psd.jl | 22 ++++++++--------- src/Bridges/Constraint/norm_to_lp.jl | 6 ++--- src/Bridges/Constraint/quad_to_soc.jl | 4 ++-- src/Bridges/Constraint/relentr_to_exp.jl | 14 +++++------ src/Bridges/Constraint/scalarize.jl | 4 ++-- src/Bridges/Constraint/semi_to_binary.jl | 20 +++++++--------- src/Bridges/Constraint/set_map.jl | 4 ++-- src/Bridges/Constraint/slack.jl | 8 +++---- .../Constraint/soc_to_nonconvex_quad.jl | 8 +++---- src/Bridges/Constraint/square.jl | 8 +++---- src/Bridges/Constraint/vectorize.jl | 4 ++-- src/Bridges/Constraint/zero_one.jl | 12 +++++----- src/Bridges/Objective/functionize.jl | 4 +--- src/Bridges/Objective/slack.jl | 4 ++-- src/Bridges/Variable/free.jl | 8 +++---- src/Bridges/Variable/rsoc_to_psd.jl | 18 +++++++------- src/Bridges/Variable/set_map.jl | 12 +++++----- src/Bridges/Variable/vectorize.jl | 4 ++-- src/Bridges/bridge_optimizer.jl | 8 +++---- src/Utilities/model.jl | 4 ++-- src/Utilities/struct_of_constraints.jl | 6 ++--- src/Utilities/vector_of_constraints.jl | 4 ++-- 28 files changed, 130 insertions(+), 136 deletions(-) diff --git a/src/Bridges/Constraint/det.jl b/src/Bridges/Constraint/det.jl index 17262431f2..6bcf25f187 100644 --- a/src/Bridges/Constraint/det.jl +++ b/src/Bridges/Constraint/det.jl @@ -211,8 +211,8 @@ end # Attributes, Bridge acting as a model -function MOI.get(b::LogDetBridge, ::MOI.NumberOfVariables) - return Int64(length(b.Δ) + length(b.l)) +function MOI.get(b::LogDetBridge, ::MOI.NumberOfVariables)::Int64 + return length(b.Δ) + length(b.l) end MOI.get(b::LogDetBridge, ::MOI.ListOfVariableIndices) = [b.Δ; b.l] @@ -223,22 +223,22 @@ function MOI.get( MOI.VectorAffineFunction{T}, MOI.PositiveSemidefiniteConeTriangle, }, -) where {T} - return Int64(1) +)::Int64 where {T} + return 1 end function MOI.get( b::LogDetBridge{T}, ::MOI.NumberOfConstraints{MOI.VectorAffineFunction{T},MOI.ExponentialCone}, -) where {T} - return Int64(length(b.lcindex)) +)::Int64 where {T} + return length(b.lcindex) end function MOI.get( ::LogDetBridge{T}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}, -) where {T} - return Int64(1) +)::Int64 where {T} + return 1 end function MOI.get( @@ -421,8 +421,8 @@ function MOI.get( MOI.VectorAffineFunction{T}, MOI.PositiveSemidefiniteConeTriangle, }, -) where {T} - return Int64(1) +)::Int64 where {T} + return 1 end function MOI.get( @@ -431,8 +431,8 @@ function MOI.get( MOI.VectorAffineFunction{T}, MOI.GeometricMeanCone, }, -) where {T} - return Int64(1) +)::Int64 where {T} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/functionize.jl b/src/Bridges/Constraint/functionize.jl index 496a43895a..f78e1b42e0 100644 --- a/src/Bridges/Constraint/functionize.jl +++ b/src/Bridges/Constraint/functionize.jl @@ -54,8 +54,8 @@ end function MOI.get( ::ScalarFunctionizeBridge{T,S}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},S}, -) where {T,S} - return Int64(1) +)::Int64 where {T,S} + return 1 end function MOI.get( @@ -158,8 +158,8 @@ end function MOI.get( ::VectorFunctionizeBridge{T,S}, ::MOI.NumberOfConstraints{MOI.VectorAffineFunction{T},S}, -) where {T,S} - return Int64(1) +)::Int64 where {T,S} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/geomean.jl b/src/Bridges/Constraint/geomean.jl index dc25d8ac89..801d689883 100644 --- a/src/Bridges/Constraint/geomean.jl +++ b/src/Bridges/Constraint/geomean.jl @@ -171,22 +171,22 @@ MOI.get(b::GeoMeanBridge, ::MOI.ListOfVariableIndices) = copy(b.xij) function MOI.get( ::GeoMeanBridge{T,F}, ::MOI.NumberOfConstraints{F,MOI.LessThan{T}}, -) where {T,F} - return Int64(1) # t ≤ x_{l1}/sqrt(N) +)::Int64 where {T,F} + return 1 # t ≤ x_{l1}/sqrt(N) end function MOI.get( b::GeoMeanBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.RotatedSecondOrderCone}, -) where {T,F,G} - return Int64(length(b.socrc)) +)::Int64 where {T,F,G} + return length(b.socrc) end function MOI.get( b::GeoMeanBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.Nonnegatives}, -) where {T,F,G} - return Int64(b.d > 2 ? 0 : 1) +)::Int64 where {T,F,G} + return b.d > 2 ? 0 : 1 end function MOI.get( diff --git a/src/Bridges/Constraint/geomean_to_relentr.jl b/src/Bridges/Constraint/geomean_to_relentr.jl index 4d2739a9ec..1c9cb895fe 100644 --- a/src/Bridges/Constraint/geomean_to_relentr.jl +++ b/src/Bridges/Constraint/geomean_to_relentr.jl @@ -95,15 +95,15 @@ end function MOI.get( ::GeoMeantoRelEntrBridge{T,F}, ::MOI.NumberOfConstraints{F,MOI.Nonnegatives}, -) where {T,F} - return Int64(1) +)::Int64 where {T,F} + return 1 end function MOI.get( ::GeoMeantoRelEntrBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.RelativeEntropyCone}, -) where {T,F,G} - return Int64(1) +)::Int64 where {T,F,G} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/indicator_sos.jl b/src/Bridges/Constraint/indicator_sos.jl index a24d01a045..8e921fb660 100644 --- a/src/Bridges/Constraint/indicator_sos.jl +++ b/src/Bridges/Constraint/indicator_sos.jl @@ -154,9 +154,7 @@ end # Attributes, Bridge acting as a model -function MOI.get(::IndicatorSOS1Bridge, ::MOI.NumberOfVariables) - return Int64(1) -end +MOI.get(::IndicatorSOS1Bridge, ::MOI.NumberOfVariables)::Int64 = 1 function MOI.get(b::IndicatorSOS1Bridge, ::MOI.ListOfVariableIndices) return [b.w_variable] @@ -165,29 +163,29 @@ end function MOI.get( ::IndicatorSOS1Bridge{T,BC,Nothing}, ::MOI.NumberOfConstraints{MOI.SingleVariable,BC}, -) where {T,BC} - return Int64(0) +)::Int64 where {T,BC} + return 0 end function MOI.get( ::IndicatorSOS1Bridge{T,BC,CI}, ::MOI.NumberOfConstraints{MOI.SingleVariable,BC}, -) where {T,BC,CI<:MOI.ConstraintIndex{MOI.SingleVariable,BC}} - return Int64(1) +)::Int64 where {T,BC,CI<:MOI.ConstraintIndex{MOI.SingleVariable,BC}} + return 1 end function MOI.get( ::IndicatorSOS1Bridge, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,<:MOI.SOS1}, -) - return Int64(1) +)::Int64 + return 1 end function MOI.get( ::IndicatorSOS1Bridge{T,BC}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},BC}, -) where {T,BC,CI<:MOI.ConstraintIndex{MOI.SingleVariable,BC}} - return Int64(1) +)::Int64 where {T,BC,CI<:MOI.ConstraintIndex{MOI.SingleVariable,BC}} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/interval.jl b/src/Bridges/Constraint/interval.jl index 2bb7043b76..47ea728a5a 100644 --- a/src/Bridges/Constraint/interval.jl +++ b/src/Bridges/Constraint/interval.jl @@ -86,15 +86,15 @@ end function MOI.get( ::SplitIntervalBridge{T,F,S,LS}, ::MOI.NumberOfConstraints{F,LS}, -) where {T,F,S,LS} - return Int64(1) +)::Int64 where {T,F,S,LS} + return 1 end function MOI.get( ::SplitIntervalBridge{T,F,S,LS,US}, ::MOI.NumberOfConstraints{F,US}, -) where {T,F,S,LS,US} - return Int64(1) +)::Int64 where {T,F,S,LS,US} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/norm_spec_nuc_to_psd.jl b/src/Bridges/Constraint/norm_spec_nuc_to_psd.jl index ee4b8afa08..be3a8764fd 100644 --- a/src/Bridges/Constraint/norm_spec_nuc_to_psd.jl +++ b/src/Bridges/Constraint/norm_spec_nuc_to_psd.jl @@ -70,10 +70,10 @@ end # Attributes, Bridge acting as a model function MOI.get( - bridge::NormSpectralBridge{T,F,G}, + ::NormSpectralBridge{T,F,G}, ::MOI.NumberOfConstraints{F,MOI.PositiveSemidefiniteConeTriangle}, -) where {T,F,G} - return Int64(1) +)::Int64 where {T,F,G} + return 1 end function MOI.get( @@ -282,8 +282,8 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -function MOI.get(bridge::NormNuclearBridge, ::MOI.NumberOfVariables) - return Int64(length(bridge.U) + length(bridge.V)) +function MOI.get(bridge::NormNuclearBridge, ::MOI.NumberOfVariables)::Int64 + return length(bridge.U) + length(bridge.V) end function MOI.get(bridge::NormNuclearBridge, ::MOI.ListOfVariableIndices) @@ -291,17 +291,17 @@ function MOI.get(bridge::NormNuclearBridge, ::MOI.ListOfVariableIndices) end function MOI.get( - bridge::NormNuclearBridge{T,F,G,H}, + ::NormNuclearBridge{T,F,G,H}, ::MOI.NumberOfConstraints{F,MOI.GreaterThan{T}}, -) where {T,F,G,H} - return Int64(1) +)::Int64 where {T,F,G,H} + return 1 end function MOI.get( - bridge::NormNuclearBridge{T,F,G,H}, + ::NormNuclearBridge{T,F,G,H}, ::MOI.NumberOfConstraints{G,MOI.PositiveSemidefiniteConeTriangle}, -) where {T,F,G,H} - return Int64(1) +)::Int64 where {T,F,G,H} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/norm_to_lp.jl b/src/Bridges/Constraint/norm_to_lp.jl index ab6feab413..e8bcf9c923 100644 --- a/src/Bridges/Constraint/norm_to_lp.jl +++ b/src/Bridges/Constraint/norm_to_lp.jl @@ -155,10 +155,10 @@ MOI.get(b::NormOneBridge, ::MOI.NumberOfVariables) = Int64(length(b.y)) MOI.get(b::NormOneBridge, ::MOI.ListOfVariableIndices) = copy(b.y) function MOI.get( - b::NormOneBridge{T,F}, + ::NormOneBridge{T,F}, ::MOI.NumberOfConstraints{F,MOI.Nonnegatives}, -) where {T,F} - return Int64(1) +)::Int64 where {T,F} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/quad_to_soc.jl b/src/Bridges/Constraint/quad_to_soc.jl index 278a3fb3f4..1bef004e07 100644 --- a/src/Bridges/Constraint/quad_to_soc.jl +++ b/src/Bridges/Constraint/quad_to_soc.jl @@ -189,8 +189,8 @@ function MOI.get( MOI.VectorAffineFunction{T}, MOI.RotatedSecondOrderCone, }, -) where {T} - return Int64(1) +)::Int64 where {T} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/relentr_to_exp.jl b/src/Bridges/Constraint/relentr_to_exp.jl index acdc52828b..f52e7fb328 100644 --- a/src/Bridges/Constraint/relentr_to_exp.jl +++ b/src/Bridges/Constraint/relentr_to_exp.jl @@ -82,8 +82,8 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -function MOI.get(bridge::RelativeEntropyBridge, ::MOI.NumberOfVariables) - return Int64(length(bridge.y)) +function MOI.get(bridge::RelativeEntropyBridge, ::MOI.NumberOfVariables)::Int64 + return length(bridge.y) end function MOI.get(bridge::RelativeEntropyBridge, ::MOI.ListOfVariableIndices) @@ -91,17 +91,17 @@ function MOI.get(bridge::RelativeEntropyBridge, ::MOI.ListOfVariableIndices) end function MOI.get( - bridge::RelativeEntropyBridge{T,F}, + ::RelativeEntropyBridge{T,F}, ::MOI.NumberOfConstraints{F,MOI.GreaterThan{T}}, -) where {T,F} - return Int64(1) +)::Int64 where {T,F} + return 1 end function MOI.get( bridge::RelativeEntropyBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.ExponentialCone}, -) where {T,F,G} - return Int64(length(bridge.y)) +)::Int64 where {T,F,G} + return length(bridge.y) end function MOI.get( diff --git a/src/Bridges/Constraint/scalarize.jl b/src/Bridges/Constraint/scalarize.jl index 41d98d000d..2bc1f7632e 100644 --- a/src/Bridges/Constraint/scalarize.jl +++ b/src/Bridges/Constraint/scalarize.jl @@ -58,8 +58,8 @@ end function MOI.get( bridge::ScalarizeBridge{T,F,S}, ::MOI.NumberOfConstraints{F,S}, -) where {T,F,S} - return Int64(length(bridge.scalar_constraints)) +)::Int64 where {T,F,S} + return length(bridge.scalar_constraints) end function MOI.get( diff --git a/src/Bridges/Constraint/semi_to_binary.jl b/src/Bridges/Constraint/semi_to_binary.jl index 54a9cd5070..f51ddabe30 100644 --- a/src/Bridges/Constraint/semi_to_binary.jl +++ b/src/Bridges/Constraint/semi_to_binary.jl @@ -214,9 +214,7 @@ end # Attributes, Bridge acting as a model -function MOI.get(::SemiToBinaryBridge, ::MOI.NumberOfVariables) - return Int64(1) -end +MOI.get(::SemiToBinaryBridge, ::MOI.NumberOfVariables)::Int64 = 1 function MOI.get(b::SemiToBinaryBridge, ::MOI.ListOfVariableIndices) return [b.binary_variable] @@ -225,29 +223,29 @@ end function MOI.get( ::SemiToBinaryBridge{T,S}, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.ZeroOne}, -) where {T,S} - return Int64(1) +)::Int64 where {T,S} + return 1 end function MOI.get( ::SemiToBinaryBridge{T,S}, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Integer}, -) where {T,S<:MOI.Semiinteger} - return Int64(1) +)::Int64 where {T,S<:MOI.Semiinteger} + return 1 end function MOI.get( ::SemiToBinaryBridge{T,S}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.GreaterThan{T}}, -) where {T,S} - return Int64(1) +)::Int64 where {T,S} + return 1 end function MOI.get( ::SemiToBinaryBridge{T,S}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}, -) where {T,S} - return Int64(1) +)::Int64 where {T,S} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/set_map.jl b/src/Bridges/Constraint/set_map.jl index 5e9390467f..ce090d4e3a 100644 --- a/src/Bridges/Constraint/set_map.jl +++ b/src/Bridges/Constraint/set_map.jl @@ -64,8 +64,8 @@ end function MOI.get( ::SetMapBridge{T,S2,S1,F}, ::MOI.NumberOfConstraints{F,S2}, -) where {T,S2,S1,F} - return Int64(1) +)::Int64 where {T,S2,S1,F} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/slack.jl b/src/Bridges/Constraint/slack.jl index 0b65461337..e2078e49de 100644 --- a/src/Bridges/Constraint/slack.jl +++ b/src/Bridges/Constraint/slack.jl @@ -15,15 +15,15 @@ end function MOI.get( ::AbstractSlackBridge{T,VF,ZS,F}, ::MOI.NumberOfConstraints{F,ZS}, -) where {T,VF,ZS,F} - return Int64(1) +)::Int64 where {T,VF,ZS,F} + return 1 end function MOI.get( ::AbstractSlackBridge{T,VF,ZS,F,S}, ::MOI.NumberOfConstraints{VF,S}, -) where {T,VF,ZS,F,S} - return Int64(1) +)::Int64 where {T,VF,ZS,F,S} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/soc_to_nonconvex_quad.jl b/src/Bridges/Constraint/soc_to_nonconvex_quad.jl index 9f73fc493f..be3c0a9d53 100644 --- a/src/Bridges/Constraint/soc_to_nonconvex_quad.jl +++ b/src/Bridges/Constraint/soc_to_nonconvex_quad.jl @@ -172,8 +172,8 @@ end function MOI.get( ::AbstractSOCtoNonConvexQuadBridge{T}, ::MOI.NumberOfConstraints{MOI.ScalarQuadraticFunction{T},MOI.LessThan{T}}, -) where {T} - return Int64(1) +)::Int64 where {T} + return 1 end function MOI.get( @@ -189,8 +189,8 @@ end function MOI.get( bridge::AbstractSOCtoNonConvexQuadBridge{T}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.GreaterThan{T}}, -) where {T} - return Int64(length(bridge.var_pos)) +)::Int64 where {T} + return length(bridge.var_pos) end function MOI.get( diff --git a/src/Bridges/Constraint/square.jl b/src/Bridges/Constraint/square.jl index c0b32e3c15..2f80b7ea11 100644 --- a/src/Bridges/Constraint/square.jl +++ b/src/Bridges/Constraint/square.jl @@ -167,15 +167,15 @@ end function MOI.get( ::SquareBridge{T,F,G,TT}, ::MOI.NumberOfConstraints{F,TT}, -) where {T,F,G,TT} - return Int64(1) +)::Int64 where {T,F,G,TT} + return 1 end function MOI.get( bridge::SquareBridge{T,F,G}, ::MOI.NumberOfConstraints{G,MOI.EqualTo{T}}, -) where {T,F,G} - return Int64(length(bridge.sym)) +)::Int64 where {T,F,G} + return length(bridge.sym) end function MOI.get( diff --git a/src/Bridges/Constraint/vectorize.jl b/src/Bridges/Constraint/vectorize.jl index de5208296c..0ec7f28449 100644 --- a/src/Bridges/Constraint/vectorize.jl +++ b/src/Bridges/Constraint/vectorize.jl @@ -74,8 +74,8 @@ end function MOI.get( ::VectorizeBridge{T,F,S}, ::MOI.NumberOfConstraints{F,S}, -) where {T,F,S} - return Int64(1) +)::Int64 where {T,F,S} + return 1 end function MOI.get( diff --git a/src/Bridges/Constraint/zero_one.jl b/src/Bridges/Constraint/zero_one.jl index 8d4e22ab99..230dc69dcb 100644 --- a/src/Bridges/Constraint/zero_one.jl +++ b/src/Bridges/Constraint/zero_one.jl @@ -101,17 +101,17 @@ end # Attributes, Bridge acting as a model function MOI.get( - bridge::ZeroOneBridge{T}, + ::ZeroOneBridge{T}, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Interval{T}}, -) where {T} - return Int64(1) +)::Int64 where {T} + return 1 end function MOI.get( - bridge::ZeroOneBridge, + ::ZeroOneBridge, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Integer}, -) - return Int64(1) +)::Int64 + return 1 end function MOI.get( diff --git a/src/Bridges/Objective/functionize.jl b/src/Bridges/Objective/functionize.jl index 090e6ff703..2d5e705861 100644 --- a/src/Bridges/Objective/functionize.jl +++ b/src/Bridges/Objective/functionize.jl @@ -38,9 +38,7 @@ function MOIB.set_objective_function_type( end # Attributes, Bridge acting as a model -function MOI.get(::FunctionizeBridge, ::MOI.NumberOfVariables) - return Int64(0) -end +MOI.get(::FunctionizeBridge, ::MOI.NumberOfVariables)::Int64 = 0 function MOI.get(::FunctionizeBridge, ::MOI.ListOfVariableIndices) return MOI.VariableIndex[] diff --git a/src/Bridges/Objective/slack.jl b/src/Bridges/Objective/slack.jl index eeffca4133..ae025a1ba3 100644 --- a/src/Bridges/Objective/slack.jl +++ b/src/Bridges/Objective/slack.jl @@ -87,8 +87,8 @@ end function MOI.get( bridge::SlackBridge{T,F}, ::MOI.NumberOfConstraints{F,S}, -) where {T,F,S<:Union{MOI.GreaterThan{T},MOI.LessThan{T}}} - return Int64(bridge.constraint isa MOI.ConstraintIndex{F,S} ? 1 : 0) +)::Int64 where {T,F,S<:Union{MOI.GreaterThan{T},MOI.LessThan{T}}} + return bridge.constraint isa MOI.ConstraintIndex{F,S} ? 1 : 0 end function MOI.get( diff --git a/src/Bridges/Variable/free.jl b/src/Bridges/Variable/free.jl index 42296626b0..33569a016d 100644 --- a/src/Bridges/Variable/free.jl +++ b/src/Bridges/Variable/free.jl @@ -34,8 +34,8 @@ function MOIB.added_constraint_types(::Type{FreeBridge{T}}) where {T} end # Attributes, Bridge acting as a model -function MOI.get(bridge::FreeBridge, ::MOI.NumberOfVariables) - return Int64(length(bridge.variables)) +function MOI.get(bridge::FreeBridge, ::MOI.NumberOfVariables)::Int64 + return length(bridge.variables) end function MOI.get(bridge::FreeBridge, ::MOI.ListOfVariableIndices) @@ -45,8 +45,8 @@ end function MOI.get( ::FreeBridge, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.Nonnegatives}, -) - return Int64(1) +)::Int64 + return 1 end function MOI.get( diff --git a/src/Bridges/Variable/rsoc_to_psd.jl b/src/Bridges/Variable/rsoc_to_psd.jl index f9add44499..cc1646cab8 100644 --- a/src/Bridges/Variable/rsoc_to_psd.jl +++ b/src/Bridges/Variable/rsoc_to_psd.jl @@ -89,8 +89,8 @@ function MOIB.added_constraint_types(::Type{RSOCtoPSDBridge{T}}) where {T} end # Attributes, Bridge acting as a model -function MOI.get(bridge::RSOCtoPSDBridge, ::MOI.NumberOfVariables) - return Int64(length(bridge.variables)) +function MOI.get(bridge::RSOCtoPSDBridge, ::MOI.NumberOfVariables)::Int64 + return length(bridge.variables) end function MOI.get(bridge::RSOCtoPSDBridge, ::MOI.ListOfVariableIndices) @@ -100,11 +100,11 @@ end function MOI.get( bridge::RSOCtoPSDBridge, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,S}, -) where {S<:Union{MOI.PositiveSemidefiniteConeTriangle,MOI.Nonnegatives}} +)::Int64 where {S<:Union{MOI.PositiveSemidefiniteConeTriangle,MOI.Nonnegatives}} if bridge.psd isa MOI.ConstraintIndex{MOI.VectorOfVariables,S} - return Int64(1) + return 1 else - return Int64(0) + return 0 end end @@ -122,8 +122,8 @@ end function MOI.get( bridge::RSOCtoPSDBridge{T}, ::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{T}}, -) where {T} - return Int64(length(bridge.off_diag)) +)::Int64 where {T} + return length(bridge.off_diag) end function MOI.get( @@ -136,8 +136,8 @@ end function MOI.get( bridge::RSOCtoPSDBridge{T}, ::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.EqualTo{T}}, -) where {T} - return Int64(length(bridge.diag)) +)::Int64 where {T} + return length(bridge.diag) end function MOI.get( diff --git a/src/Bridges/Variable/set_map.jl b/src/Bridges/Variable/set_map.jl index 8e425f2079..38896a632d 100644 --- a/src/Bridges/Variable/set_map.jl +++ b/src/Bridges/Variable/set_map.jl @@ -59,8 +59,8 @@ function MOIB.added_constraint_types(::Type{<:SetMapBridge}) end # Attributes, Bridge acting as a model -function MOI.get(bridge::SetMapBridge, ::MOI.NumberOfVariables) - return Int64(length(bridge.variables)) +function MOI.get(bridge::SetMapBridge, ::MOI.NumberOfVariables)::Int64 + return length(bridge.variables) end function MOI.get(bridge::SetMapBridge, ::MOI.ListOfVariableIndices) @@ -70,15 +70,15 @@ end function MOI.get( ::SetMapBridge{T,S1}, ::MOI.NumberOfConstraints{MOI.SingleVariable,S1}, -) where {T,S1<:MOI.AbstractScalarSet} - return Int64(1) +)::Int64 where {T,S1<:MOI.AbstractScalarSet} + return 1 end function MOI.get( ::SetMapBridge{T,S1}, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,S1}, -) where {T,S1<:MOI.AbstractVectorSet} - return Int64(1) +)::Int64 where {T,S1<:MOI.AbstractVectorSet} + return 1 end function MOI.get( diff --git a/src/Bridges/Variable/vectorize.jl b/src/Bridges/Variable/vectorize.jl index 19dee95f89..f120d42793 100644 --- a/src/Bridges/Variable/vectorize.jl +++ b/src/Bridges/Variable/vectorize.jl @@ -57,8 +57,8 @@ end function MOI.get( ::VectorizeBridge{T,S}, ::MOI.NumberOfConstraints{MOI.VectorOfVariables,S}, -) where {T,S} - return Int64(1) +)::Int64 where {T,S} + return 1 end function MOI.get( diff --git a/src/Bridges/bridge_optimizer.jl b/src/Bridges/bridge_optimizer.jl index c1e13bfb42..7da990a94b 100644 --- a/src/Bridges/bridge_optimizer.jl +++ b/src/Bridges/bridge_optimizer.jl @@ -726,7 +726,7 @@ function MOI.get( return list end -function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.NumberOfVariables) +function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.NumberOfVariables)::Int64 s = MOI.get(b.model, attr) + Variable.number_of_variables(Variable.bridges(b)) @@ -739,7 +739,7 @@ function MOI.get(b::AbstractBridgeOptimizer, attr::MOI.NumberOfVariables) for bridge in values(Objective.bridges(b)) s -= MOI.get(bridge, attr) end - return Int64(s) + return s end # Number of all constraints, including those bridged @@ -765,7 +765,7 @@ end function MOI.get( b::AbstractBridgeOptimizer, attr::MOI.NumberOfConstraints{F,S}, -) where {F,S} +)::Int64 where {F,S} s = get_all_including_bridged(b, attr) # The constraints counted in `s` may have been added by bridges for bridge in values(Variable.bridges(b)) @@ -777,7 +777,7 @@ function MOI.get( for bridge in values(Objective.bridges(b)) s -= MOI.get(bridge, attr) end - return Int64(s) + return s end function MOI.get( diff --git a/src/Utilities/model.jl b/src/Utilities/model.jl index ead3b39728..56a136cc73 100644 --- a/src/Utilities/model.jl +++ b/src/Utilities/model.jl @@ -485,8 +485,8 @@ end function MOI.get( model::AbstractModel, noc::MOI.NumberOfConstraints{F,S}, -) where {F,S} - return Int64(MOI.get(model.constraints, noc)) +)::Int64 where {F,S} + return MOI.get(model.constraints, noc) end function MOI.get( diff --git a/src/Utilities/struct_of_constraints.jl b/src/Utilities/struct_of_constraints.jl index c416785b8c..e70559bdea 100644 --- a/src/Utilities/struct_of_constraints.jl +++ b/src/Utilities/struct_of_constraints.jl @@ -117,11 +117,11 @@ end function MOI.get( model::StructOfConstraints, attr::MOI.NumberOfConstraints{F,S}, -) where {F,S} +)::Int64 where {F,S} if !MOI.supports_constraint(model, F, S) - return Int64(0) + return 0 end - return Int64(MOI.get(constraints(model, F, S), attr)) + return MOI.get(constraints(model, F, S), attr) end function MOI.get( diff --git a/src/Utilities/vector_of_constraints.jl b/src/Utilities/vector_of_constraints.jl index 0dc7b4b1a5..293c76ef16 100644 --- a/src/Utilities/vector_of_constraints.jl +++ b/src/Utilities/vector_of_constraints.jl @@ -124,8 +124,8 @@ end function MOI.get( v::VectorOfConstraints{F,S}, ::MOI.NumberOfConstraints{F,S}, -) where {F,S} - return Int64(length(v.constraints)) +)::Int64 where {F,S} + return length(v.constraints) end function MOI.get( From f60fc41dcbef37c471eaa111e2bfca1c9c35dce9 Mon Sep 17 00:00:00 2001 From: odow Date: Sat, 7 Aug 2021 10:49:07 +1200 Subject: [PATCH 12/12] Fix stragglers --- src/Bridges/Constraint/bridge.jl | 2 +- src/Bridges/Constraint/det.jl | 2 +- src/Bridges/Constraint/geomean.jl | 2 +- src/Bridges/Constraint/geomean_to_relentr.jl | 2 +- src/Bridges/Constraint/norm_to_lp.jl | 2 +- src/Bridges/Constraint/slack.jl | 4 ++-- src/Bridges/Objective/slack.jl | 2 +- src/Bridges/Variable/vectorize.jl | 2 +- src/Bridges/Variable/zeros.jl | 2 +- src/Bridges/bridge.jl | 2 +- src/DeprecatedTest/modellike.jl | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Bridges/Constraint/bridge.jl b/src/Bridges/Constraint/bridge.jl index 27ddcf1933..3e17de7b69 100644 --- a/src/Bridges/Constraint/bridge.jl +++ b/src/Bridges/Constraint/bridge.jl @@ -27,7 +27,7 @@ function bridge_constraint end The number of variables created by the bridge `b` in the model. """ -MOI.get(::AbstractBridge, ::MOI.NumberOfVariables) = Int64(0) +MOI.get(::AbstractBridge, ::MOI.NumberOfVariables)::Int64 = 0 """ MOI.get(b::AbstractBridge, ::MOI.ListOfVariableIndices) diff --git a/src/Bridges/Constraint/det.jl b/src/Bridges/Constraint/det.jl index 6bcf25f187..b0a5521391 100644 --- a/src/Bridges/Constraint/det.jl +++ b/src/Bridges/Constraint/det.jl @@ -411,7 +411,7 @@ end # Attributes, Bridge acting as a model -MOI.get(b::RootDetBridge, ::MOI.NumberOfVariables) = Int64(length(b.Δ)) +MOI.get(b::RootDetBridge, ::MOI.NumberOfVariables)::Int64 = length(b.Δ) MOI.get(b::RootDetBridge, ::MOI.ListOfVariableIndices) = copy(b.Δ) diff --git a/src/Bridges/Constraint/geomean.jl b/src/Bridges/Constraint/geomean.jl index 801d689883..d8229baf5c 100644 --- a/src/Bridges/Constraint/geomean.jl +++ b/src/Bridges/Constraint/geomean.jl @@ -164,7 +164,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(b::GeoMeanBridge, ::MOI.NumberOfVariables) = Int64(length(b.xij)) +MOI.get(b::GeoMeanBridge, ::MOI.NumberOfVariables)::Int64 = length(b.xij) MOI.get(b::GeoMeanBridge, ::MOI.ListOfVariableIndices) = copy(b.xij) diff --git a/src/Bridges/Constraint/geomean_to_relentr.jl b/src/Bridges/Constraint/geomean_to_relentr.jl index 1c9cb895fe..e25696ca2b 100644 --- a/src/Bridges/Constraint/geomean_to_relentr.jl +++ b/src/Bridges/Constraint/geomean_to_relentr.jl @@ -86,7 +86,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(::GeoMeantoRelEntrBridge, ::MOI.NumberOfVariables) = Int64(1) +MOI.get(::GeoMeantoRelEntrBridge, ::MOI.NumberOfVariables)::Int64 = 1 function MOI.get(bridge::GeoMeantoRelEntrBridge, ::MOI.ListOfVariableIndices) return [bridge.y] diff --git a/src/Bridges/Constraint/norm_to_lp.jl b/src/Bridges/Constraint/norm_to_lp.jl index e8bcf9c923..8f856ce3b6 100644 --- a/src/Bridges/Constraint/norm_to_lp.jl +++ b/src/Bridges/Constraint/norm_to_lp.jl @@ -150,7 +150,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(b::NormOneBridge, ::MOI.NumberOfVariables) = Int64(length(b.y)) +MOI.get(b::NormOneBridge, ::MOI.NumberOfVariables)::Int64 = length(b.y) MOI.get(b::NormOneBridge, ::MOI.ListOfVariableIndices) = copy(b.y) diff --git a/src/Bridges/Constraint/slack.jl b/src/Bridges/Constraint/slack.jl index e2078e49de..730625601c 100644 --- a/src/Bridges/Constraint/slack.jl +++ b/src/Bridges/Constraint/slack.jl @@ -217,7 +217,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(b::ScalarSlackBridge, ::MOI.NumberOfVariables) = Int64(1) +MOI.get(b::ScalarSlackBridge, ::MOI.NumberOfVariables)::Int64 = 1 MOI.get(b::ScalarSlackBridge, ::MOI.ListOfVariableIndices) = [b.slack] # Attributes, Bridge acting as a constraint @@ -332,7 +332,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(b::VectorSlackBridge, ::MOI.NumberOfVariables) = Int64(length(b.slack)) +MOI.get(b::VectorSlackBridge, ::MOI.NumberOfVariables)::Int64 = length(b.slack) MOI.get(b::VectorSlackBridge, ::MOI.ListOfVariableIndices) = copy(b.slack) diff --git a/src/Bridges/Objective/slack.jl b/src/Bridges/Objective/slack.jl index ae025a1ba3..a47af4b502 100644 --- a/src/Bridges/Objective/slack.jl +++ b/src/Bridges/Objective/slack.jl @@ -78,7 +78,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(::SlackBridge, ::MOI.NumberOfVariables) = Int64(1) +MOI.get(::SlackBridge, ::MOI.NumberOfVariables)::Int64 = 1 function MOI.get(bridge::SlackBridge, ::MOI.ListOfVariableIndices) return [bridge.slack] diff --git a/src/Bridges/Variable/vectorize.jl b/src/Bridges/Variable/vectorize.jl index f120d42793..5fad63075f 100644 --- a/src/Bridges/Variable/vectorize.jl +++ b/src/Bridges/Variable/vectorize.jl @@ -48,7 +48,7 @@ function concrete_bridge_type( end # Attributes, Bridge acting as a model -MOI.get(::VectorizeBridge, ::MOI.NumberOfVariables) = Int64(1) +MOI.get(::VectorizeBridge, ::MOI.NumberOfVariables)::Int64 = 1 function MOI.get(bridge::VectorizeBridge, ::MOI.ListOfVariableIndices) return [bridge.variable] diff --git a/src/Bridges/Variable/zeros.jl b/src/Bridges/Variable/zeros.jl index de6bc1d4aa..63d1b6aff3 100644 --- a/src/Bridges/Variable/zeros.jl +++ b/src/Bridges/Variable/zeros.jl @@ -40,7 +40,7 @@ function MOIB.added_constraint_types(::Type{<:ZerosBridge}) end # Attributes, Bridge acting as a model -MOI.get(::ZerosBridge, ::MOI.NumberOfVariables) = Int64(0) +MOI.get(::ZerosBridge, ::MOI.NumberOfVariables)::Int64 = 0 function MOI.get(bridge::ZerosBridge, ::MOI.ListOfVariableIndices) return MOI.VariableIndex[] diff --git a/src/Bridges/bridge.jl b/src/Bridges/bridge.jl index b0486f4501..8b84e530a3 100644 --- a/src/Bridges/bridge.jl +++ b/src/Bridges/bridge.jl @@ -34,7 +34,7 @@ end The number of constraints of the type `F`-in-`S` created by the bridge `b` in the model. """ -MOI.get(::AbstractBridge, ::MOI.NumberOfConstraints) = Int64(0) +MOI.get(::AbstractBridge, ::MOI.NumberOfConstraints)::Int64 = 0 """ MOI.get(b::AbstractBridge, ::MOI.ListOfConstraintIndices{F, S}) where {F, S} diff --git a/src/DeprecatedTest/modellike.jl b/src/DeprecatedTest/modellike.jl index a03f020afc..dd5d50337b 100644 --- a/src/DeprecatedTest/modellike.jl +++ b/src/DeprecatedTest/modellike.jl @@ -401,7 +401,7 @@ abstract type BadModel <: MOI.ModelLike end function MOI.get(::BadModel, ::MOI.ListOfModelAttributesSet) return MOI.AbstractModelAttribute[] end -MOI.get(::BadModel, ::MOI.NumberOfVariables) = Int64(1) +MOI.get(::BadModel, ::MOI.NumberOfVariables)::Int64 = 1 MOI.get(::BadModel, ::MOI.ListOfVariableIndices) = [MOI.VariableIndex(1)] function MOI.get(::BadModel, ::MOI.ListOfVariableAttributesSet) return MOI.AbstractVariableAttribute[]