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 31, 2021
1 parent 4cef58d commit 952b7a4
Show file tree
Hide file tree
Showing 40 changed files with 348 additions and 105 deletions.
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
9 changes: 5 additions & 4 deletions src/Bridges/Constraint/slack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 952b7a4

Please sign in to comment.