00001
00002
00003
00004
00005 #ifndef OsiChooseVariable_H
00006 #define OsiChooseVariable_H
00007
00008 #include <string>
00009 #include <vector>
00010
00011 #include "CoinWarmStartBasis.hpp"
00012 #include "OsiBranchingObject.hpp"
00013
00014 class OsiSolverInterface;
00015 class OsiHotInfo;
00016
00033 class OsiChooseVariable {
00034
00035 public:
00036
00038 OsiChooseVariable ();
00039
00041 OsiChooseVariable (const OsiSolverInterface * solver);
00042
00044 OsiChooseVariable (const OsiChooseVariable &);
00045
00047 OsiChooseVariable & operator= (const OsiChooseVariable& rhs);
00048
00050 virtual OsiChooseVariable * clone() const;
00051
00053 virtual ~OsiChooseVariable ();
00054
00059 virtual int setupList ( OsiBranchingInformation *info, bool initialize);
00073 virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
00075 virtual bool feasibleSolution(const OsiBranchingInformation * info,
00076 const double * solution,
00077 int numberObjects,
00078 const OsiObject ** objects);
00080 void saveSolution(const OsiSolverInterface * solver);
00082 void clearGoodSolution();
00084 virtual void updateInformation( const OsiBranchingInformation *info,
00085 int branch, OsiHotInfo * hotInfo);
00086 #if 1
00088 virtual void updateInformation( int whichObject, int branch,
00089 double changeInObjective, double changeInValue,
00090 int status);
00091 #endif
00093 inline double goodObjectiveValue() const
00094 { return goodObjectiveValue_;}
00096 inline double upChange() const
00097 { return upChange_;}
00099 inline double downChange() const
00100 { return downChange_;}
00102 inline const double * goodSolution() const
00103 { return goodSolution_;}
00105 inline int bestObjectIndex() const
00106 { return bestObjectIndex_;}
00108 inline void setBestObjectIndex(int value)
00109 { bestObjectIndex_ = value;}
00111 inline int bestWhichWay() const
00112 { return bestWhichWay_;}
00114 inline void setBestWhichWay(int value)
00115 { bestWhichWay_ = value;}
00117 inline int firstForcedObjectIndex() const
00118 { return firstForcedObjectIndex_;}
00120 inline void setFirstForcedObjectIndex(int value)
00121 { firstForcedObjectIndex_ = value;}
00123 inline int firstForcedWhichWay() const
00124 { return firstForcedWhichWay_;}
00126 inline void setFirstForcedWhichWay(int value)
00127 { firstForcedWhichWay_ = value;}
00129 inline int numberUnsatisfied() const
00130 {return numberUnsatisfied_;}
00132 inline int numberStrong() const
00133 { return numberStrong_;}
00135 inline void setNumberStrong(int value)
00136 { numberStrong_ = value;}
00138 inline int numberOnList() const
00139 { return numberOnList_;}
00141 inline int numberStrongDone() const
00142 { return numberStrongDone_;}
00144 inline int numberStrongIterations() const
00145 { return numberStrongIterations_;}
00147 inline int numberStrongFixed() const
00148 { return numberStrongFixed_;}
00150 inline const int * candidates() const
00151 { return list_;}
00153 inline bool trustStrongForBound() const
00154 { return trustStrongForBound_;}
00156 inline void setTrustStrongForBound(bool yesNo)
00157 { trustStrongForBound_ = yesNo;}
00159 inline bool trustStrongForSolution() const
00160 { return trustStrongForSolution_;}
00162 inline void setTrustStrongForSolution(bool yesNo)
00163 { trustStrongForSolution_ = yesNo;}
00165 void setSolver (const OsiSolverInterface * solver);
00177 inline int status() const
00178 { return status_;}
00179 inline void setStatus(int value)
00180 { status_ = value;}
00181
00182
00183 protected:
00184
00186 double goodObjectiveValue_;
00188 double upChange_;
00190 double downChange_;
00192 double * goodSolution_;
00194 int * list_;
00196 double * useful_;
00198 const OsiSolverInterface * solver_;
00199
00200
00201
00202
00203
00204
00205
00206
00207 int status_;
00209 int bestObjectIndex_;
00211 int bestWhichWay_;
00213 int firstForcedObjectIndex_;
00215 int firstForcedWhichWay_;
00217 int numberUnsatisfied_;
00219 int numberStrong_;
00221 int numberOnList_;
00223 int numberStrongDone_;
00225 int numberStrongIterations_;
00227 int numberStrongFixed_;
00230 bool trustStrongForBound_;
00232 bool trustStrongForSolution_;
00233 };
00234
00240 class OsiPseudoCosts {
00241 protected:
00242
00244 double * upTotalChange_;
00246 double * downTotalChange_;
00248 int * upNumber_;
00250 int * downNumber_;
00252 int numberObjects_;
00254 int numberBeforeTrusted_;
00255
00256 private:
00257 void gutsOfDelete();
00258 void gutsOfCopy(const OsiPseudoCosts& rhs);
00259
00260 public:
00261 OsiPseudoCosts();
00262 virtual ~OsiPseudoCosts();
00263 OsiPseudoCosts(const OsiPseudoCosts& rhs);
00264 OsiPseudoCosts& operator=(const OsiPseudoCosts& rhs);
00265
00267 inline int numberBeforeTrusted() const
00268 { return numberBeforeTrusted_; }
00270 inline void setNumberBeforeTrusted(int value)
00271 { numberBeforeTrusted_ = value; }
00273 void initialize(int n);
00275 inline int numberObjects() const
00276 { return numberObjects_; }
00277
00280 inline double* upTotalChange() { return upTotalChange_; }
00281 inline const double* upTotalChange() const { return upTotalChange_; }
00282
00283 inline double* downTotalChange() { return downTotalChange_; }
00284 inline const double* downTotalChange() const { return downTotalChange_; }
00285
00286 inline int* upNumber() { return upNumber_; }
00287 inline const int* upNumber() const { return upNumber_; }
00288
00289 inline int* downNumber() { return downNumber_; }
00290 inline const int* downNumber() const { return downNumber_; }
00292
00294 virtual void updateInformation(const OsiBranchingInformation *info,
00295 int branch, OsiHotInfo * hotInfo);
00296 #if 1
00298 virtual void updateInformation( int whichObject, int branch,
00299 double changeInObjective, double changeInValue,
00300 int status);
00301 #endif
00302 };
00303
00318 class OsiChooseStrong : public OsiChooseVariable {
00319
00320 public:
00321
00323 OsiChooseStrong ();
00324
00326 OsiChooseStrong (const OsiSolverInterface * solver);
00327
00329 OsiChooseStrong (const OsiChooseStrong &);
00330
00332 OsiChooseStrong & operator= (const OsiChooseStrong& rhs);
00333
00335 virtual OsiChooseVariable * clone() const;
00336
00338 virtual ~OsiChooseStrong ();
00339
00344 virtual int setupList ( OsiBranchingInformation *info, bool initialize);
00358 virtual int chooseVariable( OsiSolverInterface * solver, OsiBranchingInformation *info, bool fixVariables);
00359
00366 inline int shadowPriceMode() const
00367 { return shadowPriceMode_;}
00369 inline void setShadowPriceMode(int value)
00370 { shadowPriceMode_ = value;}
00371
00373 const OsiPseudoCosts& pseudoCosts() const
00374 { return pseudoCosts_; }
00375
00377 OsiPseudoCosts& pseudoCosts()
00378 { return pseudoCosts_; }
00379
00382 inline int numberBeforeTrusted() const {
00383 return pseudoCosts_.numberBeforeTrusted(); }
00384 inline void setNumberBeforeTrusted(int value) {
00385 pseudoCosts_.setNumberBeforeTrusted(value); }
00386 inline int numberObjects() const {
00387 return pseudoCosts_.numberObjects(); }
00388
00389 protected:
00390
00403 int doStrongBranching( OsiSolverInterface * solver,
00404 OsiBranchingInformation *info,
00405 int numberToDo, int returnCriterion);
00406
00408 void resetResults(int num);
00409
00410 protected:
00416 int shadowPriceMode_;
00417
00419 OsiPseudoCosts pseudoCosts_;
00420
00423 OsiHotInfo* results_;
00425 int numResults_;
00426 };
00427
00432 class OsiHotInfo {
00433
00434 public:
00435
00437 OsiHotInfo ();
00438
00440 OsiHotInfo ( OsiSolverInterface * solver,
00441 const OsiBranchingInformation *info,
00442 const OsiObject * const * objects,
00443 int whichObject);
00444
00446 OsiHotInfo (const OsiHotInfo &);
00447
00449 OsiHotInfo & operator= (const OsiHotInfo& rhs);
00450
00452 virtual OsiHotInfo * clone() const;
00453
00455 virtual ~OsiHotInfo ();
00456
00460 int updateInformation( const OsiSolverInterface * solver, const OsiBranchingInformation * info,
00461 OsiChooseVariable * choose);
00463 inline double originalObjectiveValue() const
00464 { return originalObjectiveValue_;}
00466 inline double upChange() const
00467 { assert (branchingObject_->numberBranches()==2); return changes_[1];}
00469 inline double downChange() const
00470 { assert (branchingObject_->numberBranches()==2); return changes_[0];}
00472 inline void setUpChange(double value)
00473 { assert (branchingObject_->numberBranches()==2); changes_[1] = value;}
00475 inline void setDownChange(double value)
00476 { assert (branchingObject_->numberBranches()==2); changes_[0] = value;}
00478 inline double change(int k) const
00479 { return changes_[k];}
00480
00482 inline int upIterationCount() const
00483 { assert (branchingObject_->numberBranches()==2); return iterationCounts_[1];}
00485 inline int downIterationCount() const
00486 { assert (branchingObject_->numberBranches()==2); return iterationCounts_[0];}
00488 inline int iterationCount(int k) const
00489 { return iterationCounts_[k];}
00490
00492 inline int upStatus() const
00493 { assert (branchingObject_->numberBranches()==2); return statuses_[1];}
00495 inline int downStatus() const
00496 { assert (branchingObject_->numberBranches()==2); return statuses_[0];}
00498 inline void setUpStatus(int value)
00499 { assert (branchingObject_->numberBranches()==2); statuses_[1] = value;}
00501 inline void setDownStatus(int value)
00502 { assert (branchingObject_->numberBranches()==2); statuses_[0] = value;}
00504 inline int status(int k) const
00505 { return statuses_[k];}
00507 inline OsiBranchingObject * branchingObject() const
00508 { return branchingObject_;}
00509 inline int whichObject() const
00510 { return whichObject_;}
00511
00512 protected:
00513
00515 double originalObjectiveValue_;
00517 double * changes_;
00519 int * iterationCounts_;
00526 int * statuses_;
00528 OsiBranchingObject * branchingObject_;
00530 int whichObject_;
00531 };
00532
00533
00534 #endif