Skip to content

Commit 33f355d

Browse files
committed
Define AnnotationCallback to replace Nothing
1 parent 7d229b7 commit 33f355d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/formulations.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,25 @@ function _specify!(sp::SubproblemForm, solver::Union{MOI.OptimizerWithAttributes
130130
return
131131
end
132132

133+
"""
134+
AnnotationCallback
135+
136+
A [`PricingCallback`](@ref) for which the oracle is registered through the annotations.
137+
"""
138+
struct AnnotationCallback end
139+
140+
MOI.Utilities.map_indices(::F, x::AnnotationCallback) where {F<:Function} = x
141+
133142
function _specify!(sp::SubproblemForm, oracle::Function)
134143
pushoptimizerbuilder!(sp.annotation, oracle)
135-
# The model must know it has a pricing callbacl otherwise it's impossible
136-
# to use call the pricing callback when using a caching optimizer.
144+
# The model must know it has a pricing callback otherwise it's impossible
145+
# to use call the pricing callback when using a caching optimizer because
146+
# it will not have the `index_map` during the callback. See
147+
# https://github.com/jump-dev/MathOptInterface.jl/blob/d66c13dab9cbd76c3451faffafd7d828a4e04ee1/src/Utilities/cachingoptimizer.jl#L358-L369
137148
# TODO(guimarqu): we currently pass the optimizer
138-
MOI.set(sp.model, PricingCallback(), nothing)
149+
# We cannot pass `nothing` as MOI interprets `nothing` as unsetting the value of an attribute.
150+
# so we pass a custom value.
151+
MOI.set(sp.model, PricingCallback(), AnnotationCallback())
139152
return
140153
end
141154

0 commit comments

Comments
 (0)