Bonmin  1.7
BonChooseVariable.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2006, 2008 International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef BonChooseVariable_H
00004 #define BonChooseVariable_H
00005 
00006 #include "OsiChooseVariable.hpp"
00007 #ifdef BONMIN_CURVATURE_BRANCHING
00008 #include "BonCurvatureEstimator.hpp"
00009 #endif
00010 #include "BonOsiTMINLPInterface.hpp"
00011 #include "CoinMessageHandler.hpp"
00012 #include "BonBabSetupBase.hpp"
00013 // Forward declaration
00014 class CbcModel;
00015 
00016 #define OLD_USEFULLNESS
00017 
00018 namespace Bonmin
00019 {
00020 
00021   class HotInfo : public OsiHotInfo {
00022     public:
00024     HotInfo();
00025 
00027     HotInfo( OsiSolverInterface * solver,
00028              const OsiBranchingInformation *info,
00029              const OsiObject * const * objects, int whichObject);
00030 
00032     HotInfo(const HotInfo & other);
00033 
00035     HotInfo & operator=(const HotInfo & rhs);
00036 
00038     virtual OsiHotInfo * clone() const;
00039 
00041     virtual ~HotInfo();
00042 
00044     int updateInformation( const OsiSolverInterface * solver, const OsiBranchingInformation * info,
00045                            OsiChooseVariable * choose);
00046 
00048     double upInfeasibility() const{
00049      return infeasibilities_[1];
00050     }
00051 
00053     double downInfeasibility() const{
00054      return infeasibilities_[0];
00055     }
00056 
00057 
00059     void setUpInfeasibility(double x){
00060       assert(branchingObject_->numberBranches()==2);
00061       infeasibilities_[1] = x;
00062     }
00063 
00065     void setDownInfeasibility(double x){
00066       assert(branchingObject_->numberBranches()==2);
00067       infeasibilities_[0] = x;
00068     }
00069     private:
00071     vector<double> infeasibilities_; 
00072   };
00073 
00081   class BonChooseVariable : public OsiChooseVariable
00082   {
00083   protected:
00096   virtual int doStrongBranching( OsiSolverInterface * solver, 
00097                                  OsiBranchingInformation *info,
00098                                  int numberToDo, int returnCriterion);
00099 #ifndef OLD_USEFULLNESS
00100 
00101     enum CandidateSortCriterion {
00102       DecrPs = 0,
00103       IncrPs,
00104       DecrInfeas,
00105       IncrInfeas};
00106 #endif
00107 
00109     enum StrongStatus{
00110       NotDone=-1,
00111       Feasible,
00112       Infeasible ,
00113       NotFinished };
00114   public:
00117     enum Messages_Types {
00118       PS_COST_HISTORY = 0,
00119       PS_COST_MULT,
00120       PS_COST_ESTIMATES,
00121       CANDIDATE_LIST,
00122       CANDIDATE_LIST2,
00123       CANDIDATE_LIST3,
00124       SB_START,
00125       SB_HEADER,
00126       SB_RES,
00127       BRANCH_VAR,
00128       CHOSEN_VAR,
00129       UPDATE_PS_COST,
00130       BON_CHOOSE_MESSAGES_DUMMY_END
00131     };
00132 
00133   class Messages : public CoinMessages
00134     {
00135     public:
00136       Messages();
00137     };
00138 
00139     void passInMessageHandler(CoinMessageHandler * handler) {
00140       int logLevel = handler_->logLevel();
00141       delete handler_;
00142       handler_ = handler->clone();
00143       handler_->setLogLevel(logLevel);
00144     }
00145 
00146     CoinMessageHandler& message(Messages_Types type) const {
00147       return handler_->message(type, messages_);
00148     }
00153     enum DoStrongReturnStatuses{
00154       provenInfeasible = -1 ,
00155       doneNoFixing ,
00156       doneCanFix ,
00157       interuptedCanFix ,
00158       maxTime };
00159 
00161     enum chooseVariableReturnStatuses{
00162       infeasibleNode = -1,
00163       hasCandidate ,
00164       feasibleNode ,
00165       canFixAndStrongBranch ,
00166       canFixAndBranch,
00167       canFixNoCandidate 
00168     };
00170     BonChooseVariable (BabSetupBase& b, const OsiSolverInterface* solver);
00171 
00173     BonChooseVariable (const BonChooseVariable &);
00174 
00176     BonChooseVariable & operator= (const BonChooseVariable& rhs);
00177 
00179     virtual OsiChooseVariable * clone() const;
00180 
00182     virtual ~BonChooseVariable ();
00183 
00184     static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
00185 
00187     double maxminCrit(const OsiBranchingInformation* info) const;
00188     void computeMultipliers(double& upMult, double& downMult) const;
00189     double computeUsefulness(const double MAXMIN_CRITERION,
00190         const double upMult, const double dowMult,
00191         const double value,
00192         const OsiObject* object, int i,
00193         double& value2) const;
00194 
00197     virtual int setupList ( OsiBranchingInformation *info, bool initialize);
00198 
00212     virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
00226 
00227     virtual void updateInformation(const OsiBranchingInformation *info,
00228         int branch, OsiHotInfo * hotInfo);
00229 #if 1
00230 
00231     virtual void updateInformation( int whichObject, int branch,
00232         double changeInObjective, double changeInValue,
00233         int status);
00234 #endif
00235 
00237     void setCbcModel(CbcModel* cbc_model)
00238     {
00239       cbc_model_ = cbc_model;
00240     }
00241 
00242     void setOnlyPseudoWhenTrusted(bool only_pseudo_when_trusted)
00243     {
00244       only_pseudo_when_trusted_ = only_pseudo_when_trusted;
00245     }
00246 
00247 
00249     const OsiPseudoCosts & pseudoCosts() const{
00250       return pseudoCosts_;}
00251 
00253     OsiPseudoCosts & pseudoCosts() {
00254       return pseudoCosts_;}
00255   protected:
00256 
00258     Ipopt::SmartPtr<Ipopt::Journalist> jnlst_;
00259 
00261     int bb_log_level_;
00262 
00264     vector<HotInfo> results_;
00265 
00267     int determineStatus(OsiSolverInterface * solver) const {
00268       if (solver->isProvenOptimal())
00269         return 0; // optimal
00270       else if (solver->isIterationLimitReached()
00271                &&!solver->isDualObjectiveLimitReached())
00272         return 2; // unknown 
00273       else
00274         return 1; // infeasible
00275     }
00276 
00277   private:
00279     BonChooseVariable ();
00280 
00282     double time_limit_;
00283 
00285     double start_time_;
00286   protected:
00288     CbcModel* cbc_model_;
00289 
00293     bool only_pseudo_when_trusted_;
00294 
00297     int number_not_trusted_;
00298 
00300     CoinMessageHandler * handler_;
00301 
00303     Messages messages_;
00304     // ToDo: Make this options
00309     double maxmin_crit_no_sol_;
00312     double maxmin_crit_have_sol_;
00314     double setup_pseudo_frac_;
00317     int numberBeforeTrustedList_;
00319     int numberStrongRoot_;
00321     int numberStrongBackup_;
00323     int numberLookAhead_;
00324 #ifndef OLD_USEFULLNESS
00325 
00326     CandidateSortCriterion sortCrit_;
00327 #endif
00328 
00329     int minNumberStrongBranch_;
00331     OsiPseudoCosts pseudoCosts_;
00333     int trustStrongForPseudoCosts_;
00334    
00336 
00338     bool isRootNode(const OsiBranchingInformation *info) const;
00339 
00341     static const std::string CNAME;
00342   };
00343 
00344 }
00345 #endif