OsiChooseVariable.hpp
Go to the documentation of this file.
1 // Copyright (C) 2006, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef OsiChooseVariable_H
4 #define OsiChooseVariable_H
5 
6 #include <string>
7 #include <vector>
8 
9 #include "CoinWarmStartBasis.hpp"
10 #include "OsiBranchingObject.hpp"
11 
12 class OsiSolverInterface;
13 class OsiHotInfo;
14 
32 
33 public:
34 
37 
39  OsiChooseVariable (const OsiSolverInterface * solver);
40 
43 
46 
48  virtual OsiChooseVariable * clone() const;
49 
51  virtual ~OsiChooseVariable ();
52 
57  virtual int setupList ( OsiBranchingInformation *info, bool initialize);
71  virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
73  virtual bool feasibleSolution(const OsiBranchingInformation * info,
74  const double * solution,
75  int numberObjects,
76  const OsiObject ** objects);
78  void saveSolution(const OsiSolverInterface * solver);
80  void clearGoodSolution();
82  virtual void updateInformation( const OsiBranchingInformation *info,
83  int branch, OsiHotInfo * hotInfo);
84 #if 1
85  virtual void updateInformation( int whichObject, int branch,
87  double changeInObjective, double changeInValue,
88  int status);
89 #endif
90  inline double goodObjectiveValue() const
92  { return goodObjectiveValue_;}
94  inline double upChange() const
95  { return upChange_;}
97  inline double downChange() const
98  { return downChange_;}
100  inline const double * goodSolution() const
101  { return goodSolution_;}
103  inline int bestObjectIndex() const
104  { return bestObjectIndex_;}
106  inline void setBestObjectIndex(int value)
107  { bestObjectIndex_ = value;}
109  inline int bestWhichWay() const
110  { return bestWhichWay_;}
112  inline void setBestWhichWay(int value)
113  { bestWhichWay_ = value;}
115  inline int firstForcedObjectIndex() const
116  { return firstForcedObjectIndex_;}
118  inline void setFirstForcedObjectIndex(int value)
119  { firstForcedObjectIndex_ = value;}
121  inline int firstForcedWhichWay() const
122  { return firstForcedWhichWay_;}
124  inline void setFirstForcedWhichWay(int value)
125  { firstForcedWhichWay_ = value;}
127  inline int numberUnsatisfied() const
128  {return numberUnsatisfied_;}
130  inline int numberStrong() const
131  { return numberStrong_;}
133  inline void setNumberStrong(int value)
134  { numberStrong_ = value;}
136  inline int numberOnList() const
137  { return numberOnList_;}
139  inline int numberStrongDone() const
140  { return numberStrongDone_;}
142  inline int numberStrongIterations() const
143  { return numberStrongIterations_;}
145  inline int numberStrongFixed() const
146  { return numberStrongFixed_;}
148  inline const int * candidates() const
149  { return list_;}
151  inline bool trustStrongForBound() const
152  { return trustStrongForBound_;}
154  inline void setTrustStrongForBound(bool yesNo)
155  { trustStrongForBound_ = yesNo;}
157  inline bool trustStrongForSolution() const
158  { return trustStrongForSolution_;}
160  inline void setTrustStrongForSolution(bool yesNo)
161  { trustStrongForSolution_ = yesNo;}
163  void setSolver (const OsiSolverInterface * solver);
175  inline int status() const
176  { return status_;}
177  inline void setStatus(int value)
178  { status_ = value;}
179 
180 
181 protected:
182  // Data
186  double upChange_;
188  double downChange_;
190  double * goodSolution_;
192  int * list_;
194  double * useful_;
197  /* Status -
198  -1 Node is infeasible
199  0 Normal termination - we have a candidate
200  1 All looks satisfied - no candidate
201  2 We can change the bound on a variable - but we also have a strong branching candidate
202  3 We can change the bound on a variable - but we have a non-strong branching candidate
203  4 We can change the bound on a variable - no other candidates
204  */
205  int status_;
231 };
232 
239 protected:
240  // Data
242  double * upTotalChange_;
246  int * upNumber_;
248  int * downNumber_;
253 
254 private:
255  void gutsOfDelete();
256  void gutsOfCopy(const OsiPseudoCosts& rhs);
257 
258 public:
259  OsiPseudoCosts();
260  virtual ~OsiPseudoCosts();
261  OsiPseudoCosts(const OsiPseudoCosts& rhs);
263 
265  inline int numberBeforeTrusted() const
266  { return numberBeforeTrusted_; }
268  inline void setNumberBeforeTrusted(int value)
269  { numberBeforeTrusted_ = value; }
271  void initialize(int n);
273  inline int numberObjects() const
274  { return numberObjects_; }
275 
278  inline double* upTotalChange() { return upTotalChange_; }
279  inline const double* upTotalChange() const { return upTotalChange_; }
280 
281  inline double* downTotalChange() { return downTotalChange_; }
282  inline const double* downTotalChange() const { return downTotalChange_; }
283 
284  inline int* upNumber() { return upNumber_; }
285  inline const int* upNumber() const { return upNumber_; }
286 
287  inline int* downNumber() { return downNumber_; }
288  inline const int* downNumber() const { return downNumber_; }
290 
292  virtual void updateInformation(const OsiBranchingInformation *info,
293  int branch, OsiHotInfo * hotInfo);
294 #if 1
295  virtual void updateInformation( int whichObject, int branch,
297  double changeInObjective, double changeInValue,
298  int status);
299 #endif
300 };
301 
317 
318 public:
319 
321  OsiChooseStrong ();
322 
324  OsiChooseStrong (const OsiSolverInterface * solver);
325 
328 
331 
333  virtual OsiChooseVariable * clone() const;
334 
336  virtual ~OsiChooseStrong ();
337 
342  virtual int setupList ( OsiBranchingInformation *info, bool initialize);
356  virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
357 
364  inline int shadowPriceMode() const
365  { return shadowPriceMode_;}
367  inline void setShadowPriceMode(int value)
368  { shadowPriceMode_ = value;}
369 
372  { return pseudoCosts_; }
373 
376  { return pseudoCosts_; }
377 
380  inline int numberBeforeTrusted() const {
382  inline void setNumberBeforeTrusted(int value) {
384  inline int numberObjects() const {
385  return pseudoCosts_.numberObjects(); }
386 
387 protected:
388 
401  int doStrongBranching( OsiSolverInterface * solver,
403  int numberToDo, int returnCriterion);
404 
406  void resetResults(int num);
407 
408 protected:
415 
418 
424 };
425 
430 class OsiHotInfo {
431 
432 public:
433 
435  OsiHotInfo ();
436 
438  OsiHotInfo ( OsiSolverInterface * solver,
439  const OsiBranchingInformation *info,
440  const OsiObject * const * objects,
441  int whichObject);
442 
444  OsiHotInfo (const OsiHotInfo &);
445 
447  OsiHotInfo & operator= (const OsiHotInfo& rhs);
448 
450  virtual OsiHotInfo * clone() const;
451 
453  virtual ~OsiHotInfo ();
454 
458  int updateInformation( const OsiSolverInterface * solver, const OsiBranchingInformation * info,
459  OsiChooseVariable * choose);
461  inline double originalObjectiveValue() const
462  { return originalObjectiveValue_;}
464  inline double upChange() const
465  { assert (branchingObject_->numberBranches()==2); return changes_[1];}
467  inline double downChange() const
468  { assert (branchingObject_->numberBranches()==2); return changes_[0];}
470  inline void setUpChange(double value)
471  { assert (branchingObject_->numberBranches()==2); changes_[1] = value;}
473  inline void setDownChange(double value)
474  { assert (branchingObject_->numberBranches()==2); changes_[0] = value;}
476  inline double change(int k) const
477  { return changes_[k];}
478 
480  inline int upIterationCount() const
481  { assert (branchingObject_->numberBranches()==2); return iterationCounts_[1];}
483  inline int downIterationCount() const
484  { assert (branchingObject_->numberBranches()==2); return iterationCounts_[0];}
486  inline int iterationCount(int k) const
487  { return iterationCounts_[k];}
488 
490  inline int upStatus() const
491  { assert (branchingObject_->numberBranches()==2); return statuses_[1];}
493  inline int downStatus() const
494  { assert (branchingObject_->numberBranches()==2); return statuses_[0];}
496  inline void setUpStatus(int value)
497  { assert (branchingObject_->numberBranches()==2); statuses_[1] = value;}
499  inline void setDownStatus(int value)
500  { assert (branchingObject_->numberBranches()==2); statuses_[0] = value;}
502  inline int status(int k) const
503  { return statuses_[k];}
506  { return branchingObject_;}
507  inline int whichObject() const
508  { return whichObject_;}
509 
510 protected:
511  // Data
515  double * changes_;
524  int * statuses_;
529 };
530 
531 
532 #endif