Osi  0.108.6
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);
83  virtual void updateInformation(const OsiBranchingInformation *info,
84  int branch, OsiHotInfo *hotInfo);
85 #if 1
87  virtual void updateInformation(int whichObject, int branch,
88  double changeInObjective, double changeInValue,
89  int status);
90 #endif
92  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:
312  virtual ~OsiPseudoCosts();
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
354  virtual void updateInformation(int whichObject, int branch,
355  double changeInObjective, double changeInValue,
356  int status);
357 #endif
358 };
359 
375 
376 public:
379 
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:
505 
508  const OsiBranchingInformation *info,
509  const OsiObject *const *objects,
510  int whichObject);
511 
514 
517 
519  virtual OsiHotInfo *clone() const;
520 
522  virtual ~OsiHotInfo();
523 
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 */
Abstract branching object base class.
int numberBranches() const
The number of branch arms created for this branching object.
This class chooses a variable to branch on.
const OsiPseudoCosts & pseudoCosts() const
Accessor method to pseudo cost object.
void setShadowPriceMode(int value)
Set Shadow price mode.
OsiChooseStrong(const OsiChooseStrong &)
Copy constructor.
int numResults_
The number of OsiHotInfo objetcs that contain information.
OsiChooseStrong()
Default Constructor.
OsiPseudoCosts & pseudoCosts()
Accessor method to pseudo cost object.
virtual OsiChooseVariable * clone() const
Clone.
OsiChooseStrong(const OsiSolverInterface *solver)
Constructor from solver (so we can set up arrays etc)
int shadowPriceMode() const
Pseudo Shadow Price mode 0 - off 1 - use if no strong info 2 - use if strong not trusted 3 - use even...
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 ~OsiChooseStrong()
Destructor.
virtual int setupList(OsiBranchingInformation *info, bool initialize)
Sets up strong list and clears all if initialize is true.
int numberBeforeTrusted() const
A feww pass-through methods to access members of pseudoCosts_ as if they were members of OsiChooseStr...
int shadowPriceMode_
Pseudo Shadow Price mode 0 - off 1 - use and multiply by strong info 2 - use.
int numberObjects() const
void resetResults(int num)
Clear out the results array.
void setNumberBeforeTrusted(int value)
OsiPseudoCosts pseudoCosts_
The pseudo costs for the chooser.
OsiHotInfo * results_
The results of the strong branching done on the candidates where the pseudocosts were not sufficient.
OsiChooseStrong & operator=(const OsiChooseStrong &rhs)
Assignment operator.
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...
This class chooses a variable to branch on.
int firstForcedWhichWay() const
Preferred way of forced object.
int firstForcedObjectIndex() const
Index of forced object.
const double * goodSolution() const
Good solution - deleted by finalize.
int numberOnList() const
Number left on strong list.
void setTrustStrongForSolution(bool yesNo)
Set trust results from strong branching for valid solution.
void setStatus(int value)
double goodObjectiveValue() const
Objective value for feasible solution.
void setNumberStrong(int value)
Set number of objects to choose for strong branching.
virtual void updateInformation(const OsiBranchingInformation *info, int branch, OsiHotInfo *hotInfo)
Given a candidate fill in useful information e.g. estimates.
double * goodSolution_
Good solution - deleted by finalize.
int bestObjectIndex() const
Index of chosen object.
void setFirstForcedObjectIndex(int value)
Set index of forced object.
OsiChooseVariable(const OsiChooseVariable &)
Copy constructor.
void setBestObjectIndex(int value)
Set index of chosen object.
int numberUnsatisfied() const
Get the number of objects unsatisfied at this node - accurate on first pass.
int numberStrongFixed() const
Number of strong branches which changed bounds.
double downChange() const
Estimate of down change or max change on other possibilities if n-way.
OsiChooseVariable & operator=(const OsiChooseVariable &rhs)
Assignment operator.
void saveSolution(const OsiSolverInterface *solver)
Saves a good solution.
int numberStrongIterations_
Number of strong iterations actually done.
int numberStrongFixed_
Number of bound changes due to strong branching.
virtual void updateInformation(int whichObject, int branch, double changeInObjective, double changeInValue, int status)
Given a branch fill in useful information e.g. estimates.
const int * candidates() const
List of candidates.
OsiChooseVariable()
Default Constructor.
int * list_
List of candidates.
bool trustStrongForSolution() const
Trust results from strong branching for valid solution.
double goodObjectiveValue_
Objective value for feasible solution.
virtual ~OsiChooseVariable()
Destructor.
int firstForcedWhichWay_
Preferred way of forced object.
virtual bool feasibleSolution(const OsiBranchingInformation *info, const double *solution, int numberObjects, const OsiObject **objects)
Returns true if solution looks feasible against given objects.
int status() const
Return status - -1 Node is infeasible 0 Normal termination - we have a candidate 1 All looks satisfie...
double * useful_
Useful array (for sorting etc)
virtual int setupList(OsiBranchingInformation *info, bool initialize)
Sets up strong list and clears all if initialize is true.
int firstForcedObjectIndex_
Index of forced object.
bool trustStrongForSolution_
Trust results from strong branching for valid solution.
OsiChooseVariable(const OsiSolverInterface *solver)
Constructor from solver (so we can set up arrays etc)
int numberUnsatisfied_
The number of objects unsatisfied at this node.
void setTrustStrongForBound(bool yesNo)
Set trust results from strong branching for changing bounds.
int numberStrong() const
Number of objects to choose for strong branching.
void setBestWhichWay(int value)
Set preferred way of chosen object.
virtual OsiChooseVariable * clone() const
Clone.
bool trustStrongForBound() const
Trust results from strong branching for changing bounds.
int bestObjectIndex_
Index of chosen object.
void setSolver(const OsiSolverInterface *solver)
Set solver and redo arrays.
int numberStrong_
Number of objects to choose for strong branching.
int numberStrongIterations() const
Number of strong iterations actually done.
const OsiSolverInterface * solver_
Pointer to solver.
double upChange_
Estimate of up change or change on chosen if n-way.
void clearGoodSolution()
Clears out good solution after use.
int numberOnList_
Number left on strong list.
int bestWhichWay() const
Preferred way of chosen object.
double downChange_
Estimate of down change or max change on other possibilities if n-way.
int numberStrongDone_
Number of strong branches actually done.
int numberStrongDone() const
Number of strong branches actually done.
void setFirstForcedWhichWay(int value)
Set preferred way of forced object.
int bestWhichWay_
Preferred way of chosen 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...
double upChange() const
Estimate of up change or change on chosen if n-way.
bool trustStrongForBound_
List of unsatisfied objects - first numberOnList_ for strong branching Trust results from strong bran...
This class contains the result of strong branching on a variable When created it stores enough inform...
void setUpChange(double value)
Set up change - invalid if n-way.
int whichObject() const
double change(int k) const
Change on way k.
virtual ~OsiHotInfo()
Destructor.
void setDownChange(double value)
Set down change - invalid if n-way.
double originalObjectiveValue_
Original objective value.
OsiHotInfo()
Default Constructor.
OsiHotInfo & operator=(const OsiHotInfo &rhs)
Assignment operator.
int downIterationCount() const
Down iteration count - invalid if n-way.
double * changes_
Objective changes.
double upChange() const
Up change - invalid if n-way.
int status(int k) const
Status on way k.
int upIterationCount() const
Up iteration count - invalid if n-way.
OsiBranchingObject * branchingObject() const
Branching object.
OsiHotInfo(const OsiHotInfo &)
Copy constructor.
int upStatus() const
Up status - invalid if n-way.
int whichObject_
Which object on list.
OsiBranchingObject * branchingObject_
Branching object.
double downChange() const
Down change - invalid if n-way.
void setDownStatus(int value)
Set down status - invalid if n-way.
int iterationCount(int k) const
Iteration count on way k.
int * statuses_
Status -1 - not done 0 - feasible and finished 1 - infeasible 2 - not finished.
virtual OsiHotInfo * clone() const
Clone.
void setUpStatus(int value)
Set up status - invalid if n-way.
int * iterationCounts_
Iteration counts.
OsiHotInfo(OsiSolverInterface *solver, const OsiBranchingInformation *info, const OsiObject *const *objects, int whichObject)
Constructor from useful information.
int updateInformation(const OsiSolverInterface *solver, const OsiBranchingInformation *info, OsiChooseVariable *choose)
Fill in useful information after strong branch.
int downStatus() const
Down status - invalid if n-way.
double originalObjectiveValue() const
Original objective value.
Abstract base class for ‘objects’.
This class is the placeholder for the pseudocosts used by OsiChooseStrong.
int numberBeforeTrusted_
Number before we trust.
virtual void updateInformation(int whichObject, int branch, double changeInObjective, double changeInValue, int status)
Given a branch fill in useful information e.g. estimates.
OsiPseudoCosts(const OsiPseudoCosts &rhs)
int * upNumber_
Number of times up.
virtual void updateInformation(const OsiBranchingInformation *info, int branch, OsiHotInfo *hotInfo)
Given a candidate fill in useful information e.g. estimates.
double * upTotalChange_
Total of all changes up.
double * upTotalChange()
virtual ~OsiPseudoCosts()
int numberObjects() const
Give the number of objects for which pseudo costs are stored.
void initialize(int n)
Initialize the pseudocosts with n entries.
void gutsOfCopy(const OsiPseudoCosts &rhs)
const int * upNumber() const
void setNumberBeforeTrusted(int value)
Set number of times before trusted.
int numberBeforeTrusted() const
Number of times before trusted.
double * downTotalChange()
OsiPseudoCosts & operator=(const OsiPseudoCosts &rhs)
double * downTotalChange_
Total of all changes down.
void gutsOfDelete()
const double * downTotalChange() const
int * downNumber_
Number of times down.
const double * upTotalChange() const
int numberObjects_
Number of objects (could be found from solver)
const int * downNumber() const
Abstract Base Class for describing an interface to a solver.