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
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
5 changes: 5 additions & 0 deletions docs/src/tutorials/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
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)::Int64
return length(b.Δ) + length(b.l)
end

MOI.get(b::LogDetBridge, ::MOI.ListOfVariableIndices) = [b.Δ; b.l]

Expand All @@ -220,21 +223,21 @@ function MOI.get(
MOI.VectorAffineFunction{T},
MOI.PositiveSemidefiniteConeTriangle,
},
) where {T}
)::Int64 where {T}
return 1
end

function MOI.get(
b::LogDetBridge{T},
::MOI.NumberOfConstraints{MOI.VectorAffineFunction{T},MOI.ExponentialCone},
) where {T}
)::Int64 where {T}
return length(b.lcindex)
end

function MOI.get(
::LogDetBridge{T},
::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}},
) where {T}
)::Int64 where {T}
return 1
end

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 @@ -417,7 +421,7 @@ function MOI.get(
MOI.VectorAffineFunction{T},
MOI.PositiveSemidefiniteConeTriangle,
},
) where {T}
)::Int64 where {T}
return 1
end

Expand All @@ -427,7 +431,7 @@ function MOI.get(
MOI.VectorAffineFunction{T},
MOI.GeometricMeanCone,
},
) where {T}
)::Int64 where {T}
return 1
end

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 @@ -54,7 +54,7 @@ end
function MOI.get(
::ScalarFunctionizeBridge{T,S},
::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},S},
) where {T,S}
)::Int64 where {T,S}
return 1
end

Expand Down Expand Up @@ -158,7 +158,7 @@ end
function MOI.get(
::VectorFunctionizeBridge{T,S},
::MOI.NumberOfConstraints{MOI.VectorAffineFunction{T},S},
) where {T,S}
)::Int64 where {T,S}
return 1
end

Expand Down
10 changes: 5 additions & 5 deletions src/Bridges/Constraint/geomean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,29 +164,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}
)::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}
)::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 (b.d > 2 ? 0 : 1)
)::Int64 where {T,F,G}
return 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 @@ -95,14 +95,14 @@ end
function MOI.get(
::GeoMeantoRelEntrBridge{T,F},
::MOI.NumberOfConstraints{F,MOI.Nonnegatives},
) where {T,F}
)::Int64 where {T,F}
return 1
end

function MOI.get(
::GeoMeantoRelEntrBridge{T,F,G},
::MOI.NumberOfConstraints{G,MOI.RelativeEntropyCone},
) where {T,F,G}
)::Int64 where {T,F,G}
return 1
end

Expand Down
12 changes: 5 additions & 7 deletions src/Bridges/Constraint/indicator_sos.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ end

# Attributes, Bridge acting as a model

function MOI.get(::IndicatorSOS1Bridge, ::MOI.NumberOfVariables)
return 1
end
MOI.get(::IndicatorSOS1Bridge, ::MOI.NumberOfVariables)::Int64 = 1

function MOI.get(b::IndicatorSOS1Bridge, ::MOI.ListOfVariableIndices)
return [b.w_variable]
Expand All @@ -165,28 +163,28 @@ end
function MOI.get(
::IndicatorSOS1Bridge{T,BC,Nothing},
::MOI.NumberOfConstraints{MOI.SingleVariable,BC},
) where {T,BC}
)::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}}
)::Int64 where {T,BC,CI<:MOI.ConstraintIndex{MOI.SingleVariable,BC}}
return 1
end

function MOI.get(
::IndicatorSOS1Bridge,
::MOI.NumberOfConstraints{MOI.VectorOfVariables,<:MOI.SOS1},
)
)::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}}
)::Int64 where {T,BC,CI<:MOI.ConstraintIndex{MOI.SingleVariable,BC}}
return 1
end

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 @@ -86,14 +86,14 @@ end
function MOI.get(
::SplitIntervalBridge{T,F,S,LS},
::MOI.NumberOfConstraints{F,LS},
) where {T,F,S,LS}
)::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}
)::Int64 where {T,F,S,LS,US}
return 1
end

Expand Down
14 changes: 7 additions & 7 deletions src/Bridges/Constraint/norm_spec_nuc_to_psd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ 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}
)::Int64 where {T,F,G}
return 1
end

Expand Down Expand Up @@ -282,7 +282,7 @@ function concrete_bridge_type(
end

# Attributes, Bridge acting as a model
function MOI.get(bridge::NormNuclearBridge, ::MOI.NumberOfVariables)
function MOI.get(bridge::NormNuclearBridge, ::MOI.NumberOfVariables)::Int64
return length(bridge.U) + length(bridge.V)
end

Expand All @@ -291,16 +291,16 @@ 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}
)::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}
)::Int64 where {T,F,G,H}
return 1
end

Expand Down
8 changes: 5 additions & 3 deletions src/Bridges/Constraint/norm_to_lp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ 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},
::NormOneBridge{T,F},
::MOI.NumberOfConstraints{F,MOI.Nonnegatives},
) where {T,F}
)::Int64 where {T,F}
return 1
end

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 @@ -189,7 +189,7 @@ function MOI.get(
MOI.VectorAffineFunction{T},
MOI.RotatedSecondOrderCone,
},
) where {T}
)::Int64 where {T}
return 1
end

Expand Down
8 changes: 4 additions & 4 deletions src/Bridges/Constraint/relentr_to_exp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function concrete_bridge_type(
end

# Attributes, Bridge acting as a model
function MOI.get(bridge::RelativeEntropyBridge, ::MOI.NumberOfVariables)
function MOI.get(bridge::RelativeEntropyBridge, ::MOI.NumberOfVariables)::Int64
return length(bridge.y)
end

Expand All @@ -91,16 +91,16 @@ 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}
)::Int64 where {T,F}
return 1
end

function MOI.get(
bridge::RelativeEntropyBridge{T,F,G},
::MOI.NumberOfConstraints{G,MOI.ExponentialCone},
) where {T,F,G}
)::Int64 where {T,F,G}
return length(bridge.y)
end

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 @@ -58,7 +58,7 @@ end
function MOI.get(
bridge::ScalarizeBridge{T,F,S},
::MOI.NumberOfConstraints{F,S},
) where {T,F,S}
)::Int64 where {T,F,S}
return length(bridge.scalar_constraints)
end

Expand Down
12 changes: 5 additions & 7 deletions src/Bridges/Constraint/semi_to_binary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ end

# Attributes, Bridge acting as a model

function MOI.get(::SemiToBinaryBridge, ::MOI.NumberOfVariables)
return 1
end
MOI.get(::SemiToBinaryBridge, ::MOI.NumberOfVariables)::Int64 = 1

function MOI.get(b::SemiToBinaryBridge, ::MOI.ListOfVariableIndices)
return [b.binary_variable]
Expand All @@ -225,28 +223,28 @@ end
function MOI.get(
::SemiToBinaryBridge{T,S},
::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.ZeroOne},
) where {T,S}
)::Int64 where {T,S}
return 1
end

function MOI.get(
::SemiToBinaryBridge{T,S},
::MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Integer},
) where {T,S<:MOI.Semiinteger}
)::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}
)::Int64 where {T,S}
return 1
end

function MOI.get(
::SemiToBinaryBridge{T,S},
::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}},
) where {T,S}
)::Int64 where {T,S}
return 1
end

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 @@ -64,7 +64,7 @@ end
function MOI.get(
::SetMapBridge{T,S2,S1,F},
::MOI.NumberOfConstraints{F,S2},
) where {T,S2,S1,F}
)::Int64 where {T,S2,S1,F}
return 1
end

Expand Down
Loading