Skip to content

Commit 337919d

Browse files
authored
Disable kHighsCallbackSimplexInterrupt in default callback (#292)
1 parent dbc50d7 commit 337919d

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/MOI_wrapper.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2212,7 +2212,14 @@ function MOI.optimize!(model::Optimizer)
22122212
# Julia introduces an interruptible ccall --- which it likely won't
22132213
# https://github.com/JuliaLang/julia/issues/2622 --- set a null
22142214
# callback.
2215-
MOI.set(model, CallbackFunction(), (args...) -> Cint(0))
2215+
cb_types = [
2216+
# See Issue 291. The SimplexInterrupt callback in HiGHS@1.11 is very
2217+
# slow.
2218+
# kHighsCallbackSimplexInterrupt,
2219+
kHighsCallbackIpmInterrupt,
2220+
kHighsCallbackMipInterrupt,
2221+
]
2222+
MOI.set(model, CallbackFunction(cb_types), (args...) -> Cint(0))
22162223
end
22172224
# if `Highs_run` implicitly uses memory or other resources owned by `model`, preserve it
22182225
GC.@preserve model begin

test/MOI_wrapper.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,34 @@ function test_callback_interrupt()
928928
return
929929
end
930930

931+
function test_callback_non_interrupt()
932+
model = HiGHS.Optimizer()
933+
MOI.set(model, MOI.RawOptimizerAttribute("presolve"), "off")
934+
x = MOI.add_variables(model, 3)
935+
MOI.add_constraint.(model, x, MOI.Integer())
936+
c = MOI.add_constraint.(model, 1.0 .* x, MOI.EqualTo.(1.0:3.0))
937+
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
938+
f = 1.0 * x[1] + x[2] + x[3]
939+
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
940+
callback_types = Cint[]
941+
function user_callback(
942+
callback_type::Cint,
943+
::Ptr{Cchar},
944+
::HiGHS.HighsCallbackDataOut,
945+
)::Cint
946+
push!(callback_types, callback_type)
947+
return 1
948+
end
949+
cb = HiGHS.CallbackFunction([HiGHS.kHighsCallbackMipSolution])
950+
MOI.set(model, cb, user_callback)
951+
MOI.optimize!(model)
952+
@test !isempty(callback_types)
953+
@test all(callback_types .== HiGHS.kHighsCallbackMipSolution)
954+
# The termination is not respected in a non-interrupt callback
955+
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL
956+
return
957+
end
958+
931959
function test_active_bound()
932960
for ((l, x, u, d), result) in [
933961
# Primal exists. Pick closest bound lower

0 commit comments

Comments
 (0)