Skip to content

Commit f388b6f

Browse files
committed
Update
1 parent 57fb0ad commit f388b6f

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

src/Utilities/universalfallback.jl

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,8 @@ function MOI.get(
464464
listattr::MOI.ListOfOptimizerAttributesSet,
465465
)
466466
list = MOI.get(uf.model, listattr)
467-
for (attr, value) in uf.optattr
468-
if value !== nothing
469-
push!(list, attr)
470-
end
467+
for attr in keys(uf.optattr)
468+
push!(list, attr)
471469
end
472470
return list
473471
end
@@ -477,10 +475,8 @@ function MOI.get(uf::UniversalFallback, listattr::MOI.ListOfModelAttributesSet)
477475
if uf.objective !== nothing
478476
push!(list, MOI.ObjectiveFunction{typeof(uf.objective)}())
479477
end
480-
for (attr, value) in uf.modattr
481-
if value !== nothing
482-
push!(list, attr)
483-
end
478+
for attr in keys(uf.modattr)
479+
push!(list, attr)
484480
end
485481
return list
486482
end
@@ -490,10 +486,8 @@ function MOI.get(
490486
listattr::MOI.ListOfVariableAttributesSet,
491487
)
492488
list = MOI.get(uf.model, listattr)
493-
for (attr, value) in uf.varattr
494-
if any(!isnothing, values(value))
495-
push!(list, attr)
496-
end
489+
for attr in keys(uf.varattr)
490+
push!(list, attr)
497491
end
498492
return list
499493
end
@@ -504,11 +498,8 @@ function MOI.get(
504498
) where {F,S}
505499
list = MOI.get(uf.model, listattr)
506500
for (attr, dict) in uf.conattr
507-
for (k, v) in dict
508-
if k isa MOI.ConstraintIndex{F,S} && !isnothing(v)
509-
push!(list, attr)
510-
break
511-
end
501+
if any(Base.Fix2(isa, MOI.ConstraintIndex{F,S}), keys(dict))
502+
push!(list, attr)
512503
end
513504
end
514505
# ConstraintName isn't stored in conattr, but in the .con_to_name dictionary
@@ -703,17 +694,20 @@ function MOI.get(
703694
)
704695
end
705696

697+
_set_or_delete(dict, key, value) = (dict[key] = value)
698+
_set_or_delete(dict, key, ::Nothing) = delete!(dict, key)
699+
706700
function _set(
707701
uf::UniversalFallback,
708702
attr::MOI.AbstractOptimizerAttribute,
709703
value,
710704
)
711-
uf.optattr[attr] = value
705+
_set_or_delete(uf.optattr, attr, value)
712706
return
713707
end
714708

715709
function _set(uf::UniversalFallback, attr::MOI.AbstractModelAttribute, value)
716-
uf.modattr[attr] = value
710+
_set_or_delete(uf.modattr, attr, value)
717711
return
718712
end
719713

@@ -726,7 +720,7 @@ function _set(
726720
if !haskey(uf.varattr, attr)
727721
uf.varattr[attr] = Dict{MOI.VariableIndex,Any}()
728722
end
729-
uf.varattr[attr][vi] = value
723+
_set_or_delete(uf.varattr[attr], vi, value)
730724
return
731725
end
732726

@@ -739,7 +733,7 @@ function _set(
739733
if !haskey(uf.conattr, attr)
740734
uf.conattr[attr] = Dict{MOI.ConstraintIndex,Any}()
741735
end
742-
uf.conattr[attr][ci] = value
736+
_set_or_delete(uf.conattr[attr], ci, value)
743737
return
744738
end
745739

test/Utilities/universalfallback.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ end
6868
### The tests
6969
###
7070

71-
# function test_MOI_Test()
72-
# inner = ModelForUniversalFallback{Float64}()
73-
# model = MOI.Utilities.UniversalFallback(inner)
74-
# MOI.Test.runtests(
75-
# model,
76-
# MOI.Test.Config(exclude = Any[MOI.optimize!]),
77-
# exclude = String[
78-
# # UniversalFallback fails all these tests because it supports
79-
# # everything
80-
# "test_attribute_",
81-
# "test_model_supports_constraint_",
82-
# "test_model_copy_to_Unsupported",
83-
# # Bugs in UniversalFallback
84-
# "test_model_LowerBoundAlreadySet",
85-
# "test_model_UpperBoundAlreadySet",
86-
# "test_add_parameter",
87-
# ],
88-
# )
89-
# return
90-
# end
71+
function test_MOI_Test()
72+
inner = ModelForUniversalFallback{Float64}()
73+
model = MOI.Utilities.UniversalFallback(inner)
74+
MOI.Test.runtests(
75+
model,
76+
MOI.Test.Config(exclude = Any[MOI.optimize!]),
77+
exclude = String[
78+
# UniversalFallback fails all these tests because it supports
79+
# everything
80+
"test_attribute_",
81+
"test_model_supports_constraint_",
82+
"test_model_copy_to_Unsupported",
83+
# Bugs in UniversalFallback
84+
"test_model_LowerBoundAlreadySet",
85+
"test_model_UpperBoundAlreadySet",
86+
"test_add_parameter",
87+
],
88+
)
89+
return
90+
end
9191

9292
function _test_Optimizer_Model_attributes(
9393
uf::MOI.Utilities.UniversalFallback,

0 commit comments

Comments
 (0)