BonChooseVariable.hpp
Go to the documentation of this file.
1 // Copyright (C) 2006, 2008 International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef BonChooseVariable_H
4 #define BonChooseVariable_H
5 
6 #include "OsiChooseVariable.hpp"
7 #ifdef BONMIN_CURVATURE_BRANCHING
9 #endif
11 #include "CoinMessageHandler.hpp"
12 #include "BonBabSetupBase.hpp"
13 // Forward declaration
14 class CbcModel;
15 
16 #define OLD_USEFULLNESS
17 
18 namespace Bonmin
19 {
20 
21  class HotInfo : public OsiHotInfo {
22  public:
24  HotInfo();
25 
27  HotInfo( OsiSolverInterface * solver,
28  const OsiBranchingInformation *info,
29  const OsiObject * const * objects, int whichObject);
30 
32  HotInfo(const HotInfo & other);
33 
35  HotInfo & operator=(const HotInfo & rhs);
36 
38  virtual OsiHotInfo * clone() const;
39 
41  virtual ~HotInfo();
42 
44  int updateInformation( const OsiSolverInterface * solver, const OsiBranchingInformation * info,
45  OsiChooseVariable * choose);
46 
48  double upInfeasibility() const{
49  return infeasibilities_[1];
50  }
51 
53  double downInfeasibility() const{
54  return infeasibilities_[0];
55  }
56 
57 
59  void setUpInfeasibility(double x){
60  assert(branchingObject_->numberBranches()==2);
61  infeasibilities_[1] = x;
62  }
63 
65  void setDownInfeasibility(double x){
66  assert(branchingObject_->numberBranches()==2);
67  infeasibilities_[0] = x;
68  }
69  private:
72  };
73 
81  class BonChooseVariable : public OsiChooseVariable
82  {
83  protected:
96  virtual int doStrongBranching( OsiSolverInterface * solver,
97  OsiBranchingInformation *info,
98  int numberToDo, int returnCriterion);
99 #ifndef OLD_USEFULLNESS
100 
101  enum CandidateSortCriterion {
102  DecrPs = 0,
103  IncrPs,
104  DecrInfeas,
105  IncrInfeas};
106 #endif
107 
114  public:
131  };
132 
133  class Messages : public CoinMessages
134  {
135  public:
136  Messages();
137  };
138 
139  void passInMessageHandler(CoinMessageHandler * handler) {
140  int logLevel = handler_->logLevel();
141  delete handler_;
142  handler_ = handler->clone();
143  handler_->setLogLevel(logLevel);
144  }
145 
146  CoinMessageHandler& message(Messages_Types type) const {
147  return handler_->message(type, messages_);
148  }
159 
168  };
170  BonChooseVariable (BabSetupBase& b, const OsiSolverInterface* solver);
171 
174 
177 
179  virtual OsiChooseVariable * clone() const;
180 
182  virtual ~BonChooseVariable ();
183 
185 
187  double maxminCrit(const OsiBranchingInformation* info) const;
188  void computeMultipliers(double& upMult, double& downMult) const;
189  double computeUsefulness(const double MAXMIN_CRITERION,
190  const double upMult, const double dowMult,
191  const double value,
192  const OsiObject* object, int i,
193  double& value2) const;
194 
197  virtual int setupList ( OsiBranchingInformation *info, bool initialize);
198 
212  virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
226  virtual void updateInformation(const OsiBranchingInformation *info,
228  int branch, OsiHotInfo * hotInfo);
229 #if 1
230  virtual void updateInformation( int whichObject, int branch,
232  double changeInObjective, double changeInValue,
233  int status);
234 #endif
235 
237  void setCbcModel(CbcModel* cbc_model)
238  {
239  cbc_model_ = cbc_model;
240  }
241 
242  void setOnlyPseudoWhenTrusted(bool only_pseudo_when_trusted)
243  {
244  only_pseudo_when_trusted_ = only_pseudo_when_trusted;
245  }
246 
247 
249  const OsiPseudoCosts & pseudoCosts() const{
250  return pseudoCosts_;}
251 
253  OsiPseudoCosts & pseudoCosts() {
254  return pseudoCosts_;}
255  protected:
256 
259 
262 
265 
267  int determineStatus(OsiSolverInterface * solver) const {
268  if (solver->isProvenOptimal())
269  return 0; // optimal
270  else if (solver->isIterationLimitReached()
271  &&!solver->isDualObjectiveLimitReached())
272  return 2; // unknown
273  else
274  return 1; // infeasible
275  }
276 
277  private:
280 
282  double time_limit_;
283 
285  double start_time_;
286  protected:
288  CbcModel* cbc_model_;
289 
294 
298 
300  CoinMessageHandler * handler_;
301 
304  // ToDo: Make this options
324 #ifndef OLD_USEFULLNESS
325 
326  CandidateSortCriterion sortCrit_;
327 #endif
328 
331  OsiPseudoCosts pseudoCosts_;
334 
336 
338  bool isRootNode(const OsiBranchingInformation *info) const;
339 
341  static const std::string CNAME;
342  };
343 
344 }
345 #endif
virtual OsiHotInfo * clone() const
Clone.
Normal termination, found a variable to branch on.
chooseVariableReturnStatuses
Return statuses for chooseVariable.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
HotInfo()
Default constructor.
virtual int setupList(OsiBranchingInformation *info, bool initialize)
Sets up strong list and clears all if initialize is true.
virtual ~BonChooseVariable()
Destructor.
void setOnlyPseudoWhenTrusted(bool only_pseudo_when_trusted)
virtual ~HotInfo()
Destructor.
void setCbcModel(CbcModel *cbc_model)
Method for setting CbcModel, which is used to get statusOfSearch.
double setup_pseudo_frac_
fraction of branching candidates that are not trusted yet
This class chooses a variable to branch on.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
Can fix variables but does not have strong branching candidates.
bool only_pseudo_when_trusted_
Flag indicating whether we don&#39;t want to mix strong branching and pseudo costs during the decision wh...
int trustStrongForPseudoCosts_
Wether or not to trust strong branching results for updating pseudo costs.
double downInfeasibility() const
down infeasibility
bool isRootNode(const OsiBranchingInformation *info) const
detecting if this is root node
Ipopt::SmartPtr< Ipopt::Journalist > jnlst_
Holding on the a pointer to the journalist.
double maxmin_crit_no_sol_
maxmin weight in branching decision when no solution has been found yet
double computeUsefulness(const double MAXMIN_CRITERION, const double upMult, const double dowMult, const double value, const OsiObject *object, int i, double &value2) const
virtual void updateInformation(const OsiBranchingInformation *info, int branch, OsiHotInfo *hotInfo)
This is a utility function which does strong branching on a list of objects and stores the results in...
double maxminCrit(const OsiBranchingInformation *info) const
Helper functions for setupList and chooseVariable.
Found variable to fix and also has remaining candidate for strong branching.
int numberStrongBackup_
backup of numberStrong_ before Root node solve
virtual OsiChooseVariable * clone() const
Clone.
double maxmin_crit_have_sol_
maxmin weight in branching decision when no solution has been found yet
void passInMessageHandler(CoinMessageHandler *handler)
static const std::string CNAME
Stores the class name for throwing errors.
int minNumberStrongBranch_
Always strong branch that many first candidate in the list regardless of numberTrusted.
vector< HotInfo > results_
Stores strong branching results.
HotInfo & operator=(const HotInfo &rhs)
Assignment operator.
All variable are feasible, the node is feasible.
CoinMessageHandler & message(Messages_Types type) const
All done no variable can be fixed.
const OsiPseudoCosts & pseudoCosts() const
Access to pseudo costs storage.
OsiPseudoCosts & pseudoCosts()
Access to pseudo costs storage.
void setDownInfeasibility(double x)
Set the down infeasibility.
A class to have all elements necessary to setup a branch-and-bound.
Interupted and found a variable to fix.
StrongStatus
Statuses for strong branching candidates.
int bb_log_level_
verbosity level
Found variable to fix and also has a (non-strong) branching candidate.
CoinMessageHandler * handler_
Message handler.
int number_not_trusted_
Number of variables put into the list because there were not trusted.
int numberLookAhead_
number of look-ahead strong-branching steps
double time_limit_
Global time limit for algorithm.
CbcModel * cbc_model_
CbcModel, used to get status of search.
void computeMultipliers(double &upMult, double &downMult) const
int numberBeforeTrustedList_
number of times a branch has to happen so that it is trusted in setupList
vector< double > infeasibilities_
infeasibilities of children
int updateInformation(const OsiSolverInterface *solver, const OsiBranchingInformation *info, OsiChooseVariable *choose)
Fill in some usefull information after a strong branching is done:
OsiPseudoCosts pseudoCosts_
Stores the pseudo costs.
Several variable can be fixed.
void setUpInfeasibility(double x)
Set the down infeasibility.
double upInfeasibility() const
up infeasibility
BonChooseVariable()
Default Constructor, forbiden for some reason.
int numberStrongRoot_
number of strong branching points at root node
int determineStatus(OsiSolverInterface *solver) const
Determine status of strong branching solution.
return b
Definition: OSdtoa.cpp:1719
Interupted because of time limit.
virtual int doStrongBranching(OsiSolverInterface *solver, OsiBranchingInformation *info, int numberToDo, int returnCriterion)
This is a utility function which does strong branching on a list of objects and stores the results in...
BonChooseVariable & operator=(const BonChooseVariable &rhs)
Assignment operator.
virtual int chooseVariable(OsiSolverInterface *solver, OsiBranchingInformation *info, bool fixVariables)
Choose a variable Returns - -1 Node is infeasible 0 Normal termination - we have a candidate 1 All lo...
double start_time_
Starting time of algorithm.
void fint fint fint real fint real * x