OsiBranchingObject.hpp
Go to the documentation of this file.
1 // Copyright (C) 2006, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef OsiBranchingObject_H
4 #define OsiBranchingObject_H
5 
6 #include <cassert>
7 #include <string>
8 #include <vector>
9 
10 #include "CoinError.hpp"
11 
12 class OsiSolverInterface;
13 class OsiSolverBranch;
14 
15 class OsiBranchingObject;
17 
18 //#############################################################################
19 //This contains the abstract base class for an object and for branching.
20 //It also contains a simple integer class
21 //#############################################################################
22 
53 class OsiObject {
54 
55 public:
56 
58  OsiObject ();
59 
61  OsiObject ( const OsiObject &);
62 
64  OsiObject & operator=( const OsiObject& rhs);
65 
67  virtual OsiObject * clone() const=0;
68 
70  virtual ~OsiObject ();
71 
93  double infeasibility(const OsiSolverInterface * solver,int &whichWay) const ;
94  // Faster version when more information available
95  virtual double infeasibility(const OsiBranchingInformation * info, int &whichWay) const =0;
96  // This does NOT set mutable stuff
97  virtual double checkInfeasibility(const OsiBranchingInformation * info) const;
98 
103  virtual double feasibleRegion(OsiSolverInterface * solver) const ;
109  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const =0;
110 
117  const OsiBranchingInformation * /*info*/,
118  int /*way*/) const {throw CoinError("Need code","createBranch","OsiBranchingObject"); return NULL; }
119 
122  virtual bool canDoHeuristics() const
123  {return true;}
126  virtual bool canMoveToNearest() const
127  {return false;}
131  virtual int columnNumber() const;
133  inline int priority() const
134  { return priority_;}
136  inline void setPriority(int priority)
137  { priority_ = priority;}
140  virtual bool boundBranch() const
141  {return true;}
143  virtual bool canHandleShadowPrices() const
144  { return false;}
146  inline int numberWays() const
147  { return numberWays_;}
149  inline void setNumberWays(int numberWays)
150  { numberWays_ = static_cast<short int>(numberWays) ; }
155  inline void setWhichWay(int way)
156  { whichWay_ = static_cast<short int>(way) ; }
161  inline int whichWay() const
162  { return whichWay_;}
164  virtual int preferredWay() const
165  { return -1;}
167  inline double infeasibility() const
168  { return infeasibility_;}
170  virtual double upEstimate() const;
172  virtual double downEstimate() const;
177  virtual void resetBounds(const OsiSolverInterface * ) {}
180  virtual void resetSequenceEtc(int , const int * ) {}
182  virtual void updateBefore(const OsiObject * ) {}
184  virtual void updateAfter(const OsiObject * , const OsiObject * ) {}
185 
186 protected:
188 
190  mutable double infeasibility_;
192  mutable short whichWay_;
194  short numberWays_;
197 
198 };
201 
202 
203 class OsiObject2 : public OsiObject {
204 
205 public:
206 
208  OsiObject2 ();
209 
211  OsiObject2 ( const OsiObject2 &);
212 
214  OsiObject2 & operator=( const OsiObject2& rhs);
215 
217  virtual ~OsiObject2 ();
218 
220  inline void setPreferredWay(int value)
221  {preferredWay_=value;}
222 
224  virtual int preferredWay() const
225  { return preferredWay_;}
226 protected:
230  mutable double otherInfeasibility_;
231 
232 };
233 
252 
253 public:
254 
257 
259  OsiBranchingObject (OsiSolverInterface * solver, double value);
260 
263 
266 
268  virtual OsiBranchingObject * clone() const=0;
269 
271  virtual ~OsiBranchingObject ();
272 
274  inline int numberBranches() const
275  {return numberBranches_;}
276 
278  inline int numberBranchesLeft() const
279  {return numberBranches_-branchIndex_;}
280 
283  { numberBranches_ ++;}
284 
288  inline void setNumberBranchesLeft(int /*value*/)
289  {/*assert (value==1&&!branchIndex_);*/ numberBranches_=1;}
290 
293  {branchIndex_++;}
294 
300  virtual double branch(OsiSolverInterface * solver)=0;
306  virtual double branch() {return branch(NULL);}
309  virtual bool boundBranch() const
310  {return true;}
314  inline int branchIndex() const
315  {return branchIndex_;}
316 
320  { branchIndex_ = static_cast<short int>(branchIndex) ; }
321 
323  inline double value() const
324  {return value_;}
325 
327  inline const OsiObject * originalObject() const
328  {return originalObject_;}
330  inline void setOriginalObject(const OsiObject * object)
331  {originalObject_=object;}
335  virtual void checkIsCutoff(double ) {}
337  int columnNumber() const;
340  virtual void print(const OsiSolverInterface * =NULL) const {}
341 
342 protected:
343 
345  double value_;
346 
349 
353 
358 
359 };
360 /* This contains information
361  This could also contain pseudo shadow prices
362  or information for dealing with computing and trusting pseudo-costs
363 */
365 
366 public:
367 
370 
375  OsiBranchingInformation (const OsiSolverInterface * solver, bool normalSolver,bool copySolution=false);
376 
379 
382 
384  virtual OsiBranchingInformation * clone() const;
385 
387  virtual ~OsiBranchingInformation ();
388 
389  // Note public
390 public:
392 
403  double cutoff_;
405  double direction_;
413  double defaultDual_;
415  mutable const OsiSolverInterface * solver_;
419  mutable const double * lower_;
421  mutable const double * solution_;
423  mutable const double * upper_;
425  const double * hotstartSolution_;
427  const double * pi_;
429  const double * rowActivity_;
431  const double * objective_;
433  const double * rowLower_;
435  const double * rowUpper_;
437  const double * elementByColumn_;
439  const CoinBigIndex * columnStart_;
441  const int * columnLength_;
443  const int * row_;
449  double * usefulRegion_;
457  int depth_;
460 };
461 
463 
465 
466 public:
467 
470 
478  int way , double value) ;
479 
482 
485 
487  virtual ~OsiTwoWayBranchingObject ();
488 
495  virtual double branch(OsiSolverInterface * solver)=0;
496 
497  inline int firstBranch() const { return firstBranch_; }
499  inline int way() const
500  { return !branchIndex_ ? firstBranch_ : -firstBranch_;}
501 protected:
504 };
506 
507 
508 class OsiSimpleInteger : public OsiObject2 {
509 
510 public:
511 
513  OsiSimpleInteger ();
514 
516  OsiSimpleInteger (const OsiSolverInterface * solver, int iColumn);
517 
519  OsiSimpleInteger (int iColumn, double lower, double upper);
520 
523 
525  virtual OsiObject * clone() const;
526 
529 
531  virtual ~OsiSimpleInteger ();
532 
535  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
536 
543  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
544 
549  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
550 
551 
553  inline void setColumnNumber(int value)
554  {columnNumber_=value;}
555 
560  virtual int columnNumber() const;
561 
563  inline double originalLowerBound() const
564  { return originalLower_;}
565  inline void setOriginalLowerBound(double value)
566  { originalLower_=value;}
567  inline double originalUpperBound() const
568  { return originalUpper_;}
569  inline void setOriginalUpperBound(double value)
570  { originalUpper_=value;}
575  virtual void resetBounds(const OsiSolverInterface * solver) ;
578  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
579 
581  virtual double upEstimate() const;
583  virtual double downEstimate() const;
585  virtual bool canHandleShadowPrices() const
586  { return false;}
587 protected:
595 
596 };
605 
606 public:
607 
610 
619  int way , double value) ;
627  OsiIntegerBranchingObject (OsiSolverInterface *solver,const OsiSimpleInteger * originalObject,
628  int way , double value, double downUpperBound, double upLowerBound) ;
629 
632 
635 
637  virtual OsiBranchingObject * clone() const;
638 
640  virtual ~OsiIntegerBranchingObject ();
641 
648  virtual double branch(OsiSolverInterface * solver);
649 
653  virtual void print(const OsiSolverInterface * solver=NULL);
654 
655 protected:
656  // Probably could get away with just value which is already stored
658  double down_[2];
660  double up_[2];
661 };
662 
663 
671 class OsiSOS : public OsiObject2 {
672 
673 public:
674 
675  // Default Constructor
676  OsiSOS ();
677 
682  OsiSOS (const OsiSolverInterface * solver, int numberMembers,
683  const int * which, const double * weights, int type=1);
684 
685  // Copy constructor
686  OsiSOS ( const OsiSOS &);
687 
689  virtual OsiObject * clone() const;
690 
691  // Assignment operator
692  OsiSOS & operator=( const OsiSOS& rhs);
693 
694  // Destructor
695  virtual ~OsiSOS ();
696 
699  virtual double infeasibility(const OsiBranchingInformation * info,int & whichWay) const;
700 
707  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
708 
713  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
715  virtual double upEstimate() const;
717  virtual double downEstimate() const;
718 
720  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
721 
723  inline int numberMembers() const
724  {return numberMembers_;}
725 
727  inline const int * members() const
728  {return members_;}
729 
731  inline int sosType() const
732  {return sosType_;}
733 
735  inline int setType() const
736  {return sosType_;}
737 
739  inline const double * weights() const
740  { return weights_;}
741 
744  virtual bool canDoHeuristics() const
745  {return (sosType_==1&&integerValued_);}
747  inline void setIntegerValued(bool yesNo)
748  { integerValued_=yesNo;}
750  virtual bool canHandleShadowPrices() const
751  { return true;}
753  inline void setNumberMembers(int value)
754  {numberMembers_=value;}
755 
757  inline int * mutableMembers() const
758  {return members_;}
759 
761  inline void setSosType(int value)
762  {sosType_=value;}
763 
765  inline double * mutableWeights() const
766  { return weights_;}
767 protected:
769 
771  int * members_;
773  double * weights_;
774 
778  int sosType_;
781 };
782 
787 
788 public:
789 
790  // Default Constructor
792 
793  // Useful constructor
795  int way,
796  double separator);
797 
798  // Copy constructor
800 
801  // Assignment operator
803 
805  virtual OsiBranchingObject * clone() const;
806 
807  // Destructor
808  virtual ~OsiSOSBranchingObject ();
809 
812  virtual double branch(OsiSolverInterface * solver);
813 
817  virtual void print(const OsiSolverInterface * solver=NULL);
818 private:
820 };
824 class OsiLotsize : public OsiObject2 {
825 
826 public:
827 
828  // Default Constructor
829  OsiLotsize ();
830 
831  /* Useful constructor - passed model index.
832  Also passed valid values - if range then pairs
833  */
834  OsiLotsize (const OsiSolverInterface * solver, int iColumn,
835  int numberPoints, const double * points, bool range=false);
836 
837  // Copy constructor
838  OsiLotsize ( const OsiLotsize &);
839 
841  virtual OsiObject * clone() const;
842 
843  // Assignment operator
844  OsiLotsize & operator=( const OsiLotsize& rhs);
845 
846  // Destructor
847  ~OsiLotsize ();
848 
851  virtual double infeasibility(const OsiBranchingInformation * info, int & whichWay) const;
852 
861  virtual double feasibleRegion(OsiSolverInterface * solver, const OsiBranchingInformation * info) const;
862 
867  virtual OsiBranchingObject * createBranch(OsiSolverInterface * solver, const OsiBranchingInformation * info, int way) const;
868 
869 
871  inline void setColumnNumber(int value)
872  {columnNumber_=value;}
873 
878  virtual int columnNumber() const;
884  virtual void resetBounds(const OsiSolverInterface * solver);
885 
889  bool findRange(double value, double integerTolerance) const;
890 
893  virtual void floorCeiling(double & floorLotsize, double & ceilingLotsize, double value,
894  double tolerance) const;
895 
897  inline double originalLowerBound() const
898  { return bound_[0];}
899  inline double originalUpperBound() const
900  { return bound_[rangeType_*numberRanges_-1];}
902  inline int rangeType() const
903  { return rangeType_;}
905  inline int numberRanges() const
906  { return numberRanges_;}
908  inline double * bound() const
909  { return bound_;}
912  virtual void resetSequenceEtc(int numberColumns, const int * originalColumns);
913 
915  virtual double upEstimate() const;
917  virtual double downEstimate() const;
919  virtual bool canHandleShadowPrices() const
920  { return true;}
923  virtual bool canDoHeuristics() const
924  {return false;}
925 
926 private:
928 
935  // largest gap
936  double largestGap_;
938  double * bound_;
940  mutable int range_;
941 };
942 
943 
955 
956 public:
957 
960 
969  int way , double value) ;
970 
973 
976 
978  virtual OsiBranchingObject * clone() const;
979 
981  virtual ~OsiLotsizeBranchingObject ();
982 
989  virtual double branch(OsiSolverInterface * solver);
990 
994  virtual void print(const OsiSolverInterface * solver=NULL);
995 
996 protected:
998  double down_[2];
1000  double up_[2];
1001 };
1002 #endif