Cbc  2.10.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OsiChooseVariable.hpp
Go to the documentation of this file.
1 // Copyright (C) 2006, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 // This code is licensed under the terms of the Eclipse Public License (EPL).
4 
5 #ifndef OsiChooseVariable_H
6 #define OsiChooseVariable_H
7 
8 #include <string>
9 #include <vector>
10 
11 #include "CoinWarmStartBasis.hpp"
12 #include "OsiBranchingObject.hpp"
13 
14 class OsiSolverInterface;
15 class OsiHotInfo;
16 
34 
35 public:
38 
41 
44 
47 
49  virtual OsiChooseVariable *clone() const;
50 
52  virtual ~OsiChooseVariable();
53 
58  virtual int setupList(OsiBranchingInformation *info, bool initialize);
72  virtual int chooseVariable(OsiSolverInterface *solver, OsiBranchingInformation *info, bool fixVariables);
74  virtual bool feasibleSolution(const OsiBranchingInformation *info,
75  const double *solution,
76  int numberObjects,
77  const OsiObject **objects);
79  void saveSolution(const OsiSolverInterface *solver);
81  void clearGoodSolution();
83  virtual void updateInformation(const OsiBranchingInformation *info,
84  int branch, OsiHotInfo *hotInfo);
85 #if 1
86  virtual void updateInformation(int whichObject, int branch,
88  double changeInObjective, double changeInValue,
89  int status);
90 #endif
91  inline double goodObjectiveValue() const
93  {
94  return goodObjectiveValue_;
95  }
97  inline double upChange() const
98  {
99  return upChange_;
100  }
102  inline double downChange() const
103  {
104  return downChange_;
105  }
107  inline const double *goodSolution() const
108  {
109  return goodSolution_;
110  }
112  inline int bestObjectIndex() const
113  {
114  return bestObjectIndex_;
115  }
117  inline void setBestObjectIndex(int value)
118  {
119  bestObjectIndex_ = value;
120  }
122  inline int bestWhichWay() const
123  {
124  return bestWhichWay_;
125  }
127  inline void setBestWhichWay(int value)
128  {
129  bestWhichWay_ = value;
130  }
132  inline int firstForcedObjectIndex() const
133  {
135  }
137  inline void setFirstForcedObjectIndex(int value)
138  {
139  firstForcedObjectIndex_ = value;
140  }
142  inline int firstForcedWhichWay() const
143  {
144  return firstForcedWhichWay_;
145  }
147  inline void setFirstForcedWhichWay(int value)
148  {
149  firstForcedWhichWay_ = value;
150  }
152  inline int numberUnsatisfied() const
153  {
154  return numberUnsatisfied_;
155  }
157  inline int numberStrong() const
158  {
159  return numberStrong_;
160  }
162  inline void setNumberStrong(int value)
163  {
164  numberStrong_ = value;
165  }
167  inline int numberOnList() const
168  {
169  return numberOnList_;
170  }
172  inline int numberStrongDone() const
173  {
174  return numberStrongDone_;
175  }
177  inline int numberStrongIterations() const
178  {
180  }
182  inline int numberStrongFixed() const
183  {
184  return numberStrongFixed_;
185  }
187  inline const int *candidates() const
188  {
189  return list_;
190  }
192  inline bool trustStrongForBound() const
193  {
194  return trustStrongForBound_;
195  }
197  inline void setTrustStrongForBound(bool yesNo)
198  {
199  trustStrongForBound_ = yesNo;
200  }
202  inline bool trustStrongForSolution() const
203  {
205  }
207  inline void setTrustStrongForSolution(bool yesNo)
208  {
209  trustStrongForSolution_ = yesNo;
210  }
212  void setSolver(const OsiSolverInterface *solver);
224  inline int status() const
225  {
226  return status_;
227  }
228  inline void setStatus(int value)
229  {
230  status_ = value;
231  }
232 
233 protected:
234  // Data
238  double upChange_;
240  double downChange_;
242  double *goodSolution_;
244  int *list_;
246  double *useful_;
249  /* Status -
250  -1 Node is infeasible
251  0 Normal termination - we have a candidate
252  1 All looks satisfied - no candidate
253  2 We can change the bound on a variable - but we also have a strong branching candidate
254  3 We can change the bound on a variable - but we have a non-strong branching candidate
255  4 We can change the bound on a variable - no other candidates
256  */
257  int status_;
283 };
284 
291 protected:
292  // Data
294  double *upTotalChange_;
298  int *upNumber_;
305 
306 private:
307  void gutsOfDelete();
308  void gutsOfCopy(const OsiPseudoCosts &rhs);
309 
310 public:
311  OsiPseudoCosts();
312  virtual ~OsiPseudoCosts();
313  OsiPseudoCosts(const OsiPseudoCosts &rhs);
315 
317  inline int numberBeforeTrusted() const
318  {
319  return numberBeforeTrusted_;
320  }
322  inline void setNumberBeforeTrusted(int value)
323  {
324  numberBeforeTrusted_ = value;
325  }
327  void initialize(int n);
329  inline int numberObjects() const
330  {
331  return numberObjects_;
332  }
333 
336  inline double *upTotalChange() { return upTotalChange_; }
337  inline const double *upTotalChange() const { return upTotalChange_; }
338 
339  inline double *downTotalChange() { return downTotalChange_; }
340  inline const double *downTotalChange() const { return downTotalChange_; }
341 
342  inline int *upNumber() { return upNumber_; }
343  inline const int *upNumber() const { return upNumber_; }
344 
345  inline int *downNumber() { return downNumber_; }
346  inline const int *downNumber() const { return downNumber_; }
348 
350  virtual void updateInformation(const OsiBranchingInformation *info,
351  int branch, OsiHotInfo *hotInfo);
352 #if 1
353  virtual void updateInformation(int whichObject, int branch,
355  double changeInObjective, double changeInValue,
356  int status);
357 #endif
358 };
359 
375 
376 public:
378  OsiChooseStrong();
379 
381  OsiChooseStrong(const OsiSolverInterface *solver);
382 
385 
388 
390  virtual OsiChooseVariable *clone() const;
391 
393  virtual ~OsiChooseStrong();
394 
399  virtual int setupList(OsiBranchingInformation *info, bool initialize);
413  virtual int chooseVariable(OsiSolverInterface *solver, OsiBranchingInformation *info, bool fixVariables);
414 
421  inline int shadowPriceMode() const
422  {
423  return shadowPriceMode_;
424  }
426  inline void setShadowPriceMode(int value)
427  {
428  shadowPriceMode_ = value;
429  }
430 
433  {
434  return pseudoCosts_;
435  }
436 
439  {
440  return pseudoCosts_;
441  }
442 
445  inline int numberBeforeTrusted() const
446  {
448  }
449  inline void setNumberBeforeTrusted(int value)
450  {
452  }
453  inline int numberObjects() const
454  {
455  return pseudoCosts_.numberObjects();
456  }
457 
458 protected:
473  int numberToDo, int returnCriterion);
474 
476  void resetResults(int num);
477 
478 protected:
485 
488 
494 };
495 
500 class OsiHotInfo {
501 
502 public:
504  OsiHotInfo();
505 
508  const OsiBranchingInformation *info,
509  const OsiObject *const *objects,
510  int whichObject);
511 
513  OsiHotInfo(const OsiHotInfo &);
514 
516  OsiHotInfo &operator=(const OsiHotInfo &rhs);
517 
519  virtual OsiHotInfo *clone() const;
520 
522  virtual ~OsiHotInfo();
523 
527  int updateInformation(const OsiSolverInterface *solver, const OsiBranchingInformation *info,
528  OsiChooseVariable *choose);
530  inline double originalObjectiveValue() const
531  {
533  }
535  inline double upChange() const
536  {
537  assert(branchingObject_->numberBranches() == 2);
538  return changes_[1];
539  }
541  inline double downChange() const
542  {
543  assert(branchingObject_->numberBranches() == 2);
544  return changes_[0];
545  }
547  inline void setUpChange(double value)
548  {
549  assert(branchingObject_->numberBranches() == 2);
550  changes_[1] = value;
551  }
553  inline void setDownChange(double value)
554  {
555  assert(branchingObject_->numberBranches() == 2);
556  changes_[0] = value;
557  }
559  inline double change(int k) const
560  {
561  return changes_[k];
562  }
563 
565  inline int upIterationCount() const
566  {
567  assert(branchingObject_->numberBranches() == 2);
568  return iterationCounts_[1];
569  }
571  inline int downIterationCount() const
572  {
573  assert(branchingObject_->numberBranches() == 2);
574  return iterationCounts_[0];
575  }
577  inline int iterationCount(int k) const
578  {
579  return iterationCounts_[k];
580  }
581 
583  inline int upStatus() const
584  {
585  assert(branchingObject_->numberBranches() == 2);
586  return statuses_[1];
587  }
589  inline int downStatus() const
590  {
591  assert(branchingObject_->numberBranches() == 2);
592  return statuses_[0];
593  }
595  inline void setUpStatus(int value)
596  {
597  assert(branchingObject_->numberBranches() == 2);
598  statuses_[1] = value;
599  }
601  inline void setDownStatus(int value)
602  {
603  assert(branchingObject_->numberBranches() == 2);
604  statuses_[0] = value;
605  }
607  inline int status(int k) const
608  {
609  return statuses_[k];
610  }
613  {
614  return branchingObject_;
615  }
616  inline int whichObject() const
617  {
618  return whichObject_;
619  }
620 
621 protected:
622  // Data
626  double *changes_;
635  int *statuses_;
640 };
641 
642 #endif
643 
644 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
645 */
void resetResults(int num)
Clear out the results array.
virtual int setupList(OsiBranchingInformation *info, bool initialize)
Sets up strong list and clears all if initialize is true.
int downIterationCount() const
Down iteration count - invalid if n-way.
double upChange_
Estimate of up change or change on chosen if n-way.
void setNumberBeforeTrusted(int value)
Set number of times before trusted.
void setSolver(const OsiSolverInterface *solver)
Set solver and redo arrays.
double goodObjectiveValue_
Objective value for feasible solution.
int numberObjects() const
Give the number of objects for which pseudo costs are stored.
double * useful_
Useful array (for sorting etc)
double * goodSolution_
Good solution - deleted by finalize.
void setTrustStrongForSolution(bool yesNo)
Set trust results from strong branching for valid solution.
int numberStrongFixed() const
Number of strong branches which changed bounds.
int firstForcedObjectIndex() const
Index of forced object.
int firstForcedWhichWay_
Preferred way of forced object.
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...
virtual void updateInformation(const OsiBranchingInformation *info, int branch, OsiHotInfo *hotInfo)
Given a candidate fill in useful information e.g. estimates.
virtual OsiHotInfo * clone() const
Clone.
int numberStrong() const
Number of objects to choose for strong branching.
int whichObject_
Which object on list.
const double * downTotalChange() const
int numberStrongIterations() const
Number of strong iterations actually done.
OsiChooseStrong & operator=(const OsiChooseStrong &rhs)
Assignment operator.
int whichObject() const
void setBestObjectIndex(int value)
Set index of chosen object.
OsiPseudoCosts & pseudoCosts()
Accessor method to pseudo cost object.
OsiPseudoCosts & operator=(const OsiPseudoCosts &rhs)
void setNumberStrong(int value)
Set number of objects to choose for strong branching.
const int * candidates() const
List of candidates.
int bestObjectIndex_
Index of chosen object.
int numberStrongFixed_
Number of bound changes due to strong branching.
void setStatus(int value)
void setNumberBeforeTrusted(int value)
int numberStrong_
Number of objects to choose for strong branching.
OsiHotInfo * results_
The results of the strong branching done on the candidates where the pseudocosts were not sufficient...
int * list_
List of candidates.
double downChange_
Estimate of down change or max change on other possibilities if n-way.
Abstract branching object base class.
void setDownChange(double value)
Set down change - invalid if n-way.
double upChange() const
Up change - invalid if n-way.
int bestWhichWay() const
Preferred way of chosen object.
int status() const
Return status - -1 Node is infeasible 0 Normal termination - we have a candidate 1 All looks satisfie...
double downChange() const
Down change - invalid if n-way.
This class contains the result of strong branching on a variable When created it stores enough inform...
OsiBranchingObject * branchingObject() const
Branching object.
void setTrustStrongForBound(bool yesNo)
Set trust results from strong branching for changing bounds.
const double * goodSolution() const
Good solution - deleted by finalize.
bool trustStrongForSolution_
Trust results from strong branching for valid solution.
const OsiSolverInterface * solver_
Pointer to solver.
int * upNumber_
Number of times up.
void setBestWhichWay(int value)
Set preferred way of chosen object.
virtual bool feasibleSolution(const OsiBranchingInformation *info, const double *solution, int numberObjects, const OsiObject **objects)
Returns true if solution looks feasible against given objects.
void clearGoodSolution()
Clears out good solution after use.
Abstract Base Class for describing an interface to a solver.
int numberUnsatisfied() const
Get the number of objects unsatisfied at this node - accurate on first pass.
OsiChooseStrong()
Default Constructor.
int upIterationCount() const
Up iteration count - invalid if n-way.
void setDownStatus(int value)
Set down status - invalid if n-way.
void setShadowPriceMode(int value)
Set Shadow price mode.
int firstForcedWhichWay() const
Preferred way of forced object.
void initialize(int n)
Initialize the pseudocosts with n entries.
virtual ~OsiHotInfo()
Destructor.
OsiBranchingObject * branchingObject_
Branching object.
void gutsOfCopy(const OsiPseudoCosts &rhs)
int numberStrongDone_
Number of strong branches actually done.
virtual ~OsiChooseVariable()
Destructor.
double * downTotalChange_
Total of all changes down.
double * upTotalChange_
Total of all changes up.
double upChange() const
Estimate of up change or change on chosen if n-way.
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...
virtual OsiChooseVariable * clone() const
Clone.
void setFirstForcedObjectIndex(int value)
Set index of forced object.
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...
int shadowPriceMode_
Pseudo Shadow Price mode 0 - off 1 - use and multiply by strong info 2 - use.
double originalObjectiveValue() const
Original objective value.
void setUpStatus(int value)
Set up status - invalid if n-way.
int numberBeforeTrusted_
Number before we trust.
OsiChooseVariable()
Default Constructor.
int numberObjects_
Number of objects (could be found from solver)
This class is the placeholder for the pseudocosts used by OsiChooseStrong.
double originalObjectiveValue_
Original objective value.
double change(int k) const
Change on way k.
int numberBeforeTrusted() const
A feww pass-through methods to access members of pseudoCosts_ as if they were members of OsiChooseStr...
const int * downNumber() const
OsiPseudoCosts pseudoCosts_
The pseudo costs for the chooser.
OsiChooseVariable & operator=(const OsiChooseVariable &rhs)
Assignment operator.
const int * upNumber() const
virtual ~OsiPseudoCosts()
int * downNumber_
Number of times down.
int numberObjects() const
virtual void updateInformation(const OsiBranchingInformation *info, int branch, OsiHotInfo *hotInfo)
Given a candidate fill in useful information e.g. estimates.
bool trustStrongForBound_
List of unsatisfied objects - first numberOnList_ for strong branching Trust results from strong bran...
double * downTotalChange()
int numberStrongIterations_
Number of strong iterations actually done.
int * statuses_
Status -1 - not done 0 - feasible and finished 1 - infeasible 2 - not finished.
int * iterationCounts_
Iteration counts.
double * changes_
Objective changes.
double * upTotalChange()
int status(int k) const
Status on way k.
int numberStrongDone() const
Number of strong branches actually done.
int downStatus() const
Down status - invalid if n-way.
int numberBeforeTrusted() const
Number of times before trusted.
virtual OsiChooseVariable * clone() const
Clone.
const OsiPseudoCosts & pseudoCosts() const
Accessor method to pseudo cost object.
bool trustStrongForSolution() const
Trust results from strong branching for valid solution.
int bestWhichWay_
Preferred way of chosen object.
OsiHotInfo & operator=(const OsiHotInfo &rhs)
Assignment operator.
int numResults_
The number of OsiHotInfo objetcs that contain information.
virtual int setupList(OsiBranchingInformation *info, bool initialize)
Sets up strong list and clears all if initialize is true.
int numberUnsatisfied_
The number of objects unsatisfied at this node.
void gutsOfDelete()
This class chooses a variable to branch on.
int numberOnList() const
Number left on strong list.
int numberOnList_
Number left on strong list.
OsiHotInfo()
Default Constructor.
int bestObjectIndex() const
Index of chosen object.
int updateInformation(const OsiSolverInterface *solver, const OsiBranchingInformation *info, OsiChooseVariable *choose)
Fill in useful information after strong branch.
Abstract base class for `objects&#39;.
int firstForcedObjectIndex_
Index of forced object.
int upStatus() const
Up status - invalid if n-way.
int numberBranches() const
The number of branch arms created for this branching object.
int shadowPriceMode() const
Pseudo Shadow Price mode 0 - off 1 - use if no strong info 2 - use if strong not trusted 3 - use even...
double goodObjectiveValue() const
Objective value for feasible solution.
int iterationCount(int k) const
Iteration count on way k.
void setUpChange(double value)
Set up change - invalid if n-way.
double downChange() const
Estimate of down change or max change on other possibilities if n-way.
void saveSolution(const OsiSolverInterface *solver)
Saves a good solution.
This class chooses a variable to branch on.
void setFirstForcedWhichWay(int value)
Set preferred way of forced object.
const double * upTotalChange() const
virtual ~OsiChooseStrong()
Destructor.
bool trustStrongForBound() const
Trust results from strong branching for changing bounds.