Skip to content

Commit

Permalink
Trying to improve lazy constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhforrest committed Sep 4, 2023
1 parent 077c6da commit 3b049ec
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
30 changes: 13 additions & 17 deletions src/CbcCutGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ bool CbcCutGenerator::generateCuts(OsiCuts &cs, int fullScan, OsiSolverInterface
const double *colLower = solver->getColLower();
double smallValue1; // = 1.0e-4;
double smallValue2; // = 1.0e-5;
double largeRatio = 1.0e8;
double largeRatio = 1.0e9;
if (!depth) {
smallValue1 = 1.0e-5;
smallValue2 = 1.0e-5;
Expand Down Expand Up @@ -908,6 +908,7 @@ bool CbcCutGenerator::generateCuts(OsiCuts &cs, int fullScan, OsiSolverInterface
double smallest=1.0e30;
bool bad=false;
double sum = 0.0;
double origRhs = rhs;
int number = 0;
for (int i=0;i<n;i++) {
double value=elements[i];
Expand Down Expand Up @@ -966,25 +967,20 @@ bool CbcCutGenerator::generateCuts(OsiCuts &cs, int fullScan, OsiSolverInterface
}
} else {
int iColumn = indices[i];
if (colUpper[iColumn]!=colLower[iColumn]) {
largest=CoinMax(largest,value);
smallest=CoinMin(smallest,value);
indices[number]=indices[i];
elements[number++]=elements[i];
} else {
// fixed so subtract out
rhs -= elements[i]*colLower[iColumn];
}
largest=CoinMax(largest,value);
smallest=CoinMin(smallest,value);
indices[number]=indices[i];
elements[number++]=elements[i];
}
}
//if (number>80)
//bad = true;
if (largest<largeRatio*smallest&&!bad) {
if (number<n)
rpv.truncate(number);
} else if (!bad) {
if (rhs!=origRhs) {
if (upper)
thisCut->setUb(rhs);
else
thisCut->setLb(rhs);
}
if (bad) {
if (bad || largest > largeRatio*smallest) {
// safer to throw away
cs.eraseRowCut(k);
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/CbcModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16397,8 +16397,7 @@ int CbcModel::chooseBranch(CbcNode *&newNode, int numberPassesLeft,
}
}
if (solverCharacteristics_ &&
solverCharacteristics_
->solutionAddsCuts() && // we are in some OA based bab
solverCharacteristics_->solverType()>2 && // we are in some OA based bab
feasible &&
(newNode->numberUnsatisfied() ==
0) // solution has become integer feasible during strong branching
Expand All @@ -16422,7 +16421,12 @@ int CbcModel::chooseBranch(CbcNode *&newNode, int numberPassesLeft,
resolve(solver_);
double objval = solver_->getObjValue();
lastHeuristic_ = NULL;
// switch off odd stuff if no cuts were found
int solverType = solverCharacteristics_->solverType();
if (feasCuts.sizeCuts()==0 && solverCharacteristics_->solverType()>2)
solverCharacteristics_->setSolverType(0);
setBestSolution(CBC_SOLUTION, objval, solver_->getColSolution());
solverCharacteristics_->setSolverType(solverType);
int easy = 2;
if (!solverCharacteristics_
->mipFeasible()) // did we prove that the node could be pruned?
Expand Down Expand Up @@ -18503,6 +18507,11 @@ int CbcModel::doOneNode(CbcModel *baseModel, CbcNode *&node,
// need dummy branch
newNode->setBranchingObject(new CbcDummyBranchingObject(this));
newNode->nodeInfo()->initializeInfo(1);
// add in cuts
for (int i=0;i<numberRowCutsAfter;i++) {
theseCuts.rowCut(i).setEffectiveness(COIN_DBL_MAX);
globalCuts_.addCutIfNotDuplicate(theseCuts.rowCut(i));
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/CbcSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,15 @@ int CbcMain1(std::deque<std::string> inputQueue, CbcModel &model,
std::ostringstream buffer;
std::string field, message, fileName;
FILE *fp;
#ifdef DEBUG_CBC_PYTHON
// Probably being stupid but finding it difficult to debug from python
static int startedPython=0;
if (!startedPython) {
printf("debug python:");
getchar();
startedPython=1;
}
#endif

double totalTime = parameters.getTotalTime();
bool useSignalHandler = parameters.useSignalHandler();
Expand Down

0 comments on commit 3b049ec

Please sign in to comment.