forked from jump-dev/MathOptInterface.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMathOptInterfaceCliqueTreesExt.jl
More file actions
35 lines (29 loc) · 1.1 KB
/
MathOptInterfaceCliqueTreesExt.jl
File metadata and controls
35 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Copyright (c) 2017: Miles Lubin and contributors
# Copyright (c) 2017: Google Inc.
#
# Use of this source code is governed by an MIT-style license that can be found
# in the LICENSE.md file or at https://opensource.org/licenses/MIT.
module MathOptInterfaceCliqueTreesExt
import CliqueTrees.Multifrontal: ChordalCholesky
import LinearAlgebra: RowMaximum, cholesky!
import MathOptInterface as MOI
import SparseArrays: findnz, sparse
function MOI.Bridges.Constraint.compute_sparse_sqrt_fallback(
Q::AbstractMatrix,
::F,
::S,
) where {F<:MOI.ScalarQuadraticFunction,S<:MOI.AbstractSet}
G = cholesky!(ChordalCholesky(Q), RowMaximum())
U = sparse(G.U) * G.P
# Verify the factorization reconstructs Q. This catches indefinite
# matrices where the diagonal is all zeros (e.g., [0 -1; -1 0]).
if !isapprox(Q, U' * U; atol = 1e-10)
msg = """
Unable to transform a quadratic constraint into a SecondOrderCone
constraint because the quadratic constraint is not convex.
"""
throw(MOI.UnsupportedConstraint{F,S}(msg))
end
return findnz(U)
end
end # module