Skip to content

Commit 2c38cb0

Browse files
committed
SetWithDotProducts
1 parent 9bb6619 commit 2c38cb0

File tree

7 files changed

+56
-64
lines changed

7 files changed

+56
-64
lines changed

docs/src/background/duality.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ and similarly, the dual is:
114114
The scalar product is different from the canonical one for the sets
115115
[`PositiveSemidefiniteConeTriangle`](@ref), [`LogDetConeTriangle`](@ref),
116116
[`RootDetConeTriangle`](@ref),
117-
[`FrobeniusProductPostiviveSemidefiniteConeTriangle`](@ref) and
118-
[`LinearMatrixInequalityConeTriangle`](@ref).
117+
[`SetWithDotProducts`](@ref) and
118+
[`LinearCombinationInSet`](@ref).
119119

120120
If the set ``C_i`` of the section [Duality](@ref) is one of these three cones,
121121
then the rows of the matrix ``A_i`` corresponding to off-diagonal entries are

docs/src/manual/standard_form.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ The vector-valued set types implemented in MathOptInterface.jl are:
8282
| [`RelativeEntropyCone(d)`](@ref MathOptInterface.RelativeEntropyCone) | ``\{ (u, v, w) \in \mathbb{R}^{d} : u \ge \sum_i w_i \log (\frac{w_i}{v_i}), v_i \ge 0, w_i \ge 0 \}`` |
8383
| [`HyperRectangle(l, u)`](@ref MathOptInterface.HyperRectangle) | ``\{x \in \bar{\mathbb{R}}^d: x_i \in [l_i, u_i] \forall i=1,\ldots,d\}`` |
8484
| [`NormCone(p, d)`](@ref MathOptInterface.NormCone) | ``\{ (t,x) \in \mathbb{R}^{d} : t \ge \left(\sum\limits_i \lvert x_i \rvert^p\right)^{\frac{1}{p}} \}`` |
85+
| [`SetWithDotProcuts(s, v)`](@ref MathOptInterface.SetWithDotProducts) | The cone `s` with dot products with the fixed vectors `v`. |
86+
| [`LinearCombinationInSet(s, v)`](@ref MathOptInterface.LinearCombinationInSet) | The cone of vector `(y, x)` such that ``\sum_i y_i v_i + x`` belongs to `s`. |
8587

8688
## Matrix cones
8789

@@ -100,8 +102,6 @@ The matrix-valued set types implemented in MathOptInterface.jl are:
100102
| [`HermitianPositiveSemidefiniteConeTriangle(d)`](@ref MathOptInterface.HermitianPositiveSemidefiniteConeTriangle) | The cone of Hermitian positive semidefinite matrices, with
101103
`side_dimension` rows and columns. |
102104
| [`Scaled(S)`](@ref MathOptInterface.Scaled) | The set `S` scaled so that [`Utilities.set_dot`](@ref MathOptInterface.Utilities.set_dot) corresponds to `LinearAlgebra.dot` |
103-
| [`FrobeniusProductPostiviveSemidefiniteConeTriangle(d, A)`](@ref MathOptInterface.FrobeniusProductPostiviveSemidefiniteConeTriangle) | The cone of positive semidefinite matrices, with `side_dimension` rows and columns and their Frobenius inner product with the matrices in `A`. |
104-
| [`LinearMatrixInequalityConeTriangle(d, A)`](@ref MathOptInterface.LinearMatrixInequalityConeTriangle) | The cone of vector `y` and symmetric `C`, with `side_dimension` rows and columns such that ``\sum_i y_i A_i + C`` is positive semidefinite. |
105105

106106
Some of these cones can take two forms: `XXXConeTriangle` and `XXXConeSquare`.
107107

