Skip to main content

Usercuts in the root node with Gurobi Callback

Awaiting user input

Comments

3 comments

  • Marika Karbstein
    Gurobi Staff Gurobi Staff

    Hi Martina,

    If you are in the MIPNODE callback, you also need to use GRB_CB_MIPNODE_NODCNT. 
    GRB_CB_MIP_NODCNT is for the MIP callback and gives bogus results when used in MIPNODE. I assume you are not using Gurob 11 since with Gurobi 11 using what-arguments that do not fit the where-arguments (see Callback Codes) should cause an error message.

    The error message

    ERROR: LoadError: Gurobi Error 10011: User cuts only allowed from MIPNODE callback

    indicates that user cuts are only allowed from MIPNODE callback. So, you need to check whether you are in the MIPNODE callback when adding user cuts (you cannot skip this check).

    I hope this helps,
    Marika

    0
  • Martina Gherardi
    Gurobi-versary
    Conversationalist
    First Question

    Hi Marika, 

    Thanks for the answer. 

    Actually I'm using Gurobi 11. 

    It seemed to me that the parameter GRB_CB_MIPNODE_NODCNT  was not effective, so I replaced it with GRB_CB_MIP_NODCNT.

    With the one you suggest (GRB_CB_MIPNODE_NODCNT), with the request to add 1 cut, I obtain the same solution whether I enforce the check or not. 

    resultP = Ref{Cint}() GRBcbget(cb_data, cb_where, GRB_CB_MIPNODE_NODCNT, resultP)
    println(resultP[])
    if resultP[] != 0
    println(resultP[])  
    return
    end

    I also ask in the check to return if resultP[] != 2, but it does not adds the cut. 

    How can I add the callback in the root (or in a specific node) effectively?

    For the MIPNODE check, this means that I cannot add a user cut in the root node only, before the root relaxation is solved and I have to wait the root relaxation is solved (?)

    Thanks

    0
  • Marika Karbstein
    Gurobi Staff Gurobi Staff

    Hi Martina,

    GRB_CB_MIPNODE_NODCNT should give you the number of currently explored nodes. If you want to add the user cuts only in the root node, you should check if the node count is 0.

    I do not know how it is done with Julia but using the Gurobi Python API, a user cut is added with Model.cbCut().
    Please have a look at this documentation, it also says that the parameter PreCrush should be set to value 1 when adding your own cuts.

    The MIPNODE check ensures that currently a MIP node is explored. This callback is not only called once but several times in the root node which you can see also in your log you shared above. Your output on the value NODCNT can be seen several times in the root node.

    I do not know what you mean by adding a user cut "before the root relaxation is solved". 
    If you already know strengthening cuts without the need to solve the LP relaxation, why not add them as constraints when creating the model? 

    Best regards,
    Marika

    0

Please sign in to leave a comment.