@@ -137,25 +137,6 @@ triangular part of the matrix is constrained to belong to the
137
137
"""
138
138
struct PSDCone end
139
139
140
- function build_constraint (
141
- _error:: Function ,
142
- f:: AbstractMatrix{<:AbstractJuMPScalar} ,
143
- :: Nonnegatives ,
144
- extra:: PSDCone ,
145
- )
146
- return build_constraint (_error, f, extra)
147
- end
148
-
149
- function build_constraint (
150
- _error:: Function ,
151
- f:: AbstractMatrix{<:AbstractJuMPScalar} ,
152
- :: Nonpositives ,
153
- extra:: PSDCone ,
154
- )
155
- new_f = _MA. operate!! (* , - 1 , f)
156
- return build_constraint (_error, new_f, extra)
157
- end
158
-
159
140
"""
160
141
SymmetricMatrixShape
161
142
@@ -167,6 +148,7 @@ lower-left triangular part given row by row).
167
148
struct SymmetricMatrixShape <: AbstractShape
168
149
side_dimension:: Int
169
150
end
151
+
170
152
function reshape_vector (
171
153
vectorized_form:: Vector{T} ,
172
154
shape:: SymmetricMatrixShape ,
@@ -181,12 +163,14 @@ function reshape_vector(
181
163
end
182
164
return LinearAlgebra. Symmetric (matrix)
183
165
end
166
+
184
167
function reshape_set (
185
168
:: MOI.PositiveSemidefiniteConeTriangle ,
186
169
:: SymmetricMatrixShape ,
187
170
)
188
171
return PSDCone ()
189
172
end
173
+
190
174
function vectorize (matrix, :: SymmetricMatrixShape )
191
175
n = LinearAlgebra. checksquare (matrix)
192
176
return [matrix[i, j] for j in 1 : n for i in 1 : j]
@@ -414,12 +398,7 @@ function build_variable(
414
398
)
415
399
n = _square_side (_error, variables)
416
400
set = MOI. PositiveSemidefiniteConeTriangle (n)
417
- shape = SymmetricMatrixShape (n)
418
- return VariablesConstrainedOnCreation (
419
- _vectorize_variables (_error, variables),
420
- set,
421
- shape,
422
- )
401
+ return build_variable (_error, variables, set)
423
402
end
424
403
425
404
function value (
@@ -476,12 +455,7 @@ function build_constraint(
476
455
:: PSDCone ,
477
456
) where {V<: AbstractJuMPScalar ,M<: AbstractMatrix{V} }
478
457
n = LinearAlgebra. checksquare (Q)
479
- shape = SymmetricMatrixShape (n)
480
- return VectorConstraint (
481
- vectorize (Q, shape),
482
- MOI. PositiveSemidefiniteConeTriangle (n),
483
- shape,
484
- )
458
+ return build_constraint (_error, Q, MOI. PositiveSemidefiniteConeTriangle (n))
485
459
end
486
460
487
461
"""
@@ -511,12 +485,7 @@ function build_constraint(
511
485
:: PSDCone ,
512
486
)
513
487
n = LinearAlgebra. checksquare (Q)
514
- shape = SquareMatrixShape (n)
515
- return VectorConstraint (
516
- vectorize (Q, shape),
517
- MOI. PositiveSemidefiniteConeSquare (n),
518
- shape,
519
- )
488
+ return build_constraint (_error, Q, MOI. PositiveSemidefiniteConeSquare (n))
520
489
end
521
490
522
491
"""
@@ -742,3 +711,60 @@ function build_constraint(_error::Function, ::AbstractMatrix, ::Zeros)
742
711
" `LinearAlgebra.Symmetric` or `LinearAlgebra.Hermitian`." ,
743
712
)
744
713
end
714
+
715
+ function build_constraint (
716
+ _error:: Function ,
717
+ Q:: LinearAlgebra.Symmetric{V,M} ,
718
+ set:: MOI.AbstractSymmetricMatrixSetTriangle ,
719
+ ) where {V<: AbstractJuMPScalar ,M<: AbstractMatrix{V} }
720
+ n = LinearAlgebra. checksquare (Q)
721
+ shape = SymmetricMatrixShape (n)
722
+ return VectorConstraint (vectorize (Q, shape), set, shape)
723
+ end
724
+
725
+ function build_constraint (
726
+ _error:: Function ,
727
+ Q:: AbstractMatrix{<:AbstractJuMPScalar} ,
728
+ set:: MOI.AbstractSymmetricMatrixSetSquare ,
729
+ )
730
+ n = LinearAlgebra. checksquare (Q)
731
+ shape = SquareMatrixShape (n)
732
+ return VectorConstraint (vectorize (Q, shape), set, shape)
733
+ end
734
+
735
+ function build_constraint (
736
+ _error:: Function ,
737
+ f:: AbstractMatrix{<:AbstractJuMPScalar} ,
738
+ :: Nonnegatives ,
739
+ extra:: Union {
740
+ MOI. AbstractSymmetricMatrixSetTriangle,
741
+ MOI. AbstractSymmetricMatrixSetSquare,
742
+ PSDCone,
743
+ },
744
+ )
745
+ return build_constraint (_error, f, extra)
746
+ end
747
+
748
+ function build_constraint (
749
+ _error:: Function ,
750
+ f:: AbstractMatrix{<:AbstractJuMPScalar} ,
751
+ :: Nonpositives ,
752
+ extra:: Union {
753
+ MOI. AbstractSymmetricMatrixSetTriangle,
754
+ MOI. AbstractSymmetricMatrixSetSquare,
755
+ PSDCone,
756
+ },
757
+ )
758
+ new_f = _MA. operate!! (* , - 1 , f)
759
+ return build_constraint (_error, new_f, extra)
760
+ end
761
+
762
+ function build_variable (
763
+ _error:: Function ,
764
+ variables:: Matrix{<:AbstractVariable} ,
765
+ set:: MOI.AbstractSymmetricMatrixSetTriangle ,
766
+ )
767
+ n = _square_side (_error, variables)
768
+ x = _vectorize_variables (_error, variables)
769
+ return VariablesConstrainedOnCreation (x, set, SymmetricMatrixShape (n))
770
+ end
0 commit comments