docs/src/reference/standard_form.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,6 @@ LogDetConeTriangle
153153
LogDetConeSquare
154154
RootDetConeTriangle
155155
RootDetConeSquare
156-
FrobeniusProductPostiviveSemidefiniteConeTriangle
157-
LinearMatrixInequalityConeTriangle
156+
SetWithDotProducts,
157+
LinearCombinationInSet,
158158
```

src/Utilities/model.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,6 @@ const LessThanIndicatorZero{T} =
806806
MOI.Scaled{MOI.PositiveSemidefiniteConeTriangle},
807807
MOI.RootDetConeTriangle,
808808
MOI.RootDetConeSquare,
809-
MOI.FrobeniusProductPostiviveSemidefiniteConeTriangle,
810-
MOI.LinearMatrixInequalityConeTriangle,
811809
MOI.LogDetConeTriangle,
812810
MOI.LogDetConeSquare,
813811
MOI.AllDifferent,

src/Utilities/results.jl

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -498,29 +498,3 @@ function get_fallback(
498498
f = MOI.get(model, MOI.ConstraintFunction(), ci)
499499
return _variable_dual(T, model, attr, ci, f)
500500
end
501-
502-
function set_dot(
503-
x::AbstractVector,
504-
y::AbstractVector,
505-
set::Union{
506-
MOI.FrobeniusProductPostiviveSemidefiniteConeTriangle,
507-
MOI.LinearMatrixInequalityConeTriangle,
508-
},
509-
)
510-
m = length(set.matrices)
511-
return LinearAlgebra.dot(view(x, 1:m), view(y, 1:m)) +
512-
triangle_dot(x, y, set.side_dimension, m)
513-
end
514-
515-
516-
function set_dot(
517-
a::AbstractVector,
518-
set::Union{
519-
MOI.FrobeniusProductPostiviveSemidefiniteConeTriangle,
520-
MOI.LinearMatrixInequalityConeTriangle,
521-
},
522-
)
523-
b = copy(a)
524-
triangle_coefficients!(b, set.side_dimension, length(set.matrices))
525-
return b
526-
end

src/Utilities/set_dot.jl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ function set_dot(
8686
return x[1] * y[1] + x[2] * y[2] + triangle_dot(x, y, set.side_dimension, 2)
8787
end
8888

89+
function set_dot(
90+
x::AbstractVector,
91+
y::AbstractVector,
92+
set::Union{
93+
MOI.SetWithDotProducts,
94+
MOI.LinearCombinationInSet,
95+
},
96+
)
97+
m = length(set.matrices)
98+
return LinearAlgebra.dot(view(x, 1:m), view(y, 1:m)) +
99+
set_dot(view(x, (m+1):length(x)), view(y, (m+1):length(y)), set.set)
100+
end
101+
89102
"""
90103
dot_coefficients(a::AbstractVector, set::AbstractVectorSet)
91104
@@ -145,6 +158,19 @@ function dot_coefficients(a::AbstractVector, set::MOI.LogDetConeTriangle)
145158
return b
146159
end
147160

161+
function dot_coefficients(
162+
a::AbstractVector,
163+
set::Union{
164+
MOI.SetWithDotProducts,
165+
MOI.LinearCombinationInSet,
166+
},
167+
)
168+
b = copy(a)
169+
m = length(set.vectors)
170+
b[(m+1):end] = dot_coefficients(b[(m+1):end], set.set)
171+
return b
172+
end
173+
148174
# For `SetDotScalingVector`, we would like to compute the dot product
149175
# of canonical vectors in O(1) instead of O(n)
150176
# See https://github.com/jump-dev/Dualization.jl/pull/135

src/sets.jl

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1804,58 +1804,52 @@ function Base.getproperty(
18041804
end
18051805

18061806
"""
1807-
FrobeniusProductPostiviveSemidefiniteConeTriangle{M}(side_dimension::Int, matrices::Vector{M})
1807+
SetWithDotProducts(set, vectors::Vector{V})
18081808
1809-
Given `m` symmetric matrices `A_1`, ..., `A_m` given in `matrices`, the frobenius inner
1810-
product of positive semidefinite matrices is the convex cone:
1811-
``\\{ ((\\langle A_1, X \\rangle, ..., \\langle A_m, X \\rangle, X) \\in \\mathbb{R}^{m + d(d+1)/2} : X \\text{ postive semidefinite} \\}``,
1812-
where the matrix `X` is represented in the same symmetric packed format as in
1813-
the [`PositiveSemidefiniteConeTriangle`](@ref).
1809+
Given a set `set` of dimension `d` and `m` vectors `v_1`, ..., `v_m` given in `vectors`, this is the set:
1810+
``\\{ ((\\langle v_1, x \\rangle, ..., \\langle v_m, x \\rangle, x) \\in \\mathbb{R}^{m + d} : x \\in \\text{set} \\}.``
18141811
"""
1815-
struct FrobeniusProductPostiviveSemidefiniteConeTriangle{M} <: AbstractVectorSet
1816-
side_dimension::Int
1817-
matrices::Vector{M}
1812+
struct SetWithDotProducts{S,V} <: AbstractVectorSet
1813+
set::S
1814+
vectors::Vector{V}
18181815
end
18191816

1820-
function dimension(s::FrobeniusProductPostiviveSemidefiniteConeTriangle)
1821-
return length(s.matrices) + s.side_dimension^2
1817+
function dimension(s::SetWithDotProducts)
1818+
return length(s.vectors) + dimension(s.set)
18221819
end
18231820

1824-
function dual_set(s::FrobeniusProductPostiviveSemidefiniteConeTriangle)
1825-
return LinearMatrixInequalityConeTriangle(s.side_dimension, s.matrices)
1821+
function dual_set(s::SetWithDotProducts)
1822+
return LinearCombinationInSet(s.set, s.vectors)
18261823
end
18271824

18281825
function dual_set_type(
1829-
::Type{FrobeniusProductPostiviveSemidefiniteConeTriangle{M}},
1830-
) where {M}
1831-
return LinearMatrixInequalityConeTriangle
1826+
::Type{SetWithDotProducts{S,V}},
1827+
) where {S,V}
1828+
return LinearCombinationInSet{S,V}
18321829
end
18331830

18341831
"""
1835-
LinearMatrixInequalityConeTriangle{M}(side_dimension::Int, matrices::Vector{M})
1832+
LinearCombinationInSet{S,V}(set::S, matrices::Vector{V})
18361833
1837-
Given `m` symmetric matrices `A_1`, ..., `A_m` given in `matrices`, the linear
1838-
matrix inequality cone is the convex cone:
1839-
``\\{ ((y, C) \\in \\mathbb{R}^{m + d(d+1)/2} : \\sum_{i=1}^m y_i A_i + C \\text{ postive semidefinite} \\}``,
1840-
where the matrix `C` is represented in the same symmetric packed format as in
1841-
the [`PositiveSemidefiniteConeTriangle`](@ref).
1834+
Given a set `set` of dimension `d` and `m` vectors `v_1`, ..., `v_m` given in `vectors`, this is the set:
1835+
``\\{ ((y, x) \\in \\mathbb{R}^{m + d} : \\sum_{i=1}^m y_i v_i + x \\in \\text{set} \\}.``
18421836
"""
1843-
struct LinearMatrixInequalityConeTriangle{M} <: AbstractVectorSet
1844-
side_dimension::Int
1845-
matrices::Vector{M}
1837+
struct LinearCombinationInSet{S,V} <: AbstractVectorSet
1838+
set::S
1839+
vectors::Vector{V}
18461840
end
18471841

1848-
dimension(s::LinearMatrixInequalityConeTriangle) = length(s.matrices) + s.side_dimension^2
1842+
dimension(s::LinearCombinationInSet) = length(s.vectors) + simension(s.set)
18491843

1850-
function dual_set(s::LinearMatrixInequalityConeTriangle)
1851-
return FrobeniusProductPostiviveSemidefiniteConeTriangle(
1844+
function dual_set(s::LinearCombinationInSet)
1845+
return SetWithDotProducts(
18521846
s.side_dimension,
18531847
s.matrices,
18541848
)
18551849
end
18561850

1857-
function dual_set_type(::Type{LinearMatrixInequalityConeTriangle{M}}) where {M}
1858-
return FrobeniusProductPostiviveSemidefiniteConeTriangle
1851+
function dual_set_type(::Type{LinearCombinationInSet{S,V}}) where {S,V}
1852+
return SetWithDotProducts{S,V}
18591853
end
18601854

18611855
"""

0 commit comments

Comments
 (0)