From 33f355dfd832328f516e72360cf6196081358bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 16 Jul 2025 12:50:15 +0200 Subject: [PATCH] Define AnnotationCallback to replace Nothing --- src/formulations.jl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/formulations.jl b/src/formulations.jl index be786c6..12478a4 100644 --- a/src/formulations.jl +++ b/src/formulations.jl @@ -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