Originally posted by: VKV7_Anulark_Naber
Now I implemented my NodeData like this:
typedef std::map<int,int> FixVarMap;
class FixVarInfo_t : public IloCplex::BranchCallbackI::NodeData {
IloInt ParentId; //parent's nodeid
FixVarInfo_t * ParentPtr; //pointer to the parent's nodedata
FixVarMap FixPair;
public:
FixVarInfo_t () {};
FixVarInfo_t (IloInt id, FixVarInfo_t *ptr) //store parent's id and ptr ot parent's nodedata
: ParentId(id), ParentPtr(ptr) {};
void FixVarInfo_t::insertVals (const int key, const int val) {
//To insert variables and fixed values to FixPair };
int FixVarInfo_t::getValue (const int key, FixVarInfo_t *ptr1) { //key is variableId //A recursive method
int index = -1;
FixVarMap::iterator it;
it = ptr1->FixPair.find(key);
if (it != ptr1->FixPair.end()) {
index = it->second;
}
else {
if (ptr1->ParentId > 0)
index = ptr1->getValue (key, ptr1->ParentPtr);
}
return index;
};
};
Now there is a problem. Till a node in the second level (say node 3), the nodedata is changed.
Here are some output from debugger of these codes in BranchCallback before branching:
FixVarInfo_t *FixVarInfo = dynamic_cast <FixVarInfo_t *> (getNodeData()); //get nodedata of the current node
FixVarInfo_t *FixVarInfo1 = new FixVarInfo_t (getNodeId()._id, FixVarInfo); //nodedata of a new node, here copy the nodedata of the current node as its parent
---At Node 0, before branching
+ FixVarInfo 0x0000000000000000 {ParentId=??? ParentPtr=??? FixPair={ size=??? } } FixVarInfo_t *
+ FixVarInfo1 0x0000000000334fc0 {ParentId=0 ParentPtr=0x0000000000000000 {ParentId=??? ParentPtr=??? FixPair={ size=??? } } ...} FixVarInfo_t *
---At Node 2, before branching
+ FixVarInfo 0x0000000000334fc0 {ParentId=0 ParentPtr=0x0000000000000000 {ParentId=??? ParentPtr=??? FixPair={ size=??? } } ...} FixVarInfo_t *
+ FixVarInfo1 0x0000000003257d40 {ParentId=2 ParentPtr=0x0000000000334fc0 {ParentId=0 ParentPtr=0x0000000000000000 {...} ...} ...} FixVarInfo_t *
So far so good.
---At Node 3, before branching
+ FixVarInfo 0x0000000003257d40 {ParentId=2 ParentPtr=0x0000000000334fc0 {ParentId=3 ParentPtr=0x0000000003257d40 {...} ...} ...} FixVarInfo_t *
+ FixVarInfo1 0x0000000000334fc0 {ParentId=3 ParentPtr=0x0000000003257d40 {ParentId=2 ParentPtr=0x0000000000334fc0 {...} ...} ...} FixVarInfo_t *
Now something went wrong. FixVarInfo is obtained from getNodeData() at Node 3, it is supposed to be the same as FixVarInfo1 at Node 2, but it is not. This creates an infinite loop in the recursive method getValue(). I cannot figure out what went wrong. I used the pointers to the nodedata of the parent, so I don't need to copy all fixed variables in order to save time and storage. Could somebody help please?
#CPLEXOptimizers#DecisionOptimization