New Gurobi.jl syntax trouble

Hi all

I’ve got some issues in adapting to the new Gurobi.jl syntax.
For example, this is a callback that I made in the old syntax:

function cb(cb_data, cb_where)

    if cb_where == CB_MIPNODE
        #first node
        if cbget_mipnode_nodcnt(cb_data, cb_where) == 0
            #Pegando a relaxação linear de todas as variáveis
            linear_rel = cbget_mipnode_rel(cb_data, cb_where)

            tam = length(linear_rel)-(n+1)
            aux = linear_rel[1:tam]

            #Graph
            flow_graph = DiGraph(n+1)
            capacity_matrix = zeros(n+1, n+1)

            for j in 1:n
                for i in 1:n+1
                    if aux[(j-1)*(n+1) + i] > g_params.EPS
                        add_edge!(flow_graph, i, j)
                        capacity_matrix[i,j] = aux[(j-1)*(n+1) + i]
                    end
                end
            end
end
end

I would like to transform that one to the new syntax. For the “nodcnt” I managed to adapt using

resultP = Ref {Cint} ()
    GRBcbget (cb_data, cb_where, GRB_CB_MIPNODE_NODCNT, resultP)

However, I’m having issues to query the linear relaxation values :frowning:
Error like these is happening:

signal (11): Segmentation fault
in expression starting at /PATH/TO/EXAMPLE.jl 88
cb at /home/afazevedo/Documentos/dissertacao/src/bc.jl:47
unknown function (ip: 0x7fffffffffffffff)
Allocations: 176939438 (Pool: 176893431; Big: 46007); GC: 148

I imagine it has to do with allocation and pointers, but I don’t know how to solve it.
Can anyone help me? :exploding_head:

Thanks in advance!

A couple of points:

  1. GRB_CB_MIPNODE_NODCNT is a Cdouble: https://www.gurobi.com/documentation/9.0/refman/cb_codes.html

    resultP = Ref {Cdouble}()
    GRBcbget(cb_data, cb_where, GRB_CB_MIPNODE_NODCNT, resultP)
    
  2. For the primal solution, follow the example: https://github.com/jump-dev/Gurobi.jl#callbacks.

    Or, if you just want the vector, you need something like

    n = # number of variables
    resultP = Vector{Cdouble}(undef, n)
    GRBcbget(cb_data, cb_where, GRB_CB_MIPNODE_REL, resultP)
    
1 Like

Thanks a lot!! :heart: