Skip to content

Commit e37bd53

Browse files
committed
SetWithDotProducts
1 parent 66fcd61 commit e37bd53

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
@@ -792,8 +792,6 @@ const LessThanIndicatorZero{T} =
792792
MOI.Scaled{MOI.PositiveSemidefiniteConeTriangle},
793793
MOI.RootDetConeTriangle,
794794
MOI.RootDetConeSquare,
795-
MOI.FrobeniusProductPostiviveSemidefiniteConeTriangle,
796-
MOI.LinearMatrixInequalityConeTriangle,
797795
MOI.LogDetConeTriangle,
798796
MOI.LogDetConeSquare,
799797
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
@@ -1792,58 +1792,52 @@ function Base.getproperty(
17921792
end
17931793

17941794
"""
1795-
FrobeniusProductPostiviveSemidefiniteConeTriangle{M}(side_dimension::Int, matrices::Vector{M})
1795+
SetWithDotProducts(set, vectors::Vector{V})
17961796
1797-
Given `m` symmetric matrices `A_1`, ..., `A_m` given in `matrices`, the frobenius inner
1798-
product of positive semidefinite matrices is the convex cone:
1799-
``\\{ ((\\langle A_1, X \\rangle, ..., \\langle A_m, X \\rangle, X) \\in \\mathbb{R}^{m + d(d+1)/2} : X \\text{ postive semidefinite} \\}``,
1800-
where the matrix `X` is represented in the same symmetric packed format as in
1801-
the [`PositiveSemidefiniteConeTriangle`](@ref).
1797+
Given a set `set` of dimension `d` and `m` vectors `v_1`, ..., `v_m` given in `vectors`, this is the set:
1798+
``\\{ ((\\langle v_1, x \\rangle, ..., \\langle v_m, x \\rangle, x) \\in \\mathbb{R}^{m + d} : x \\in \\text{set} \\}.``
18021799
"""
1803-
struct FrobeniusProductPostiviveSemidefiniteConeTriangle{M} <: AbstractVectorSet
1804-
side_dimension::Int
1805-
matrices::Vector{M}
1800+
struct SetWithDotProducts{S,V} <: AbstractVectorSet
1801+
set::S
1802+
vectors::Vector{V}
18061803
end
18071804

1808-
function dimension(s::FrobeniusProductPostiviveSemidefiniteConeTriangle)
1809-
return length(s.matrices) + s.side_dimension^2
1805+
function dimension(s::SetWithDotProducts)
1806+
return length(s.vectors) + dimension(s.set)
18101807
end
18111808

1812-
function dual_set(s::FrobeniusProductPostiviveSemidefiniteConeTriangle)
1813-
return LinearMatrixInequalityConeTriangle(s.side_dimension, s.matrices)
1809+
function dual_set(s::SetWithDotProducts)
1810+
return LinearCombinationInSet(s.set, s.vectors)
18141811
end
18151812

18161813
function dual_set_type(
1817-
::Type{FrobeniusProductPostiviveSemidefiniteConeTriangle{M}},
1818-
) where {M}
1819-
return LinearMatrixInequalityConeTriangle
1814+
::Type{SetWithDotProducts{S,V}},
1815+
) where {S,V}
1816+
return LinearCombinationInSet{S,V}
18201817
end
18211818

18221819
"""
1823-
LinearMatrixInequalityConeTriangle{M}(side_dimension::Int, matrices::Vector{M})
1820+
LinearCombinationInSet{S,V}(set::S, matrices::Vector{V})
18241821
1825-
Given `m` symmetric matrices `A_1`, ..., `A_m` given in `matrices`, the linear
1826-
matrix inequality cone is the convex cone:
1827-
``\\{ ((y, C) \\in \\mathbb{R}^{m + d(d+1)/2} : \\sum_{i=1}^m y_i A_i + C \\text{ postive semidefinite} \\}``,
1828-
where the matrix `C` is represented in the same symmetric packed format as in
1829-
the [`PositiveSemidefiniteConeTriangle`](@ref).
1822+
Given a set `set` of dimension `d` and `m` vectors `v_1`, ..., `v_m` given in `vectors`, this is the set:
1823+
``\\{ ((y, x) \\in \\mathbb{R}^{m + d} : \\sum_{i=1}^m y_i v_i + x \\in \\text{set} \\}.``
18301824
"""
1831-
struct LinearMatrixInequalityConeTriangle{M} <: AbstractVectorSet
1832-
side_dimension::Int
1833-
matrices::Vector{M}
1825+
struct LinearCombinationInSet{S,V} <: AbstractVectorSet
1826+
set::S
1827+
vectors::Vector{V}
18341828
end
18351829

1836-
dimension(s::LinearMatrixInequalityConeTriangle) = length(s.matrices) + s.side_dimension^2
1830+
dimension(s::LinearCombinationInSet) = length(s.vectors) + simension(s.set)
18371831

1838-
function dual_set(s::LinearMatrixInequalityConeTriangle)
1839-
return FrobeniusProductPostiviveSemidefiniteConeTriangle(
1832+
function dual_set(s::LinearCombinationInSet)
1833+
return SetWithDotProducts(
18401834
s.side_dimension,
18411835
s.matrices,
18421836
)
18431837
end
18441838

1845-
function dual_set_type(::Type{LinearMatrixInequalityConeTriangle{M}}) where {M}
1846-
return FrobeniusProductPostiviveSemidefiniteConeTriangle
1839+
function dual_set_type(::Type{LinearCombinationInSet{S,V}}) where {S,V}
1840+
return SetWithDotProducts{S,V}
18471841
end
18481842

18491843
"""

0 commit comments

Comments
 (0)