/home/coin/SVN-release/OS-2.2.0/Bonmin/src/CbcBonmin/BonCbcNlpStrategy.cpp

Go to the documentation of this file.
00001 // (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // John J. Forrest, International Business Machines Corporation
00007 // P. Bonami, Carnegie Mellon University,
00008 //
00009 // Date : 03/15/2006
00010 
00011 #if defined(_MSC_VER)
00012 // Turn off compiler warning about long names
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 // Default Constructor
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 // Destructor
00042   CbcNlpStrategy::~CbcNlpStrategy ()
00043   {}
00044 
00045 // Clone
00046   CbcStrategy *
00047   CbcNlpStrategy::clone() const
00048   {
00049     return new CbcNlpStrategy(*this);
00050   }
00051 
00052 // Copy constructor
00053   CbcNlpStrategy::CbcNlpStrategy(const CbcNlpStrategy & rhs)
00054       :
00055       hasFailed_(false),
00056       maxFailure_(rhs.maxFailure_),
00057       maxInfeasible_(rhs.maxInfeasible_),
00058       pretendFailIsInfeasible_(rhs.pretendFailIsInfeasible_)
00059   {}
00060 // Return a new Full node information pointer (descendant of CbcFullNodeInfo)
00061   CbcNodeInfo *
00062   CbcNlpStrategy::fullNodeInfo(CbcModel * model,int numberRowsAtContinuous) const
00063   {
00064     return new CbcFullNodeInfo(model,numberRowsAtContinuous);
00065   }
00066 // Return a new Partial node information pointer (descendant of CbcPartialNodeInfo)
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   /* After a CbcModel::resolve this can return a status
00077      -1 no effect
00078      0 treat as optimal
00079      1 as 0 but do not do any more resolves (i.e. no more cuts)
00080      2 treat as infeasible
00081   */
00082   int
00083   CbcNlpStrategy::status(CbcModel * model, CbcNodeInfo * parent,int whereFrom)
00084   {
00085 
00086     OsiSolverInterface * solver = model->solver();//get 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       // Have to make sure that we will branch
00125       OsiTMINLPInterface * ipopt = dynamic_cast<OsiTMINLPInterface *>(solver);
00126       ipopt->forceBranchable();
00127       //change objective value
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       // Have to make sure that we will branch
00136       OsiTMINLPInterface * osiMinlp = dynamic_cast<OsiTMINLPInterface *>(solver);
00137       osiMinlp->forceBranchable();     //      feasible=1;
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         //force infeasible
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 }

Generated on Thu Aug 5 03:02:54 2010 by  doxygen 1.4.7