I am solving a MILP using Gurobi called from a C++ program. I want to retrieve the number of generated nodes and the value of the objective function of the LP relaxation.
For the nodes count, I used this class:
class NodeCounter : public GRBCallback {
public:
int nodecnt;
void callback() {
if (where == GRB_CB_MIPNODE) {
nodecnt = getDoubleInfo(GRB_CB_MIPNODE_NODCNT);
}
}
};
Then I call the the function before the model.optimize()
as follows:
// Create an instance of callback class
NodeCounter callback;
// Set the callback function
model.setCallback(&callback);
but the number of nodes I am getting is not correct!
For the LP relaxation, I called Model.relax()
to create the relaxation of the MILP and then I solve it again, my question here is: how to use the callback
to get the LP without solving the LP again?