fork download
  1. ILOBRANCHCALLBACK0(stopBranching)
  2. {
  3. try {
  4. if (newBestSolution)
  5. if (this->getObjValue() < slnBest)
  6. {
  7. //cout << "obj nhanh nay:" << this->getObjValue() << " qua be so voi optimal hien tai = " << slnBest + 1<< " nen stop" << endl;
  8. nbReject++;
  9. this->prune();
  10. return;
  11. }
  12. else
  13. return;
  14.  
  15.  
  16. if (this->getBestObjValue() < slnBest + 1 && this->getObjValue() < slnBest + 1)
  17. {
  18. cout << "da tim thay optimal solution" << endl;;
  19. this->abort();
  20. return;
  21. }
  22. if (this->getObjValue() < slnBest + 1)
  23. {
  24. //cout << "obj nhanh nay:" << this->getObjValue() << " qua be so voi optimal hien tai = " << slnBest + 1<< " nen stop" << endl;
  25. nbReject++;
  26. this->prune();
  27. return;
  28. }
  29.  
  30.  
  31. if (earlyStopping == false)
  32. return;
  33.  
  34. IloNumArray lbYmaster(this->getEnv());
  35. IloNumArray ubYmaster(this->getEnv());
  36.  
  37. this->getLBs(lbYmaster, yMaster);
  38. this->getUBs(ubYmaster, yMaster);
  39.  
  40. IloNumArray y_valBC(this->getEnv(), ttdp.N);
  41. vector<int> fixedNodes;
  42.  
  43. long long h = 0;
  44. int unfixed = 0;
  45. int score = 0;
  46.  
  47. int lb[11] = { 0 };
  48. for (int i = 0;i < ttdp.nbCat;i++) lb[i] = 0;
  49.  
  50. int pos = 0;
  51. for (int i = 0;i < ttdp.N;i++)
  52. if (lbYmaster[i] == 1 && ubYmaster[i] == 1)
  53. {
  54. y_valBC[i] = 1;
  55.  
  56. fixedNodes.push_back(i);
  57. //cout << i << " ";
  58. for (int j = 0;j < ttdp.category[i].size();j++)
  59. lb[ttdp.category[i][j]]++;
  60.  
  61. score += ttdp.score[i];
  62. }
  63. else
  64. {
  65. if (lbYmaster[i] - ubYmaster[i])
  66. unfixed++;
  67.  
  68. y_valBC[i] = 0;
  69.  
  70. if (ownBranching && lbYmaster[i] - ubYmaster[i])
  71. if (ttdp.score[i] > ttdp.score[pos])
  72. pos = i;
  73.  
  74.  
  75. }
  76. //cout << endl;
  77.  
  78.  
  79. if (fixedNodes.size() == 2)
  80. return;
  81.  
  82. if (unfixed == 0)
  83. return;
  84.  
  85. if (score <= slnBest)
  86. if (!ownBranching)
  87. {
  88. return;
  89. }
  90. else //issues happen here
  91. {
  92. this->makeBranch(yFull[pos], 1, IloCplex::BranchDown, this->getObjValue());
  93. this->makeBranch(yFull[pos], 0, IloCplex::BranchUp, this->getObjValue());
  94. return;
  95. }
  96.  
  97.  
  98.  
  99. for (int i = 0;i < ttdp.nbCat;i++)
  100. if (lb[i] < ttdp.lbCategory[i])
  101. return;
  102.  
  103. //int ranVal = rand() % (int)( slnBest +1);
  104.  
  105. //if (ranVal > score)
  106. // return;
  107.  
  108.  
  109. updateSlaveModel(y_valBC);
  110. int startTime = this->getCplexTime();
  111. cplexSlave.solve();
  112. int endTime = this->getCplexTime();
  113.  
  114. if (cplexSlave.getStatus() == IloAlgorithm::Infeasible)
  115. {
  116. cout << "we stop branching here because of infeasible POIs: ";
  117. for (int i = 0;i < fixedNodes.size();i++)
  118. cout << fixedNodes[i] << " ";
  119. cout << "at the node " << this->getNodeId() << " with " << unfixed << " unfixed variables and " << endTime - startTime << endl;
  120.  
  121. nbReject++;
  122.  
  123. inBranching = true;
  124.  
  125. prepareCut(y_valBC);
  126.  
  127. y_valBC.end();lbYmaster.end();ubYmaster.end();
  128.  
  129.  
  130. this->prune();
  131.  
  132. return;
  133. }
  134. else
  135. {
  136. cout << "New solution found while branching: ";
  137. for (int i = 0;i < ttdp.N;i++)
  138. if (lbYmaster[i] == 1 && ubYmaster[i] == 1)
  139. {
  140. cout << i << " ";
  141. }
  142. cout << " with a value of " << score << endl;
  143.  
  144. slnBest = score;
  145. LocalBranching(y_valBC);
  146. y_valBC.end();lbYmaster.end();ubYmaster.end();
  147.  
  148. if (ownBranching) //issues happen here
  149. {
  150. this->makeBranch(yFull[pos], 1, IloCplex::BranchDown, this->getObjValue());
  151. this->makeBranch(yFull[pos], 0, IloCplex::BranchUp, this->getObjValue());
  152. return;
  153. }
  154.  
  155. }
  156. }
  157. catch (IloException& ex) {
  158. cerr << "Error: " << ex << endl;
  159. }
  160.  
  161.  
  162.  
  163. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:19: error: expected constructor, destructor, or type conversion before ‘(’ token
 ILOBRANCHCALLBACK0(stopBranching)
                   ^
stdout
Standard output is empty