Error using CPXcallbackgetrelaxationpoint at CPLEX.jl solver specifc callback

status = CPXcallbackgetrelaxationpoint(cb_data, x, 0, 1, obj_p)
@info “Relaxation point: $(x)”

There are a few problems here:

  • x is not defined yet. You should typically write your callback function after creating the model, etc
  • x gets defined later as a Matrix{VariableRef}, whereas CPLEX needs to be passed a Vector{Float64}.
  • x[] is the syntax for Ref variables, not vectors or matrices.

You could instead pass something like this (although I didn’t try it, so there might be a mistake):

    if (lpstat[] == CPX_STAT_OPTIMAL) || (lpstat[] == CPX_STAT_OPTIMAL_INFEAS)
        # Relaxation is optimal. Find the integer variable that is most fractional.
        println("Branching")
        obj_p = Ref{Cdouble}()
        x_val = Vector{Cdouble}(undef, N^2)
        status = CPXcallbackgetrelaxationpoint(cb_data, x_val, 0, N^2 - 1, obj_p)
        if Bool(status) 
            @error "CPXcallbackgetrelaxationpoint failed."
        else 
            @info "Relaxation point: $(x_val)"
            @info "Relaxation objective: $(obj_p[])"
        end
    end