Skip to content

Define AnnotationCallback to replace Nothing #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025
Merged
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
19 changes: 16 additions & 3 deletions src/formulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,25 @@ function _specify!(sp::SubproblemForm, solver::Union{MOI.OptimizerWithAttributes
return
end

"""
AnnotationCallback

A [`PricingCallback`](@ref) for which the oracle is registered through the annotations.
"""
struct AnnotationCallback end

MOI.Utilities.map_indices(::F, x::AnnotationCallback) where {F<:Function} = x

function _specify!(sp::SubproblemForm, oracle::Function)
pushoptimizerbuilder!(sp.annotation, oracle)
# The model must know it has a pricing callbacl otherwise it's impossible
# to use call the pricing callback when using a caching optimizer.
# The model must know it has a pricing callback otherwise it's impossible
# to use call the pricing callback when using a caching optimizer because
# it will not have the `index_map` during the callback. See
# https://github.com/jump-dev/MathOptInterface.jl/blob/d66c13dab9cbd76c3451faffafd7d828a4e04ee1/src/Utilities/cachingoptimizer.jl#L358-L369
# TODO(guimarqu): we currently pass the optimizer
MOI.set(sp.model, PricingCallback(), nothing)
# We cannot pass `nothing` as MOI interprets `nothing` as unsetting the value of an attribute.
# so we pass a custom value.
MOI.set(sp.model, PricingCallback(), AnnotationCallback())
return
end

Expand Down