Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MOI.attribute_value_type #1283

Merged
merged 16 commits into from
Aug 8, 2021
5 changes: 5 additions & 0 deletions docs/src/manual/implementing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions docs/src/reference/models.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ get
get!
set
supports
attribute_value_type
```

## Model interface
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down
18 changes: 11 additions & 7 deletions src/Bridges/Constraint/det.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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(
Expand Down Expand Up @@ -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.Δ)

Expand All @@ -418,7 +422,7 @@ function MOI.get(
MOI.PositiveSemidefiniteConeTriangle,
},
) where {T}
return 1
return Int64(1)
end

function MOI.get(
Expand All @@ -428,7 +432,7 @@ function MOI.get(
MOI.GeometricMeanCone,
},
) where {T}
return 1
return Int64(1)
end

function MOI.get(
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/functionize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/Bridges/Constraint/geomean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,29 @@ 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)

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(
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/Constraint/geomean_to_relentr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/Bridges/Constraint/indicator_sos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions src/Bridges/Constraint/norm_spec_nuc_to_psd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions src/Bridges/Constraint/norm_to_lp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/quad_to_soc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function MOI.get(
MOI.RotatedSecondOrderCone,
},
) where {T}
return 1
return Int64(1)
end

function MOI.get(
Expand Down
6 changes: 3 additions & 3 deletions src/Bridges/Constraint/relentr_to_exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/scalarize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/Bridges/Constraint/semi_to_binary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/Bridges/Constraint/set_map.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading