From 3b049ec384abbfc43f1e5d7c62dd0c6735a5068a Mon Sep 17 00:00:00 2001 From: John Forrest Date: Mon, 4 Sep 2023 10:09:13 +0100 Subject: [PATCH] Trying to improve lazy constraints --- src/CbcCutGenerator.cpp | 30 +++++++++++++----------------- src/CbcModel.cpp | 13 +++++++++++-- src/CbcSolver.cpp | 9 +++++++++ 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/CbcCutGenerator.cpp b/src/CbcCutGenerator.cpp index e6e09c121..fdbbbcd75 100644 --- a/src/CbcCutGenerator.cpp +++ b/src/CbcCutGenerator.cpp @@ -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; @@ -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;i80) - //bad = true; - if (largestsetUb(rhs); + else + thisCut->setLb(rhs); } - if (bad) { + if (bad || largest > largeRatio*smallest) { + // safer to throw away cs.eraseRowCut(k); } } diff --git a/src/CbcModel.cpp b/src/CbcModel.cpp index c70342a5b..36287702b 100644 --- a/src/CbcModel.cpp +++ b/src/CbcModel.cpp @@ -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 @@ -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? @@ -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 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();