Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/Utilities/matrix_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions test/Utilities/matrix_of_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ MOI.Utilities.@product_of_sets(
MOI.Nonnegatives,
MOI.Nonpositives,
MOI.SecondOrderCone,
MOI.PositiveSemidefiniteConeSquare,
MOI.PositiveSemidefiniteConeTriangle,
)

function _new_VectorSets()
Expand Down Expand Up @@ -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()