diff --git a/src/MOI_wrapper/MOI_wrapper.jl b/src/MOI_wrapper/MOI_wrapper.jl index a936f8c..494a7d3 100644 --- a/src/MOI_wrapper/MOI_wrapper.jl +++ b/src/MOI_wrapper/MOI_wrapper.jl @@ -197,6 +197,8 @@ mutable struct CallbackData exception::Union{Nothing, Exception} end +Base.broadcastable(x::CallbackData) = Ref(x) + # Dummy callback function for internal use only. Responsible for updating the # objective bound, saving the mip gap, and calling the user's callback. # diff --git a/test/MOI_callbacks.jl b/test/MOI_callbacks.jl index 316cbe4..4967492 100644 --- a/test/MOI_callbacks.jl +++ b/test/MOI_callbacks.jl @@ -414,4 +414,18 @@ end @test GLPK.GLP_IHEUR in cb_calls end end + + @testset "broadcasting" begin + model, x, _ = callback_knapsack_model() + f(cb_data, x) = MOI.get(model, MOI.CallbackVariablePrimal(cb_data), x) + solutions = Vector{Float64}[] + MOI.set(model, GLPK.CallbackFunction(), (cb_data) -> begin + if GLPK.glp_ios_reason(cb_data.tree) == GLPK.GLP_IHEUR + push!(solutions, f.(cb_data, x)) + end + end) + MOI.optimize!(model) + @test length(solutions) > 0 + @test length(solutions[1]) == length(x) + end end