I'm coding in Julia and use the JuMP package. My IP solver stops by a fixed node limitation. I noticed that I can only get the feasible primal and dual solution if has any, however I would like to get the fractional solution who gives the best lower bound so far. Is there a way to get the fractional solution (and objective value) of a node in a b&c tree ?
1 Answer
$\begingroup$
$\endgroup$
In general, JuMP does not support querying the best fractional solution of a branch and bound tree.
However, if you are using CPLEX or Gurobi, you can write a solver-specific callback to do what you want.
Since you tagged CPLEX
, use something like this:
using JuMP, CPLEX
model = direct_model(CPLEX.Optimizer())
# This is very, very important!!! Only use callbacks in single-threaded mode.
MOI.set(model, MOI.NumberOfThreads(), 1)
@variable(model, x[1:100], Bin)
@constraint(model, rand(100)' * x <= 10)
@objective(model, Max, rand(100)' * x)
best_value, best_solution = Inf, fill(NaN, num_variables(model))
function my_callback_function(cb_data, context_id)
if callback_node_status(cb_data, model) == MOI.CALLBACK_NODE_STATUS_FRACTIONAL
valueP = Ref{Cdouble}()
CPXcallbackgetrelaxationpoint(cb_data, C_NULL, 0, -1, valueP)
if valueP[] < best_value
global best_value = valueP[]
CPLEX.load_callback_variable_primal(cb_data, context_id)
best_solution .= callback_value.(cb_data, all_variables(model))
@info "New upper bound: $best_value"
end
end
return
end
MOI.set(model, CPLEX.CallbackFunction(), my_callback_function)
optimize!(model)