Skip to content

Commit d39cc85

Browse files
authored
[Utilities] Fix for empty product of sets (#2101)
1 parent d1cd81b commit d39cc85

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Utilities/product_of_sets.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,12 @@ end
206206

207207
function MOI.dimension(sets::OrderedProductOfSets)
208208
@assert sets.final_touch
209-
return sets.num_rows[end]
209+
if isempty(sets.num_rows)
210+
# There is no set type
211+
return 0
212+
else
213+
return sets.num_rows[end]
214+
end
210215
end
211216

212217
function rows(

test/Utilities/matrix_of_constraints.jl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ MOI.Utilities.@product_of_sets(
5555
MOI.SecondOrderCone,
5656
)
5757

58-
function _new_VectorSets()
58+
function _new_VectorSets(V = VectorSets)
5959
return MOI.Utilities.GenericOptimizer{
6060
Int,
6161
MOI.Utilities.ObjectiveContainer{Int},
@@ -68,7 +68,7 @@ function _new_VectorSets()
6868
MOI.Utilities.OneBasedIndexing,
6969
},
7070
Vector{Int},
71-
VectorSets{Int},
71+
V{Int},
7272
},
7373
}()
7474
end
@@ -610,6 +610,20 @@ function test_set_with_dimension()
610610
return
611611
end
612612

613+
MOI.Utilities.@product_of_sets(EmptyProductOfSets)
614+
615+
function test_empty_product_of_sets(T = Int)
616+
model = _new_VectorSets(EmptyProductOfSets)
617+
x = MOI.add_variable(model)
618+
MOI.Utilities.final_touch(model, nothing)
619+
A = convert(
620+
SparseArrays.SparseMatrixCSC{T,Int},
621+
model.constraints.coefficients,
622+
)
623+
@test size(A) == (0, 1)
624+
return
625+
end
626+
613627
end
614628

615629
TestMatrixOfConstraints.runtests()

0 commit comments

Comments
 (0)