00001
00002
00003 #ifndef BonChooseVariable_H
00004 #define BonChooseVariable_H
00005
00006 #include "OsiChooseVariable.hpp"
00007 #include "BonCurvatureEstimator.hpp"
00008 #include "BonOsiTMINLPInterface.hpp"
00009 #include "CoinMessageHandler.hpp"
00010 #include "BonBabSetupBase.hpp"
00011
00012 class CbcModel;
00013
00014 #define OLD_USEFULLNESS
00015
00016 namespace Bonmin
00017 {
00018
00019 class HotInfo : public OsiHotInfo {
00020 public:
00022 HotInfo();
00023
00025 HotInfo( OsiSolverInterface * solver,
00026 const OsiBranchingInformation *info,
00027 const OsiObject * const * objects, int whichObject);
00028
00030 HotInfo(const HotInfo & other);
00031
00033 HotInfo & operator=(const HotInfo & rhs);
00034
00036 virtual OsiHotInfo * clone() const;
00037
00039 virtual ~HotInfo();
00040
00042 int updateInformation( const OsiSolverInterface * solver, const OsiBranchingInformation * info,
00043 OsiChooseVariable * choose);
00044
00046 double upInfeasibility() const{
00047 return infeasibilities_[1];
00048 }
00049
00051 double downInfeasibility() const{
00052 return infeasibilities_[0];
00053 }
00054
00055
00057 void setUpInfeasibility(double x){
00058 assert(branchingObject_->numberBranches()==2);
00059 infeasibilities_[1] = x;
00060 }
00061
00063 void setDownInfeasibility(double x){
00064 assert(branchingObject_->numberBranches()==2);
00065 infeasibilities_[0] = x;
00066 }
00067 private:
00069 vector<double> infeasibilities_;
00070 };
00071
00079 class BonChooseVariable : public OsiChooseVariable
00080 {
00081 protected:
00094 virtual int doStrongBranching( OsiSolverInterface * solver,
00095 OsiBranchingInformation *info,
00096 int numberToDo, int returnCriterion);
00097 #ifndef OLD_USEFULLNESS
00098
00099 enum CandidateSortCriterion {
00100 DecrPs = 0,
00101 IncrPs,
00102 DecrInfeas,
00103 IncrInfeas};
00104 #endif
00105
00107 enum StrongStatus{
00108 NotDone=-1,
00109 Feasible,
00110 Infeasible ,
00111 NotFinished };
00112 public:
00115 enum Messages_Types {
00116 PS_COST_HISTORY = 0,
00117 PS_COST_MULT,
00118 PS_COST_ESTIMATES,
00119 CANDIDATE_LIST,
00120 CANDIDATE_LIST2,
00121 CANDIDATE_LIST3,
00122 SB_HEADER,
00123 SB_RES,
00124 BRANCH_VAR,
00125 CHOSEN_VAR,
00126 UPDATE_PS_COST,
00127 BON_CHOOSE_MESSAGES_DUMMY_END
00128 };
00129
00130 class Messages : public CoinMessages
00131 {
00132 public:
00133 Messages();
00134 };
00135
00136 void passInMessageHandler(CoinMessageHandler * handler) {
00137 int logLevel = handler_->logLevel();
00138 delete handler_;
00139 handler_ = handler->clone();
00140 handler_->setLogLevel(logLevel);
00141 }
00142
00143 CoinMessageHandler& message(Messages_Types type) const {
00144 return handler_->message(type, messages_);
00145 }
00150 enum DoStrongReturnStatuses{
00151 provenInfeasible = -1 ,
00152 doneNoFixing ,
00153 doneCanFix ,
00154 interuptedCanFix ,
00155 maxTime };
00156
00158 enum chooseVariableReturnStatuses{
00159 infeasibleNode = -1,
00160 hasCandidate ,
00161 feasibleNode ,
00162 canFixAndStrongBranch ,
00163 canFixAndBranch,
00164 canFixNoCandidate
00165 };
00167 BonChooseVariable (BabSetupBase& b, const OsiSolverInterface* solver);
00168
00170 BonChooseVariable (const BonChooseVariable &);
00171
00173 BonChooseVariable & operator= (const BonChooseVariable& rhs);
00174
00176 virtual OsiChooseVariable * clone() const;
00177
00179 virtual ~BonChooseVariable ();
00180
00181 static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions);
00182
00184 double maxminCrit(const OsiBranchingInformation* info) const;
00185 void computeMultipliers(double& upMult, double& downMult) const;
00186 double computeUsefulness(const double MAXMIN_CRITERION,
00187 const double upMult, const double dowMult,
00188 const double value,
00189 const OsiObject* object, int i,
00190 double& value2) const;
00191
00194 virtual int setupList ( OsiBranchingInformation *info, bool initialize);
00195
00209 virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
00223
00224 virtual void updateInformation(const OsiBranchingInformation *info,
00225 int branch, OsiHotInfo * hotInfo);
00226 #if 1
00228 virtual void updateInformation( int whichObject, int branch,
00229 double changeInObjective, double changeInValue,
00230 int status);
00231 #endif
00232
00234 void setCbcModel(CbcModel* cbc_model)
00235 {
00236 cbc_model_ = cbc_model;
00237 }
00238
00239 void setOnlyPseudoWhenTrusted(bool only_pseudo_when_trusted)
00240 {
00241 only_pseudo_when_trusted_ = only_pseudo_when_trusted;
00242 }
00243
00244
00246 const OsiPseudoCosts & pseudoCosts() const{
00247 return pseudoCosts_;}
00248
00250 OsiPseudoCosts & pseudoCosts() {
00251 return pseudoCosts_;}
00252 protected:
00253
00255 SmartPtr<Journalist> jnlst_;
00256
00258 int bb_log_level_;
00259
00261 vector<HotInfo> results_;
00262
00264 int determineStatus(OsiSolverInterface * solver) const {
00265 if (solver->isProvenOptimal())
00266 return 0;
00267 else if (solver->isIterationLimitReached()
00268 &&!solver->isDualObjectiveLimitReached())
00269 return 2;
00270 else
00271 return 1;
00272 }
00273
00274 private:
00276 BonChooseVariable ();
00277
00278 protected:
00280 CbcModel* cbc_model_;
00281
00285 bool only_pseudo_when_trusted_;
00286
00289 int number_not_trusted_;
00290
00292 CoinMessageHandler * handler_;
00293
00295 Messages messages_;
00296
00301 double maxmin_crit_no_sol_;
00304 double maxmin_crit_have_sol_;
00306 double setup_pseudo_frac_;
00309 int numberBeforeTrustedList_;
00311 int numberStrongRoot_;
00313 int numberStrongBackup_;
00315 int numberLookAhead_;
00316 #ifndef OLD_USEFULLNESS
00317
00318 CandidateSortCriterion sortCrit_;
00319 #endif
00320
00321 int minNumberStrongBranch_;
00323 OsiPseudoCosts pseudoCosts_;
00325 int trustStrongForPseudoCosts_;
00326
00328
00330 bool isRootNode(const OsiBranchingInformation *info) const;
00331
00333 static const std::string CNAME;
00334 };
00335
00336 }
00337 #endif