| 1 |
|
| 2 |
#include "BonLinearCutsGenerator.hpp" |
| 3 |
#include "BonTMINLP2Quad.hpp" |
| 4 |
#include "OsiClpSolverInterface.hpp" |
| 5 |
|
| 6 |
//MILP cuts |
| 7 |
#include "CglGomory.hpp" |
| 8 |
#include "CglProbing.hpp" |
| 9 |
#include "CglKnapsackCover.hpp" |
| 10 |
#include "CglOddHole.hpp" |
| 11 |
#include "CglClique.hpp" |
| 12 |
#include "CglFlowCover.hpp" |
| 13 |
#include "CglMixedIntegerRounding2.hpp" |
| 14 |
#include "CglTwomir.hpp" |
| 15 |
#include "CglPreProcess.hpp" |
| 16 |
#include "CglLandP.hpp" |
| 17 |
#include "CglRedSplit.hpp" |
| 18 |
|
| 19 |
namespace Bonmin { |
| 20 |
|
| 21 |
void LinearCutsGenerator::initialize(BabSetupBase & s){ |
| 22 |
assert(dynamic_cast<TMINLP2TNLPQuadCuts *> (s.nonlinearSolver()->problem())); |
| 23 |
int freq; |
| 24 |
s.options()->GetIntegerValue("Gomory_cuts", freq,"bonmin."); |
| 25 |
if (freq) { |
| 26 |
Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod; |
| 27 |
cg->frequency = freq; |
| 28 |
CglGomory * gom = new CglGomory; |
| 29 |
cg->cgl = gom; |
| 30 |
gom->setLimitAtRoot(512); |
| 31 |
gom->setLimit(50); |
| 32 |
cg->id = "Mixed Integer Gomory"; |
| 33 |
methods_.push_back(cg); |
| 34 |
} |
| 35 |
|
| 36 |
s.options()->GetIntegerValue("mir_cuts",freq,"bonmin."); |
| 37 |
if (freq) { |
| 38 |
Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod; |
| 39 |
cg->frequency = freq; |
| 40 |
CglMixedIntegerRounding2 * mir = new CglMixedIntegerRounding2; |
| 41 |
cg->cgl = mir; |
| 42 |
cg->id = "Mixed Integer Rounding"; |
| 43 |
methods_.push_back(cg); |
| 44 |
|
| 45 |
|
| 46 |
} |
| 47 |
s.options()->GetIntegerValue("2mir_cuts",freq,"bonmin."); |
| 48 |
if (freq) { |
| 49 |
Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod; |
| 50 |
cg->frequency = freq; |
| 51 |
CglTwomir * mir2 = new CglTwomir; |
| 52 |
cg->cgl = mir2; |
| 53 |
cg->id = "2-MIR"; |
| 54 |
methods_.push_back(cg); |
| 55 |
} |
| 56 |
s.options()->GetIntegerValue("cover_cuts",freq,"bonmin."); |
| 57 |
if (freq) { |
| 58 |
Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod; |
| 59 |
cg->frequency = freq; |
| 60 |
CglKnapsackCover * cover = new CglKnapsackCover; |
| 61 |
cg->cgl = cover; |
| 62 |
cg->id = "Cover"; |
| 63 |
methods_.push_back(cg); |
| 64 |
} |
| 65 |
|
| 66 |
s.options()->GetIntegerValue("clique_cuts",freq,"bonmin."); |
| 67 |
if (freq) { |
| 68 |
Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod; |
| 69 |
cg->frequency = freq; |
| 70 |
CglClique * clique = new CglClique; |
| 71 |
clique->setStarCliqueReport(false); |
| 72 |
clique->setRowCliqueReport(false); |
| 73 |
clique->setMinViolation(0.1); |
| 74 |
|
| 75 |
cg->cgl = clique; |
| 76 |
cg->id = "Clique"; |
| 77 |
methods_.push_back(cg); |
| 78 |
} |
| 79 |
s.options()->GetIntegerValue("flow_cover_cuts",freq,"bonmin."); |
| 80 |
if (freq) { |
| 81 |
Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod; |
| 82 |
cg->frequency = freq; |
| 83 |
CglFlowCover * flow = new CglFlowCover; |
| 84 |
cg->cgl = flow; |
| 85 |
cg->id = "Flow Covers"; |
| 86 |
methods_.push_back(cg); |
| 87 |
} |
| 88 |
s.options()->GetIntegerValue("lift_and_project_cuts",freq,"bonmin."); |
| 89 |
if (freq) { |
| 90 |
Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod; |
| 91 |
cg->frequency = freq; |
| 92 |
CglLandP * landp = new CglLandP; |
| 93 |
cg->cgl = landp; |
| 94 |
cg->id = "Lift-and-Project"; |
| 95 |
methods_.push_back(cg); |
| 96 |
} |
| 97 |
s.options()->GetIntegerValue("reduce_and_split_cuts",freq,"bonmin."); |
| 98 |
if (freq) { |
| 99 |
Coin::SmartPtr<CuttingMethod> cg = new CuttingMethod; |
| 100 |
cg->frequency = freq; |
| 101 |
CglRedSplit * rands = new CglRedSplit; |
| 102 |
cg->cgl = rands; |
| 103 |
cg->id = "Reduce-and-Split"; |
| 104 |
methods_.push_back(cg); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
void |
| 109 |
LinearCutsGenerator::generateCuts(const OsiSolverInterface &solver, OsiCuts &cs, |
| 110 |
const CglTreeInfo info) { |
| 111 |
|
| 112 |
//const OsiTMINLPInterface * tmp = dynamic_cast<const OsiTMINLPInterface *>(&solver); |
| 113 |
OsiTMINLPInterface * nlp = dynamic_cast<OsiTMINLPInterface *>(solver.clone());//const_cast<OsiTMINLPInterface *>(tmp); |
| 114 |
assert(nlp); |
| 115 |
OuterApprox oa; |
| 116 |
//si.writeMps("toto"); |
| 117 |
int numberRows = nlp->getNumRows(); |
| 118 |
for(int i = 0 ; i < 5 ; i++){ |
| 119 |
nlp->resolve(); |
| 120 |
OsiClpSolverInterface si; |
| 121 |
oa(*nlp, &si, solver.getColSolution(), true); |
| 122 |
si.resolve(); |
| 123 |
OsiCuts cuts; |
| 124 |
for(std::list<Coin::SmartPtr<CuttingMethod> >::const_iterator i = methods_.begin() ; |
| 125 |
i != methods_.end() ; i++){ |
| 126 |
(*i)->cgl->generateCuts(si, cuts, info); |
| 127 |
} |
| 128 |
std::vector<OsiRowCut *> mycuts(cuts.sizeRowCuts()); |
| 129 |
for(int i = 0 ; i < cuts.sizeRowCuts() ; i++){ |
| 130 |
mycuts[i] = cuts.rowCutPtr(i); |
| 131 |
cs.insert(*mycuts[i]); |
| 132 |
} |
| 133 |
nlp->applyRowCuts((int)mycuts.size(), const_cast<const OsiRowCut **> (&mycuts[0])); |
| 134 |
} |
| 135 |
|
| 136 |
// Take off slack cuts |
| 137 |
std::vector<int> kept; |
| 138 |
int numberRowsNow = nlp->getNumRows(); |
| 139 |
int * del = new int [numberRowsNow-numberRows]; |
| 140 |
nlp->resolve(); |
| 141 |
|
| 142 |
const double * activity = nlp->getRowActivity(); |
| 143 |
const double * lb = nlp->getRowLower(); |
| 144 |
const double * ub = nlp->getRowUpper(); |
| 145 |
CoinRelFltEq eq(1e-06); |
| 146 |
//int nDelete=0; |
| 147 |
for (int i=numberRowsNow -1;i>=numberRows;i--) { |
| 148 |
if ( !(eq(activity[i], lb[i]) || eq(activity[i], ub[i])) ) |
| 149 |
cs.eraseRowCut(i - numberRows); |
| 150 |
} |
| 151 |
delete [] del; |
| 152 |
delete nlp; |
| 153 |
} |
| 154 |
}/* Ends Bonmin namespace.*/ |