Originally posted by: anahana
Thanks for the detailed reply. I found the copyNodes function in the ILONODECALLBACK and ILOBRANCHCALLBACK macros. It's not a function in my code that I wrote. I have no idea what it does or where it came from.
I implemented something similar to your suggestion actually, but got stuck on the following issue:
I call a ILONODECALLBACK macro from within a ILOBRANCHCALLBACK to select the next node for processing. See code segment:
ILOBRANCHCALLBACK1(dataCollector1, IloNumVarArray, vars)
{
IloInt i, j, k = 0;
IloInt n0 = 10;
IloNum upBranchImp = IloInfinity;
IloNum downBranchImp = IloInfinity;
IntegerFeasibilityArray feas(getEnv());
//determine the baseSet
getFeasibilities(feas, vars);
j = 0;
for(i = 0; i < feas.getSize(); i++)
if(feas[i] == 1)
j++;
//define arrays for data collection
IloNumVarArray baseSet(getEnv(), j);
IloArray<IloNumArray> baseSetData(getEnv(), j);
IloArray<IloIntArray> baseSetInfoPool(getEnv(), j);
for(i = 0; i < vars.getSize(); i++)
baseSetData[i] = IloNumArray(getEnv(), n0);
for(i = 0; i < vars.getSize(); i++)
baseSetInfoPool[i] = IloIntArray(getEnv(), 2*n0); //no. of columns to be determined later
baseSet.clear();
baseSetData.clear();
baseSetInfoPool.clear();
//copy vars. to baseSet
for(i = 0; i < feas.getSize(); i++)
if(feas[i] == 1)
baseSet.add(vars[i]);
//obtain two readings for each var. in baseSet from node0
for(i = 0; i < baseSet.getSize(); i++)
{
cout << getNodeId()._id << endl;
NodeData *data = getNodeData();
NodeId upNode;
NodeId downNode;
upNode = makeBranch(baseSet[i], IloInfinity, IloCplex::BranchUp, getObjValue(), data);
downNode = makeBranch(baseSet[i], IloInfinity, IloCplex::BranchDown, getObjValue(), data);
nodeSelect(getEnv(), upNode, upBranchImp, downBranchImp);
nodeSelect(getEnv(), downNode, upBranchImp, downBranchImp);
delete data;
}
feas.end();
baseSet.end();
baseSetData.end();
baseSetInfoPool.end();
}
ILONODECALLBACK3(nodeSelect, IloCplex::MIPCallbackI::NodeId, nextNode, IloNum, upBranchImp, IloNum, downBranchImp)
{
cout << nextNode._id << endl;
selectNode(nextNode);
}
Once the nextNode is selected, I want to solve it and return the solution (or at least the solution quality) to ILOBRANCHCALLBACK1 so I can store it somewhere and process the next node. Is this possible from ILONODECALLBACK3? If not, and I leave the code as is, I suspect cplex.solve() take control again, call ILOBRANCHCALLBACK1 and ILONODECALLBACK3 again at whatever node, and... I don't even imagine what will happen next.
If my implementation is totally wrong, please let me know.
Regards,
#CPLEXOptimizers#DecisionOptimization