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?
I want to share the solution I have found so far for the count of the number of generated nodes. I changes the previous class to
I observed that, in this case, the number of nodes returned is less than 1 the number of nodes declared in the log file. But, if the number of declared nodes in the log file is 0 or 1, the class returns 0 in the two cases. Is there any way to distinguish between these latter two cases?