Skip to content

Commit 72c3705

Browse files
authored
[Utilities] fix a Utilities.AbstractModel with no constraints (#2819)
1 parent 7e27018 commit 72c3705

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/Utilities/model.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,10 @@ end
369369
function MOI.get(
370370
model::AbstractModel{T},
371371
attr::MOI.ListOfConstraintTypesPresent,
372-
) where {T}
372+
)::Vector{Tuple{Type,Type}} where {T}
373373
return vcat(
374-
MOI.get(model.constraints, attr)::Vector{Tuple{Type,Type}},
375-
MOI.get(model.variables, attr)::Vector{Tuple{Type,Type}},
374+
MOI.get(model.constraints, attr),
375+
MOI.get(model.variables, attr),
376376
)
377377
end
378378

src/Utilities/struct_of_constraints.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ function MOI.get(
152152
end
153153

154154
function MOI.is_empty(model::StructOfConstraints)
155-
return mapreduce_constraints(&, model, true) do constrs
155+
ret = mapreduce_constraints(&, model, true) do constrs
156156
return constrs === nothing || MOI.is_empty(constrs)
157157
end
158+
return something(ret, true)
158159
end
159160

160161
function MOI.empty!(model::StructOfConstraints)

test/Utilities/model.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,16 @@ function test_struct_of_constraints_by_set_types()
617617
return
618618
end
619619

620+
MOI.Utilities.@model(EmptyModel, (), (), (), (), (), (), (), ())
621+
622+
function test_empty_model()
623+
model = EmptyModel{Float64}()
624+
@test MOI.is_empty(model)
625+
@test MOI.get(model, MOI.ListOfConstraintTypesPresent()) ==
626+
Tuple{Type,Type}[]
627+
return
628+
end
629+
620630
end # module
621631

622632
TestModel.runtests()

0 commit comments

Comments
 (0)