From 51159cfc51caeb9bf75d5b3adf6bdeb0ef3c277f Mon Sep 17 00:00:00 2001 From: John Forrest Date: Tue, 29 Aug 2023 09:24:42 +0100 Subject: [PATCH] modifications for lazy constraints --- src/CbcModel.cpp | 41 +++++++++++++++++++++++++---------------- src/CbcSolver.cpp | 8 +++++--- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/CbcModel.cpp b/src/CbcModel.cpp index 58bf82350..4fad21975 100644 --- a/src/CbcModel.cpp +++ b/src/CbcModel.cpp @@ -1253,10 +1253,18 @@ void CbcModel::analyzeObjective() value *= scaleFactor; // trueIncrement=CoinMax(cutoff,value);; if (value * 0.999 > cutoff) { - messageHandler()->message(CBC_INTEGERINCREMENT, messages()) + if ((moreSpecialOptions2_ & 65536) == 0) { + messageHandler()->message(CBC_INTEGERINCREMENT, messages()) << value << CoinMessageEol; - setDblParam(CbcModel::CbcCutoffIncrement, - CoinMax(value * 0.999, value - 1.0e-4)); + setDblParam(CbcModel::CbcCutoffIncrement, + CoinMax(value * 0.999, value - 1.0e-4)); + } else { + // lazy constraints - can't be certain + char temp[100]; + sprintf(temp,"May be able to increase cutoff increment to %g - but we have lazy constraints",CoinMax(value*0.999,value-1.0e-4)); + messageHandler()->message(CBC_GENERAL, messages()) + << temp << CoinMessageEol; + } } } } @@ -2375,9 +2383,10 @@ void CbcModel::branchAndBound(int doStatistics) #endif bool feasible; numberSolves_ = 0; - { - // check + if (!parentModel_) { int numberOdd = 0; + moreSpecialOptions2_ &= ~65536; // say no lazy constraints + // check int numberSOS = 0; for (int i = 0; i < numberObjects_; i++) { CbcSimpleInteger *obj = dynamic_cast(object_[i]); @@ -2395,18 +2404,18 @@ void CbcModel::branchAndBound(int doStatistics) #endif specialOptions_ &= ~(512 | 32768); } - moreSpecialOptions2_ &= ~65536; // say no lazy constraints - if (!numberOdd && !parentModel_) { - // see if lazy constraints - bool needCuts = false; - for (int i = 0; i < numberCutGenerators_; i++) { - bool generate = generator_[i]->atSolution(); - if (generate) { - needCuts = true; - } + // see if lazy constraints + bool needCuts = false; + for (int i = 0; i < numberCutGenerators_; i++) { + bool generate = generator_[i]->atSolution(); + if (generate) { + needCuts = true; } - if (needCuts) - moreSpecialOptions2_ |= 65536; // lazy constraints + } + if (needCuts) { + moreSpecialOptions2_ |= 65536; // lazy constraints + // switch off nauty + moreSpecialOptions2_ &= ~(128|256); } } // If NLP then we assume already solved outside branchAndbound diff --git a/src/CbcSolver.cpp b/src/CbcSolver.cpp index f643922a2..dd5ebee11 100644 --- a/src/CbcSolver.cpp +++ b/src/CbcSolver.cpp @@ -2310,7 +2310,7 @@ int CbcMain1(std::deque inputQueue, CbcModel &model, buffer.str(""); buffer << "switching on global root cuts for gomory and " << "knapsack" << std::endl; - buffer << "using OSL factorization" << std::endl; + //buffer << "using OSL factorization" << std::endl; buffer << "extra options - -rens on -extra4 " << extra4 << " -passc 1000!" << std::endl; printGeneralMessage(model_, buffer.str()); @@ -2321,7 +2321,7 @@ int CbcMain1(std::deque inputQueue, CbcModel &model, parameters[CbcParam::KNAPSACKCUTS]->setVal("onGlobal"); knapsackMode = CbcParameters::CGOnGlobal; clpParameters[ClpParam::FACTORIZATION]->setVal("osl"); - lpSolver->factorization()->forceOtherFactorization(3); + //lpSolver->factorization()->forceOtherFactorization(3); parameters[CbcParam::MAXHOTITS]->setVal(100); parameters[CbcParam::CUTPASS]->setVal(1000); cutPass = 1000; @@ -6339,9 +6339,11 @@ int CbcMain1(std::deque inputQueue, CbcModel &model, double increment = babModel_->getCutoffIncrement(); ; int *changed = NULL; - if (!miplib && increment == normalIncrement) +#ifdef UNSAFE_FOR_LAZY_CUTS + if (!miplib && increment == normalIncrement) changed = analyze(osiclp, numberChanged, increment, false, generalMessageHandler, parameters.noPrinting()); +#endif #elif CBC_OTHER_SOLVER == 1 double increment = babModel_->getCutoffIncrement(); ;