2
$\begingroup$

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 ?

$\endgroup$

1 Answer 1

3
$\begingroup$

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)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.