Skip to content

Commit f26cbc5

Browse files
authored
Move sets into sets.jl (#349)
* Move sets into sets.jl * Rename sos_polynomial.jl * Fixes * Fix docstring * Fix format
1 parent b52f933 commit f26cbc5

File tree

7 files changed

+115
-111
lines changed

7 files changed

+115
-111
lines changed

docs/src/references.bib

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ @InBook{Laurent2008
8787
issn = {0940-6573},
8888
}
8989

90+
@Article{Murty1987,
91+
title = {Some {{NP-complete}} Problems in Quadratic and Nonlinear Programming},
92+
author = {Murty, Katta G and Kabadi, Santosh N},
93+
year = {1987},
94+
journal = {Mathematical Programming: Series A and B},
95+
volume = {39},
96+
number = {2},
97+
pages = {117--129},
98+
publisher = {Springer-Verlag Berlin, Heidelberg}
99+
}
100+
90101
@Article{Parrilo2003,
91102
title = {Semidefinite Programming Relaxations for Semialgebraic Problems},
92103
author = {Parrilo, Pablo A},

src/SumOfSquares.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ Reexport.@reexport using PolyJuMP
4747

4848
include("sets.jl")
4949
include("attributes.jl")
50-
include("diagonally_dominant.jl")
51-
include("sos_polynomial.jl")
50+
include("build_matrix.jl")
5251
include("copositive_inner.jl")
5352

5453
# Bridges

src/sos_polynomial.jl renamed to src/build_matrix.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,3 @@ end
162162
function build_moment_matrix(q::Vector, basis::AbstractPolynomialBasis)
163163
return MomentMatrix(MultivariateMoments.SymMatrix(q, length(basis)), basis)
164164
end
165-
166-
struct SOSPolynomialSet{
167-
DT<:AbstractSemialgebraicSet,
168-
MT<:MP.AbstractMonomial,
169-
MVT<:AbstractVector{MT},
170-
CT<:Certificate.AbstractCertificate,
171-
} <: MOI.AbstractVectorSet
172-
domain::DT
173-
monomials::MVT
174-
certificate::CT
175-
end
176-
MOI.dimension(set::SOSPolynomialSet) = length(set.monomials)
177-
Base.copy(set::SOSPolynomialSet) = set

src/copositive_inner.jl

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export CopositiveInner
99
1010
A symmetric matrix ``Q`` is copositive if ``x^{\\top} Q x \\ge 0`` for all
1111
vector ``x`` in the nonnegative orthant. Checking copositivity is a
12-
co-NP-complete problem [MK87] and this cone is only the inner approximation of
12+
co-NP-complete problem [Murty1987](@cite) and this cone is only the inner approximation of
1313
the cone of copositive symmetric matrices given by Minknowski sum of `psd_inner`
1414
and the cone of symmetric matrices with nonnegative entries (the diagonal
1515
entries can be chosen to be zero) [Blekherman2012; Lemma 3.164](@cite).
@@ -46,13 +46,9 @@ which is the same as, using the `domain` keyword,
4646
4747
As an important difference with its equivalent forms, the
4848
[`GramMatrixAttribute`](@ref) for the copositive constraint is given by matrix
49-
`Q` while for the equivalent form using the domain` keyword, the value
49+
`Q` while for the equivalent form using the `domain` keyword, the value
5050
of the attribute would correspond to the the gram matrix in the `psd_inner`
5151
cone, i.e. which should be equal to `Q - Λ`.
52-
53-
[MK87] K. G. Murty and S. N. Kabadi.
54-
*Some NP-complete problems in quadratic and nonlinear programming*.
55-
Mathematical programming, 39:117–129, **1987**.
5652
"""
5753
struct CopositiveInner{S} <: SOSLikeCone
5854
psd_inner::S
@@ -65,10 +61,7 @@ end
6561
function matrix_cone_type(::Type{CopositiveInner{S}}) where {S}
6662
return CopositiveInnerCone{matrix_cone_type(S)}
6763
end
68-
function matrix_cone(
69-
set::Type{CopositiveInnerCone{S}},
70-
side_dimension,
71-
) where {S}
64+
function matrix_cone(::Type{CopositiveInnerCone{S}}, side_dimension) where {S}
7265
return CopositiveInnerCone(matrix_cone(S, side_dimension))
7366
end
7467
MOI.side_dimension(set::CopositiveInnerCone) = MOI.side_dimension(set.psd_inner)

src/diagonally_dominant.jl

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/sets.jl

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,101 @@ MOI.side_dimension(::PositiveSemidefinite2x2ConeTriangle) = 2
2222
function Base.copy(set::Union{EmptyCone,PositiveSemidefinite2x2ConeTriangle})
2323
return set
2424
end
25+
26+
function matrix_cone(
27+
S::Type{<:MOI.AbstractSymmetricMatrixSetTriangle},
28+
side_dimension,
29+
)
30+
if iszero(side_dimension)
31+
# Some solvers such as Mosek does not support 0-dimensional PSD cone
32+
return EmptyCone()
33+
elseif isone(side_dimension)
34+
# PSD constraints on 1x1 matrices are equivalent to the nonnegativity
35+
# of the only entry.
36+
return MOI.Nonnegatives(1)
37+
elseif side_dimension == 2
38+
# PSD constraints on 2x2 matrices are SOC representable.
39+
return PositiveSemidefinite2x2ConeTriangle()
40+
else
41+
# PSD constraints on nxn matrices with n ≥ 3 is not SOC representable,
42+
# see [F18].
43+
#
44+
# [F18] Fawzi, Hamza
45+
# On representing the positive semidefinite cone using the second-order
46+
# cone.
47+
# Mathematical Programming (2018): 1-10.
48+
return S(side_dimension)
49+
end
50+
end
51+
52+
"""
53+
struct DiagonallyDominantConeTriangle <: MOI.AbstractSymmetricMatrixSetTriangle
54+
side_dimension::Int
55+
end
56+
57+
See [Ahmadi2017; Definition 4](@cite) for a precise definition of the last two items.
58+
"""
59+
struct DiagonallyDominantConeTriangle <: MOI.AbstractSymmetricMatrixSetTriangle
60+
side_dimension::Int
61+
end
62+
63+
function matrix_cone(S::Type{DiagonallyDominantConeTriangle}, side_dimension)
64+
if iszero(side_dimension)
65+
return EmptyCone()
66+
elseif isone(side_dimension)
67+
return MOI.Nonnegatives(1)
68+
else
69+
# With `side_dimension` = 2, we want to avoid using SOC and only use LP
70+
return S(side_dimension)
71+
end
72+
end
73+
74+
"""
75+
struct ScaledDiagonallyDominantConeTriangle <: MOI.AbstractSymmetricMatrixSetTriangle
76+
side_dimension::Int
77+
end
78+
79+
See [Ahmadi2017; Definition 4](@cite) for a precise definition of the last two items.
80+
"""
81+
struct ScaledDiagonallyDominantConeTriangle <:
82+
MOI.AbstractSymmetricMatrixSetTriangle
83+
side_dimension::Int
84+
end
85+
86+
function matrix_cone(
87+
S::Type{ScaledDiagonallyDominantConeTriangle},
88+
side_dimension,
89+
)
90+
if iszero(side_dimension)
91+
return EmptyCone()
92+
elseif isone(side_dimension)
93+
return MOI.Nonnegatives(side_dimension)
94+
elseif side_dimension == 2
95+
return PositiveSemidefinite2x2ConeTriangle()
96+
else
97+
return S(side_dimension)
98+
end
99+
end
100+
101+
# isbits types, nothing to copy
102+
function Base.copy(
103+
set::Union{
104+
DiagonallyDominantConeTriangle,
105+
ScaledDiagonallyDominantConeTriangle,
106+
},
107+
)
108+
return set
109+
end
110+
111+
struct SOSPolynomialSet{
112+
DT<:AbstractSemialgebraicSet,
113+
MT<:MP.AbstractMonomial,
114+
MVT<:AbstractVector{MT},
115+
CT<:Certificate.AbstractCertificate,
116+
} <: MOI.AbstractVectorSet
117+
domain::DT
118+
monomials::MVT
119+
certificate::CT
120+
end
121+
MOI.dimension(set::SOSPolynomialSet) = length(set.monomials)
122+
Base.copy(set::SOSPolynomialSet) = set

src/variables.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function moi_add_variable(
3535
binary::Bool,
3636
integer::Bool,
3737
)
38-
Q, con_Q = MOI.add_constrained_variables(model, set)
38+
Q, _ = MOI.add_constrained_variables(model, set)
3939
if binary
4040
for q in Q
4141
MOI.add_constraint(model, q, MOI.ZeroOne())
@@ -52,7 +52,7 @@ end
5252
function JuMP.add_variable(
5353
model::JuMP.AbstractModel,
5454
v::PolyJuMP.Variable{<:PosPoly},
55-
name::String = "",
55+
::String = "",
5656
)
5757
MCT = matrix_cone_type(v.p)
5858
set = matrix_cone(MCT, length(v.p.polynomial_basis))

0 commit comments

Comments
 (0)