00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if defined(_MSC_VER)
00012
00013 # pragma warning(disable:4786)
00014 #endif
00015 #include <cassert>
00016 #include <cmath>
00017 #include <cfloat>
00018
00019 #include "OsiSolverInterface.hpp"
00020 #include "CbcModel.hpp"
00021 #include "BonCbcNlpStrategy.hpp"
00022 #include "BonCbcNode.hpp"
00023
00024 #include "BonOsiTMINLPInterface.hpp"
00025 namespace Bonmin
00026 {
00027
00028 CbcNlpStrategy::CbcNlpStrategy(int maxFailures,
00029 int maxInfeasibles,
00030 int pretendFailIsInfeasible)
00031 :
00032 hasFailed_(false),
00033 maxFailure_(maxFailures),
00034 maxInfeasible_(maxInfeasibles),
00035 pretendFailIsInfeasible_(pretendFailIsInfeasible)
00036 {
00037 setPreProcessState(0);
00038 }
00039
00040
00041
00042 CbcNlpStrategy::~CbcNlpStrategy ()
00043 {}
00044
00045
00046 CbcStrategy *
00047 CbcNlpStrategy::clone() const
00048 {
00049 return new CbcNlpStrategy(*this);
00050 }
00051
00052
00053 CbcNlpStrategy::CbcNlpStrategy(const CbcNlpStrategy & rhs)
00054 :
00055 hasFailed_(false),
00056 maxFailure_(rhs.maxFailure_),
00057 maxInfeasible_(rhs.maxInfeasible_),
00058 pretendFailIsInfeasible_(rhs.pretendFailIsInfeasible_)
00059 {}
00060
00061 CbcNodeInfo *
00062 CbcNlpStrategy::fullNodeInfo(CbcModel * model,int numberRowsAtContinuous) const
00063 {
00064 return new CbcFullNodeInfo(model,numberRowsAtContinuous);
00065 }
00066
00067 CbcNodeInfo *
00068 CbcNlpStrategy::partialNodeInfo(CbcModel * model, CbcNodeInfo * parent, CbcNode * owner,
00069 int numberChangedBounds,const int * variables,
00070 const double * boundChanges,
00071 const CoinWarmStartDiff *basisDiff) const
00072 {
00073 return new BonCbcPartialNodeInfo(model,parent, owner, numberChangedBounds, variables,
00074 boundChanges,basisDiff);
00075 }
00076
00077
00078
00079
00080
00081
00082 int
00083 CbcNlpStrategy::status(CbcModel * model, CbcNodeInfo * parent,int whereFrom)
00084 {
00085
00086 OsiSolverInterface * solver = model->solver();
00087 int feasible = 1;
00088 bool solved = true;
00089 int returnStatus = -1;
00090 BonCbcPartialNodeInfo * bmNodeInfo = dynamic_cast<BonCbcPartialNodeInfo *>(parent);
00091 if (!bmNodeInfo) return -1;
00092
00093 int seqOfInfeasiblesSize = bmNodeInfo->getSequenceOfInfeasiblesSize();
00094 int seqOfUnsolvedSize = bmNodeInfo->getSequenceOfUnsolvedSize();
00095
00096
00097 if (solver->isAbandoned()) {
00098 solved = false;
00099 seqOfUnsolvedSize++;
00100 ;
00101 }
00102 else if (solver->isProvenPrimalInfeasible()) {
00103 feasible = 0;
00104 seqOfInfeasiblesSize++;
00105 }
00106
00107 if ((seqOfUnsolvedSize==0) || (maxFailure_ == 0) &&
00108 (maxInfeasible_== 0) || (seqOfInfeasiblesSize==0))
00109
00110 if (feasible && seqOfInfeasiblesSize > 1) {
00111 (*model->messageHandler())<<"Feasible node while father was infeasible."
00112 <<CoinMessageEol;
00113 }
00114
00115 if (solved && seqOfUnsolvedSize > 1) {
00116 (*model->messageHandler())<<"Solved node while father was unsolved."
00117 <<CoinMessageEol;
00118 }
00119
00120 if (seqOfInfeasiblesSize < maxInfeasible_ &&
00121 solved && !feasible) {
00122 (*model->messageHandler())<<"Branching on infeasible node, sequence of infeasibles size "
00123 <<seqOfInfeasiblesSize<<CoinMessageEol;
00124
00125 OsiTMINLPInterface * ipopt = dynamic_cast<OsiTMINLPInterface *>(solver);
00126 ipopt->forceBranchable();
00127
00128 returnStatus = 0;
00129
00130 }
00131
00132 if (!solved && parent != NULL &&
00133 seqOfUnsolvedSize <= maxFailure_) {
00134 (*model->messageHandler())<<"Branching on unsolved node, sequence of unsolved size "<<seqOfUnsolvedSize<<CoinMessageEol;
00135
00136 OsiTMINLPInterface * osiMinlp = dynamic_cast<OsiTMINLPInterface *>(solver);
00137 osiMinlp->forceBranchable();
00138 returnStatus = 0;
00139 }
00140
00141 if (solver->isAbandoned() && parent != NULL &&
00142 seqOfUnsolvedSize > maxFailure_) {
00143 hasFailed_ = true;
00144 OsiTMINLPInterface * osiMinlp =
00145 dynamic_cast<OsiTMINLPInterface *>(solver);
00146 if (pretendFailIsInfeasible_) {
00147
00148 osiMinlp->forceInfeasible();
00149 returnStatus = 2;
00150 }
00151 else {
00152 std::string probName;
00153 osiMinlp->getStrParam(OsiProbName,probName);
00154 throw osiMinlp->newUnsolvedError(0, osiMinlp->problem(), probName);
00155 }
00156 }
00157 return returnStatus;
00158 }
00159
00160 void
00161 CbcNlpStrategy::setupCutGenerators(CbcModel &model)
00162 {}
00163
00164 void
00165 CbcNlpStrategy::setupHeuristics(CbcModel &model)
00166 {}
00167
00168 void
00169 CbcNlpStrategy::setupPrinting(CbcModel &model, int toto)
00170 {}
00171
00172 void
00173 CbcNlpStrategy::setupOther(CbcModel &model)
00174 {}
00175 }