Skip to content
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

Change heuristic callback status to UNKNOWN instead of REJECTED #495

Merged
merged 3 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 10 additions & 2 deletions src/MOI_wrapper/MOI_callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,15 @@ function MOI.submit(
objP = Ref{Cdouble}()
ret = GRBcbsolution(cb.callback_data, solution, objP)
_check_ret(model, ret)
return objP[] < GRB_INFINITY ? MOI.HEURISTIC_SOLUTION_ACCEPTED :
MOI.HEURISTIC_SOLUTION_REJECTED
if objP[] < GRB_INFINITY
return MOI.HEURISTIC_SOLUTION_ACCEPTED
end
if cb.callback_data.cb_where == GRB_CB_MIPNODE
# In a MIPNODE callback, Gurobi will process the solution immediately.
return MOI.HEURISTIC_SOLUTION_REJECTED
end
# Although not accepted at present, Gurobi may cache the solution and use it
# later in the optimization process.
return MOI.HEURISTIC_SOLUTION_UNKNOWN
end
MOI.supports(::Optimizer, ::MOI.HeuristicSolution{CallbackData}) = true
7 changes: 7 additions & 0 deletions test/MOI/MOI_callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,18 @@ function test_CallbackFunction_callback_HeuristicSolution()
model, x, item_weights = callback_knapsack_model()
solution_accepted = false
solution_rejected = false
solution_unknown = false
cb_calls = Int32[]
MOI.set(
model,
Gurobi.CallbackFunction(),
(cb_data, cb_where) -> begin
push!(cb_calls, cb_where)
if cb_where == Gurobi.GRB_CB_MIP
attr = MOI.HeuristicSolution(cb_data)
status = MOI.submit(model, attr, x, fill(2.0, length(x)))
solution_unknown |= (status == MOI.HEURISTIC_SOLUTION_UNKNOWN)
odow marked this conversation as resolved.
Show resolved Hide resolved
end
if cb_where != Gurobi.GRB_CB_MIPNODE
return
end
Expand Down Expand Up @@ -539,6 +545,7 @@ function test_CallbackFunction_callback_HeuristicSolution()
MOI.optimize!(model)
@test solution_accepted
@test solution_rejected
@test solution_unknown
@test Gurobi.GRB_CB_MIPNODE in cb_calls
end

Expand Down