/home/coin/SVN-release/Osi-0.97.1/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   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 
00376   inline int numberBeforeTrusted() const {
00377     return pseudoCosts_.numberBeforeTrusted(); }
00378   inline void setNumberBeforeTrusted(int value) {
00379     pseudoCosts_.setNumberBeforeTrusted(value); }
00380   inline int numberObjects() const {
00381     return pseudoCosts_.numberObjects(); }
00382 
00383 protected:
00384 
00397   int doStrongBranching( OsiSolverInterface * solver, 
00398                          OsiBranchingInformation *info,
00399                          int numberToDo, int returnCriterion);
00400 
00402   void resetResults(int num);
00403 
00404 protected:
00410   int shadowPriceMode_;
00411 
00413   OsiPseudoCosts pseudoCosts_;
00414 
00417   OsiHotInfo* results_;
00419   int numResults_;
00420 };
00421 
00426 class OsiHotInfo  {
00427  
00428 public:
00429     
00431   OsiHotInfo ();
00432 
00434   OsiHotInfo ( OsiSolverInterface * solver, 
00435                const OsiBranchingInformation *info,
00436                const OsiObject * const * objects,
00437                int whichObject);
00438 
00440   OsiHotInfo (const OsiHotInfo &);
00441    
00443   OsiHotInfo & operator= (const OsiHotInfo& rhs);
00444 
00446   virtual OsiHotInfo * clone() const;
00447 
00449   virtual ~OsiHotInfo ();
00450 
00454   int updateInformation( const OsiSolverInterface * solver, const OsiBranchingInformation * info,
00455                          OsiChooseVariable * choose);
00457   inline double originalObjectiveValue() const
00458   { return originalObjectiveValue_;}
00460   inline double upChange() const
00461   { assert (branchingObject_->numberBranches()==2); return changes_[1];}
00463   inline double downChange() const
00464   { assert (branchingObject_->numberBranches()==2); return changes_[0];}
00466   inline void setUpChange(double value)
00467   { assert (branchingObject_->numberBranches()==2); changes_[1] = value;}
00469   inline void setDownChange(double value)
00470   { assert (branchingObject_->numberBranches()==2); changes_[0] = value;}
00472   inline double change(int k) const
00473   { return changes_[k];}
00474 
00476   inline int upIterationCount() const
00477   { assert (branchingObject_->numberBranches()==2); return iterationCounts_[1];}
00479   inline int downIterationCount() const
00480   { assert (branchingObject_->numberBranches()==2); return iterationCounts_[0];}
00482   inline int iterationCount(int k) const
00483   { return iterationCounts_[k];}
00484 
00486   inline int upStatus() const
00487   { assert (branchingObject_->numberBranches()==2); return statuses_[1];}
00489   inline int downStatus() const
00490   { assert (branchingObject_->numberBranches()==2); return statuses_[0];}
00492   inline void setUpStatus(int value)
00493   { assert (branchingObject_->numberBranches()==2); statuses_[1] = value;}
00495   inline void setDownStatus(int value)
00496   { assert (branchingObject_->numberBranches()==2); statuses_[0] = value;}
00498   inline int status(int k) const
00499   { return statuses_[k];}
00501   inline OsiBranchingObject * branchingObject() const
00502   { return branchingObject_;}
00503   inline int whichObject() const
00504   { return whichObject_;}
00505 
00506 protected:
00507   // Data
00509   double originalObjectiveValue_;
00511   double * changes_;
00513   int * iterationCounts_;
00520   int * statuses_;
00522   OsiBranchingObject * branchingObject_;
00524   int whichObject_;
00525 };
00526 
00527 
00528 #endif

Generated on Fri May 16 00:16:56 2008 by  doxygen 1.4.7