Bonmin 1.4trunk
|
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_HEADER, 00125 SB_RES, 00126 BRANCH_VAR, 00127 CHOSEN_VAR, 00128 UPDATE_PS_COST, 00129 BON_CHOOSE_MESSAGES_DUMMY_END 00130 }; 00131 00132 class Messages : public CoinMessages 00133 { 00134 public: 00135 Messages(); 00136 }; 00137 00138 void passInMessageHandler(CoinMessageHandler * handler) { 00139 int logLevel = handler_->logLevel(); 00140 delete handler_; 00141 handler_ = handler->clone(); 00142 handler_->setLogLevel(logLevel); 00143 } 00144 00145 CoinMessageHandler& message(Messages_Types type) const { 00146 return handler_->message(type, messages_); 00147 } 00152 enum DoStrongReturnStatuses{ 00153 provenInfeasible = -1 , 00154 doneNoFixing , 00155 doneCanFix , 00156 interuptedCanFix , 00157 maxTime }; 00158 00160 enum chooseVariableReturnStatuses{ 00161 infeasibleNode = -1, 00162 hasCandidate , 00163 feasibleNode , 00164 canFixAndStrongBranch , 00165 canFixAndBranch, 00166 canFixNoCandidate 00167 }; 00169 BonChooseVariable (BabSetupBase& b, const OsiSolverInterface* solver); 00170 00172 BonChooseVariable (const BonChooseVariable &); 00173 00175 BonChooseVariable & operator= (const BonChooseVariable& rhs); 00176 00178 virtual OsiChooseVariable * clone() const; 00179 00181 virtual ~BonChooseVariable (); 00182 00183 static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions); 00184 00186 double maxminCrit(const OsiBranchingInformation* info) const; 00187 void computeMultipliers(double& upMult, double& downMult) const; 00188 double computeUsefulness(const double MAXMIN_CRITERION, 00189 const double upMult, const double dowMult, 00190 const double value, 00191 const OsiObject* object, int i, 00192 double& value2) const; 00193 00196 virtual int setupList ( OsiBranchingInformation *info, bool initialize); 00197 00211 virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables); 00225 00226 virtual void updateInformation(const OsiBranchingInformation *info, 00227 int branch, OsiHotInfo * hotInfo); 00228 #if 1 00229 00230 virtual void updateInformation( int whichObject, int branch, 00231 double changeInObjective, double changeInValue, 00232 int status); 00233 #endif 00234 00236 void setCbcModel(CbcModel* cbc_model) 00237 { 00238 cbc_model_ = cbc_model; 00239 } 00240 00241 void setOnlyPseudoWhenTrusted(bool only_pseudo_when_trusted) 00242 { 00243 only_pseudo_when_trusted_ = only_pseudo_when_trusted; 00244 } 00245 00246 00248 const OsiPseudoCosts & pseudoCosts() const{ 00249 return pseudoCosts_;} 00250 00252 OsiPseudoCosts & pseudoCosts() { 00253 return pseudoCosts_;} 00254 protected: 00255 00257 SmartPtr<Journalist> jnlst_; 00258 00260 int bb_log_level_; 00261 00263 vector<HotInfo> results_; 00264 00266 int determineStatus(OsiSolverInterface * solver) const { 00267 if (solver->isProvenOptimal()) 00268 return 0; // optimal 00269 else if (solver->isIterationLimitReached() 00270 &&!solver->isDualObjectiveLimitReached()) 00271 return 2; // unknown 00272 else 00273 return 1; // infeasible 00274 } 00275 00276 private: 00278 BonChooseVariable (); 00279 00281 double time_limit_; 00282 00284 double start_time_; 00285 protected: 00287 CbcModel* cbc_model_; 00288 00292 bool only_pseudo_when_trusted_; 00293 00296 int number_not_trusted_; 00297 00299 CoinMessageHandler * handler_; 00300 00302 Messages messages_; 00303 // ToDo: Make this options 00308 double maxmin_crit_no_sol_; 00311 double maxmin_crit_have_sol_; 00313 double setup_pseudo_frac_; 00316 int numberBeforeTrustedList_; 00318 int numberStrongRoot_; 00320 int numberStrongBackup_; 00322 int numberLookAhead_; 00323 #ifndef OLD_USEFULLNESS 00324 00325 CandidateSortCriterion sortCrit_; 00326 #endif 00327 00328 int minNumberStrongBranch_; 00330 OsiPseudoCosts pseudoCosts_; 00332 int trustStrongForPseudoCosts_; 00333 00335 00337 bool isRootNode(const OsiBranchingInformation *info) const; 00338 00340 static const std::string CNAME; 00341 }; 00342 00343 } 00344 #endif