Skip to content

Commit

Permalink
Add MOI.attribute_value_type for attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed May 11, 2021
1 parent 550f585 commit 94050cb
Show file tree
Hide file tree
Showing 40 changed files with 344 additions and 101 deletions.
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/bridge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,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
17 changes: 10 additions & 7 deletions src/Bridges/Constraint/det.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,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]
function MOI.get(
b::LogDetBridge{T},
Expand All @@ -187,19 +190,19 @@ 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(
b::LogDetBridge{T},
::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}},
) where {T}
return 1
return Int64(1)
end
function MOI.get(
b::LogDetBridge{T},
Expand Down Expand Up @@ -357,7 +360,7 @@ 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) = b.Δ
function MOI.get(
b::RootDetBridge{T},
Expand All @@ -366,7 +369,7 @@ function MOI.get(
MOI.PositiveSemidefiniteConeTriangle,
},
) where {T}
return 1
return Int64(1)
end
function MOI.get(
b::RootDetBridge{T},
Expand All @@ -375,7 +378,7 @@ function MOI.get(
MOI.GeometricMeanCone,
},
) where {T}
return 1
return Int64(1)
end
function MOI.get(
b::RootDetBridge{T},
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 @@ -51,7 +51,7 @@ function MOI.get(
b::ScalarFunctionizeBridge{T,S},
::MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},S},
) where {T,S}
return 1
return Int64(1)
end
function MOI.get(
b::ScalarFunctionizeBridge{T,S},
Expand Down Expand Up @@ -141,7 +141,7 @@ function MOI.get(
b::VectorFunctionizeBridge{T,S},
::MOI.NumberOfConstraints{MOI.VectorAffineFunction{T},S},
) where {T,S}
return 1
return Int64(1)
end
function MOI.get(
b::VectorFunctionizeBridge{T,S},
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 @@ -158,25 +158,25 @@ 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) = b.xij
function MOI.get(
b::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(
b::GeoMeanBridge{T,F},
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 @@ -77,21 +77,21 @@ function concrete_bridge_type(
end

# Attributes, Bridge acting as a model
MOI.get(bridge::GeoMeantoRelEntrBridge, ::MOI.NumberOfVariables) = 1
MOI.get(bridge::GeoMeantoRelEntrBridge, ::MOI.NumberOfVariables) = Int64(1)
function MOI.get(bridge::GeoMeantoRelEntrBridge, ::MOI.ListOfVariableIndices)
return [bridge.y]
end
function MOI.get(
bridge::GeoMeantoRelEntrBridge{T,F},
::MOI.NumberOfConstraints{F,MOI.Nonnegatives},
) where {T,F}
return 1
return Int64(1)
end
function MOI.get(
bridge::GeoMeantoRelEntrBridge{T,F,G},
::MOI.NumberOfConstraints{G,MOI.RelativeEntropyCone},
) where {T,F,G}
return 1
return Int64(1)
end
function MOI.get(
bridge::GeoMeantoRelEntrBridge{T,F},
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 @@ -81,13 +81,13 @@ 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(
bridge::SplitIntervalBridge{T,F,S,LS},
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 @@ -69,7 +69,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(
bridge::NormSpectralBridge{T,F,G},
Expand Down Expand Up @@ -267,7 +267,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)
return vcat(bridge.U, bridge.V)
Expand All @@ -276,13 +276,13 @@ 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(
bridge::NormNuclearBridge{T,F,G,H},
Expand Down
4 changes: 2 additions & 2 deletions src/Bridges/Constraint/norm_to_lp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ 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) = 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(
b::NormOneBridge{T,F},
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 @@ -183,7 +183,7 @@ function MOI.get(
MOI.RotatedSecondOrderCone,
},
) where {T}
return 1
return Int64(1)
end
function MOI.get(
bridge::QuadtoSOCBridge{T},
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 @@ -78,20 +78,20 @@ end

# Attributes, Bridge acting as a model
function MOI.get(bridge::RelativeEntropyBridge, ::MOI.NumberOfVariables)
return length(bridge.y)
return Int64(length(bridge.y))
end
MOI.get(bridge::RelativeEntropyBridge, ::MOI.ListOfVariableIndices) = bridge.y
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(
bridge::RelativeEntropyBridge{T,F},
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 @@ -55,7 +55,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(
bridge::ScalarizeBridge{T,F,S},
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 @@ -39,7 +39,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(
bridge::SetMapBridge{T,S2,S1,F},
Expand Down
8 changes: 4 additions & 4 deletions src/Bridges/Constraint/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ 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(
bridge::AbstractSlackBridge{T,VF,ZS,F},
Expand Down Expand Up @@ -200,7 +200,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
Expand Down Expand Up @@ -289,7 +289,7 @@ 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) = b.slack

# Attributes, Bridge acting as a constraint
Expand Down
Loading

0 comments on commit 94050cb

Please sign in to comment.