Reputation: 103
When I use UserCutCallback and retrieve some function like getuppseudocost or slack it generates the outputs twice. For example I have 50 variables it shows pseudocosts for all 50 variables then under the 50th variable it shows the first variable to the 50th variable again. What is wrong in my code?
ILOUSERCUTCALLBACK1(Myuppesodo, IloArray<IloNumVarArray>, vars) {
for (int i = 0; i < nbworkers; i++) {
for (int j = 0; j < nbmachines; j++)
{
auto temp = getUpPseudoCost(vars[i][j]);
cout << "getUpPseudoCost(" << vars[i][j] << ")= " <<
temp << endl;
}
}
}
Upvotes: 1
Views: 52
Reputation: 5940
The user cut callback may be invoked multiple times per node. This is expected since cuts are separated in a loop. You can easily detect whether the callback was already invoked for the current node by following this paradigm: struct Marker : public IloCplex::MIPCallbackI::NodeData {};
ILOUSERCUTCALLBACK0(SolveCallback) {
if ( !getNodeData() ) {
// Invoked first time at current node
setNodeData(new Marker());
}
else {
// Not the first time at current node
}
}
Upvotes: 1