- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Cgl-0.55.0/Osi/src/OsiChooseVariable.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2006, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003 #ifndef OsiChooseVariable_H
    00004 #define OsiChooseVariable_H
    00005
    00006 #include <string>
    00007 #include <vector>
    00008
    00009 #include "CoinWarmStartBasis.hpp"
    00010 #include "OsiBranchingObject.hpp"
    00011
    00012 class OsiSolverInterface;
    00013 class OsiHotInfo;
    00014
    00031 class OsiChooseVariable  {
    00032
    00033 public:
    00034
    00036   OsiChooseVariable ();
    00037
    00039   OsiChooseVariable (const OsiSolverInterface * solver);
    00040
    00042   OsiChooseVariable (const OsiChooseVariable &);
    00043
    00045   OsiChooseVariable & operator= (const OsiChooseVariable& rhs);
    00046
    00048   virtual OsiChooseVariable * clone() const;
    00049
    00051   virtual ~OsiChooseVariable ();
    00052
    00057   virtual int setupList ( OsiBranchingInformation *info, bool initialize);
    00071   virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
    00073   virtual bool feasibleSolution(const OsiBranchingInformation * info,
    00074                         const double * solution,
    00075                         int numberObjects,
    00076                         const OsiObject ** objects);
    00078   void saveSolution(const OsiSolverInterface * solver);
    00080   void clearGoodSolution();
    00082   virtual void updateInformation( const OsiBranchingInformation *info,
    00083                                   int branch, OsiHotInfo * hotInfo);
    00084 #if 1
    00086   virtual void updateInformation( int whichObject, int branch,
    00087                                   double changeInObjective, double changeInValue,
    00088                                   int status);
    00089 #endif
    00091   inline double goodObjectiveValue() const
    00092   { return goodObjectiveValue_;}
    00094   inline double upChange() const
    00095   { return upChange_;}
    00097   inline double downChange() const
    00098   { return downChange_;}
    00100   inline const double * goodSolution() const
    00101   { return goodSolution_;}
    00103   inline int bestObjectIndex() const
    00104   { return bestObjectIndex_;}
    00106   inline void setBestObjectIndex(int value)
    00107   { bestObjectIndex_ = value;}
    00109   inline int bestWhichWay() const
    00110   { return bestWhichWay_;}
    00112   inline void setBestWhichWay(int value)
    00113   { bestWhichWay_ = value;}
    00115   inline int firstForcedObjectIndex() const
    00116   { return firstForcedObjectIndex_;}
    00118   inline void setFirstForcedObjectIndex(int value)
    00119   { firstForcedObjectIndex_ = value;}
    00121   inline int firstForcedWhichWay() const
    00122   { return firstForcedWhichWay_;}
    00124   inline void setFirstForcedWhichWay(int value)
    00125   { firstForcedWhichWay_ = value;}
    00127   inline int numberUnsatisfied() const
    00128   {return numberUnsatisfied_;}
    00130   inline int numberStrong() const
    00131   { return numberStrong_;}
    00133   inline void setNumberStrong(int value)
    00134   { numberStrong_ = value;}
    00136   inline int numberOnList() const
    00137   { return numberOnList_;}
    00139   inline int numberStrongDone() const
    00140   { return numberStrongDone_;}
    00142   inline int numberStrongIterations() const
    00143   { return numberStrongIterations_;}
    00145   inline int numberStrongFixed() const
    00146   { return numberStrongFixed_;}
    00148   inline const int * candidates() const
    00149   { return list_;}
    00151   inline bool trustStrongForBound() const
    00152   { return trustStrongForBound_;}
    00154   inline void setTrustStrongForBound(bool yesNo)
    00155   { trustStrongForBound_ = yesNo;}
    00157   inline bool trustStrongForSolution() const
    00158   { return trustStrongForSolution_;}
    00160   inline void setTrustStrongForSolution(bool yesNo)
    00161   { trustStrongForSolution_ = yesNo;}
    00163   void setSolver (const OsiSolverInterface * solver);
    00175   inline int status() const
    00176   { return status_;}
    00177   inline void setStatus(int value)
    00178   { status_ = value;}
    00179
    00180
    00181 protected:
    00182   // Data
    00184   double goodObjectiveValue_;
    00186   double upChange_;
    00188   double downChange_;
    00190   double * goodSolution_;
    00192   int * list_;
    00194   double * useful_;
    00196   const OsiSolverInterface * solver_;
    00197   /* Status -
    00198      -1 Node is infeasible
    00199      0  Normal termination - we have a candidate
    00200      1  All looks satisfied - no candidate
    00201      2  We can change the bound on a variable - but we also have a strong branching candidate
    00202      3  We can change the bound on a variable - but we have a non-strong branching candidate
    00203      4  We can change the bound on a variable - no other candidates
    00204   */
    00205   int status_;
    00207   int bestObjectIndex_;
    00209   int bestWhichWay_;
    00211   int firstForcedObjectIndex_;
    00213   int firstForcedWhichWay_;
    00215   int numberUnsatisfied_;
    00217   int numberStrong_;
    00219   int numberOnList_;
    00221   int numberStrongDone_;
    00223   int numberStrongIterations_;
    00225   int numberStrongFixed_;
    00228   bool trustStrongForBound_;
    00230   bool trustStrongForSolution_;
    00231 };
    00232
    00238 class OsiPseudoCosts {
    00239 protected:
    00240    // Data
    00242   double * upTotalChange_;
    00244   double * downTotalChange_;
    00246   int * upNumber_;
    00248   int * downNumber_;
    00250   int numberObjects_;
    00252   int numberBeforeTrusted_;
    00253
    00254 private:
    00255   void gutsOfDelete();
    00256   void gutsOfCopy(const OsiPseudoCosts& rhs);
    00257
    00258 public:
    00259   OsiPseudoCosts();
    00260   virtual ~OsiPseudoCosts();
    00261   OsiPseudoCosts(const OsiPseudoCosts& rhs);
    00262   OsiPseudoCosts& operator=(const OsiPseudoCosts& rhs);
    00263
    00265   inline int numberBeforeTrusted() const
    00266   { return numberBeforeTrusted_; }
    00268   inline void setNumberBeforeTrusted(int value)
    00269   { numberBeforeTrusted_ = value; }
    00271   void initialize(int n);
    00273   inline int numberObjects() const
    00274   { return numberObjects_; }
    00275
    00278   inline double* upTotalChange()               { return upTotalChange_; }
    00279   inline const double* upTotalChange() const   { return upTotalChange_; }
    00280
    00281   inline double* downTotalChange()             { return downTotalChange_; }
    00282   inline const double* downTotalChange() const { return downTotalChange_; }
    00283
    00284   inline int* upNumber()                       { return upNumber_; }
    00285   inline const int* upNumber() const           { return upNumber_; }
    00286
    00287   inline int* downNumber()                     { return downNumber_; }
    00288   inline const int* downNumber() const         { return downNumber_; }
    00290
    00292   virtual void updateInformation(const OsiBranchingInformation *info,
    00293                                   int branch, OsiHotInfo * hotInfo);
    00294 #if 1
    00296   virtual void updateInformation( int whichObject, int branch,
    00297                                   double changeInObjective, double changeInValue,
    00298                                   int status);
    00299 #endif
    00300 };
    00301
    00316 class OsiChooseStrong  : public OsiChooseVariable {
    00317
    00318 public:
    00319
    00321   OsiChooseStrong ();
    00322
    00324   OsiChooseStrong (const OsiSolverInterface * solver);
    00325
    00327   OsiChooseStrong (const OsiChooseStrong &);
    00328
    00330   OsiChooseStrong & operator= (const OsiChooseStrong& rhs);
    00331
    00333   virtual OsiChooseVariable * clone() const;
    00334
    00336   virtual ~OsiChooseStrong ();
    00337
    00342   virtual int setupList ( OsiBranchingInformation *info, bool initialize);
    00356   virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
    00357
    00364   inline int shadowPriceMode() const
    00365   { return shadowPriceMode_;}
    00367   inline void setShadowPriceMode(int value)
    00368   { shadowPriceMode_ = value;}
    00369
    00371   const OsiPseudoCosts& pseudoCosts() const
    00372   { return pseudoCosts_; }
    00373
    00375   OsiPseudoCosts& pseudoCosts()
    00376   { return pseudoCosts_; }
    00377
    00380   inline int numberBeforeTrusted() const {
    00381     return pseudoCosts_.numberBeforeTrusted(); }
    00382   inline void setNumberBeforeTrusted(int value) {
    00383     pseudoCosts_.setNumberBeforeTrusted(value); }
    00384   inline int numberObjects() const {
    00385     return pseudoCosts_.numberObjects(); }
    00386
    00387 protected:
    00388
    00401   int doStrongBranching( OsiSolverInterface * solver,
    00402                          OsiBranchingInformation *info,
    00403                          int numberToDo, int returnCriterion);
    00404
    00406   void resetResults(int num);
    00407
    00408 protected:
    00414   int shadowPriceMode_;
    00415
    00417   OsiPseudoCosts pseudoCosts_;
    00418
    00421   OsiHotInfo* results_;
    00423   int numResults_;
    00424 };
    00425
    00430 class OsiHotInfo  {
    00431
    00432 public:
    00433
    00435   OsiHotInfo ();
    00436
    00438   OsiHotInfo ( OsiSolverInterface * solver,
    00439                const OsiBranchingInformation *info,
    00440                const OsiObject * const * objects,
    00441                int whichObject);
    00442
    00444   OsiHotInfo (const OsiHotInfo &);
    00445
    00447   OsiHotInfo & operator= (const OsiHotInfo& rhs);
    00448
    00450   virtual OsiHotInfo * clone() const;
    00451
    00453   virtual ~OsiHotInfo ();
    00454
    00458   int updateInformation( const OsiSolverInterface * solver, const OsiBranchingInformation * info,
    00459                          OsiChooseVariable * choose);
    00461   inline double originalObjectiveValue() const
    00462   { return originalObjectiveValue_;}
    00464   inline double upChange() const
    00465   { assert (branchingObject_->numberBranches()==2); return changes_[1];}
    00467   inline double downChange() const
    00468   { assert (branchingObject_->numberBranches()==2); return changes_[0];}
    00470   inline void setUpChange(double value)
    00471   { assert (branchingObject_->numberBranches()==2); changes_[1] = value;}
    00473   inline void setDownChange(double value)
    00474   { assert (branchingObject_->numberBranches()==2); changes_[0] = value;}
    00476   inline double change(int k) const
    00477   { return changes_[k];}
    00478
    00480   inline int upIterationCount() const
    00481   { assert (branchingObject_->numberBranches()==2); return iterationCounts_[1];}
    00483   inline int downIterationCount() const
    00484   { assert (branchingObject_->numberBranches()==2); return iterationCounts_[0];}
    00486   inline int iterationCount(int k) const
    00487   { return iterationCounts_[k];}
    00488
    00490   inline int upStatus() const
    00491   { assert (branchingObject_->numberBranches()==2); return statuses_[1];}
    00493   inline int downStatus() const
    00494   { assert (branchingObject_->numberBranches()==2); return statuses_[0];}
    00496   inline void setUpStatus(int value)
    00497   { assert (branchingObject_->numberBranches()==2); statuses_[1] = value;}
    00499   inline void setDownStatus(int value)
    00500   { assert (branchingObject_->numberBranches()==2); statuses_[0] = value;}
    00502   inline int status(int k) const
    00503   { return statuses_[k];}
    00505   inline OsiBranchingObject * branchingObject() const
    00506   { return branchingObject_;}
    00507   inline int whichObject() const
    00508   { return whichObject_;}
    00509
    00510 protected:
    00511   // Data
    00513   double originalObjectiveValue_;
    00515   double * changes_;
    00517   int * iterationCounts_;
    00524   int * statuses_;
    00526   OsiBranchingObject * branchingObject_;
    00528   int whichObject_;
    00529 };
    00530
    00531
    00532 #endif