diff --git a/src/Utilities/matrix_of_constraints.jl b/src/Utilities/matrix_of_constraints.jl index cee2305cc1..451b6e9ef7 100644 --- a/src/Utilities/matrix_of_constraints.jl +++ b/src/Utilities/matrix_of_constraints.jl @@ -525,8 +525,35 @@ end function_constants(b::Vector, rows) = b[rows] -# FIXME does not work for all sets -set_from_constants(::Vector, ::Type{S}, rows) where {S} = S(length(rows)) +function set_from_constants( + ::Vector, + ::Type{S}, + rows, +) where {S<:MOI.AbstractVectorSet} + return S(length(rows)) +end + +function set_from_constants( + ::Vector, + ::Type{S}, + rows, +) where {S<:MOI.AbstractSymmetricMatrixSetTriangle} + nnz = length(rows) + side_dimension = (-1 + sqrt(1 + 8nnz)) / 2 + @assert side_dimension * (side_dimension + 1) == 2 * nnz + return S(Int(side_dimension)) +end + +function set_from_constants( + ::Vector, + ::Type{S}, + rows, +) where {S<:MOI.AbstractSymmetricMatrixSetSquare} + nnz = length(rows) + side_dimension = isqrt(nnz) + @assert length(rows) == side_dimension^2 + return S(side_dimension) +end function MOI.get( model::MatrixOfConstraints, diff --git a/test/Utilities/matrix_of_constraints.jl b/test/Utilities/matrix_of_constraints.jl index 9b0d6bc864..3519490396 100644 --- a/test/Utilities/matrix_of_constraints.jl +++ b/test/Utilities/matrix_of_constraints.jl @@ -49,6 +49,8 @@ MOI.Utilities.@product_of_sets( MOI.Nonnegatives, MOI.Nonpositives, MOI.SecondOrderCone, + MOI.PositiveSemidefiniteConeSquare, + MOI.PositiveSemidefiniteConeTriangle, ) function _new_VectorSets() @@ -398,6 +400,30 @@ function test_multicone() return end +function test_matrix_sets_Triangle() + S = MOI.PositiveSemidefiniteConeTriangle + model = MOI.Utilities.Model{Int}() + x = MOI.add_variables(model, 3) + f = MOI.Utilities.operate(vcat, Int, (1 .* x)...) + c = MOI.add_constraint(model, f, S(2)) + dest = _new_VectorSets() + map = MOI.copy_to(dest, model) + @test MOI.get(dest, MOI.ConstraintSet(), map[c]) == S(2) + return +end + +function test_matrix_sets_Square() + S = MOI.PositiveSemidefiniteConeSquare + model = MOI.Utilities.Model{Int}() + x = MOI.add_variables(model, 4) + f = MOI.Utilities.operate(vcat, Int, (1 .* x)...) + c = MOI.add_constraint(model, f, S(2)) + dest = _new_VectorSets() + map = MOI.copy_to(dest, model) + @test MOI.get(dest, MOI.ConstraintSet(), map[c]) == S(2) + return +end + end TestMatrixOfConstraints.runtests()