Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

SbbNode.hpp

00001 // Copyright (C) 2002, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #ifndef SbbNode_H
00004 #define SbbNode_H
00005 
00006 #include <string>
00007 #include <vector>
00008 
00009 #include "CoinWarmStartBasis.hpp"
00010 #include "SbbBranchBase.hpp"
00011 
00012 class OsiSolverInterface;
00013 
00014 class OsiCuts;
00015 class OsiRowCut;
00016 class OsiRowCutDebugger;
00017 class CoinWarmStartBasis;
00018 class SbbCountRowCut;
00019 class SbbModel;
00020 class SbbNode;
00021 
00022 //#############################################################################
00059 class SbbNodeInfo {
00060 
00061 public:
00062 
00069   SbbNodeInfo ();
00070 
00076   SbbNodeInfo (SbbNodeInfo * parent);
00077    
00082   SbbNodeInfo (SbbNodeInfo * parent, SbbNode * owner);
00083 
00089   virtual ~SbbNodeInfo();
00091 
00092 
00098   virtual void applyToModel (SbbModel *model, CoinWarmStartBasis *&basis,
00099                              SbbCountRowCut **addCuts,
00100                              int &currentNumberCuts) const = 0 ;
00101 
00106   virtual SbbNodeInfo * buildRowBasis(CoinWarmStartBasis & basis) const = 0;
00108   virtual SbbNodeInfo * clone() const = 0;
00109 
00111   inline void increment(int amount=1)
00112   {numberPointingToThis_+=amount;};
00113 
00115   inline int decrement(int amount=1)
00116   {numberPointingToThis_-=amount;return numberPointingToThis_;};
00117 
00123   inline void initializeInfo(int number)
00124   {numberPointingToThis_=number;numberBranchesLeft_=number;};
00125 
00127   inline int numberBranchesLeft() const
00128   {return numberBranchesLeft_;};
00129 
00131   inline int numberPointingToThis() const
00132   {return numberPointingToThis_;};
00133 
00135   inline int branchedOn()
00136   {numberPointingToThis_--;numberBranchesLeft_--;return numberBranchesLeft_;};
00137 
00139   inline void throwAway()
00140   {numberPointingToThis_-=numberBranchesLeft_;numberBranchesLeft_=0;};
00141 
00143   SbbNodeInfo * parent() const
00144   {return parent_;};
00145 
00146   void addCuts(OsiCuts & cuts,int numberToBranch, int * whichGenerator);
00147   void addCuts(int numberCuts, SbbCountRowCut ** cuts,int numberToBranch);
00151   void deleteCuts(int numberToDelete,SbbCountRowCut ** cuts);
00152   void deleteCuts(int numberToDelete,int * which);
00153 
00155   void deleteCut(int whichOne);
00156 
00158   void decrementCuts(int change=1);
00159 
00161   void decrementParentCuts(int change=1);
00162 
00164   void incrementParentCuts(int change=1);
00165 
00167   inline SbbCountRowCut ** cuts() const
00168   {return cuts_;};
00169 
00171   inline int numberCuts() const
00172   {return numberCuts_;};
00173   inline void setNumberCuts(int value)
00174   {numberCuts_=value;};
00175 
00177   inline void nullOwner()
00178   { owner_=NULL;};
00179 protected:
00180 
00188   int numberPointingToThis_;
00189 
00191   SbbNodeInfo * parent_;
00192 
00194   SbbNode * owner_;
00195 
00197   int numberCuts_;
00198 
00200   SbbCountRowCut ** cuts_;
00201 
00204   int numberRows_;
00205 
00212   int numberBranchesLeft_;
00213       
00214 private:
00215   
00217   SbbNodeInfo & operator=(const SbbNodeInfo& rhs);
00218   
00219 };
00220 
00232 class SbbFullNodeInfo : public SbbNodeInfo {
00233 
00234 public:
00235 
00245   virtual void applyToModel (SbbModel *model, CoinWarmStartBasis *&basis,
00246                              SbbCountRowCut **addCuts,
00247                              int &currentNumberCuts) const ;
00248 
00253   virtual SbbNodeInfo * buildRowBasis(CoinWarmStartBasis & basis) const ;
00254   // Default Constructor 
00255   SbbFullNodeInfo ();
00256 
00259   SbbFullNodeInfo (SbbModel * model,
00260                    int numberRowsAtContinuous);
00261   
00262   // Copy constructor 
00263   SbbFullNodeInfo ( const SbbFullNodeInfo &);
00264    
00265   // Destructor 
00266   ~SbbFullNodeInfo ();
00267   
00269   virtual SbbNodeInfo * clone() const;
00270 protected:
00271   // Data
00277   CoinWarmStartBasis *basis_;
00278   int numberIntegers_;
00279   // Bounds stored in full
00280   double * lower_;
00281   double * upper_;
00282 private:
00284   SbbFullNodeInfo & operator=(const SbbFullNodeInfo& rhs);
00285 };
00286 
00287 
00288 
00297 class SbbPartialNodeInfo : public SbbNodeInfo {
00298 
00299 public:
00300 
00306   virtual void applyToModel (SbbModel *model, CoinWarmStartBasis *&basis,
00307                              SbbCountRowCut **addCuts,
00308                              int &currentNumberCuts) const ;
00309 
00314   virtual SbbNodeInfo * buildRowBasis(CoinWarmStartBasis & basis ) const ;
00315   // Default Constructor 
00316   SbbPartialNodeInfo ();
00317 
00318   // Constructor from current state 
00319   SbbPartialNodeInfo (SbbNodeInfo * parent, SbbNode * owner,
00320                 int numberChangedBounds,const int * variables,
00321                 const double * boundChanges,
00322                 const CoinWarmStartDiff *basisDiff) ;
00323   
00324   // Copy constructor 
00325   SbbPartialNodeInfo ( const SbbPartialNodeInfo &);
00326    
00327   // Destructor 
00328   ~SbbPartialNodeInfo ();
00329   
00331   virtual SbbNodeInfo * clone() const;
00332 private:
00333   /* Data values */
00334 
00336   CoinWarmStartDiff *basisDiff_ ;
00338   int * variables_;
00339   // New bound
00340   double * newBounds_;
00342   int numberChangedBounds_;
00343 private:
00344   
00346   SbbPartialNodeInfo & operator=(const SbbPartialNodeInfo& rhs);
00347 };
00348 
00349 
00350 
00368 class SbbNode  {
00369  
00370 public:
00371     
00373   SbbNode ();
00374 
00376   SbbNode (SbbModel * model, SbbNode * lastNode);
00377 
00379   SbbNode (const SbbNode &);
00380    
00382   SbbNode & operator= (const SbbNode& rhs);
00383 
00385   ~SbbNode ();
00386 
00402   void
00403   createInfo(SbbModel * model,
00404              SbbNode * lastNode,
00405              const CoinWarmStartBasis *lastws,
00406              const double * lastLower, const double * lastUpper,
00407              int numberOldActiveCuts,int numberNewCuts);
00408   
00426   int chooseBranch (SbbModel * model,
00427                     SbbNode * lastNode);
00428   
00430   void decrementCuts(int change=1);
00431 
00433   void decrementParentCuts(int change=1);
00434 
00436   void nullNodeInfo();
00445   void initializeInfo();
00446 
00448   int branch();
00449 
00450   // Information to make basis and bounds
00451   inline SbbNodeInfo * nodeInfo() const
00452   {return nodeInfo_;};
00453 
00454   // Objective value
00455   inline double objectiveValue() const
00456   { return objectiveValue_;};
00457   inline void setObjectiveValue(double value)
00458   { objectiveValue_=value;};
00460   inline int numberBranches() const
00461   { if (branch_)
00462       return (branch_->numberBranches()) ;
00463     else
00464       return (-1) ; } ;
00465 
00471   inline int variable() const
00472   {if (branch_) return branch_->variable();else return -1;};
00473 
00474   /* Active arm of the attached SbbBranchingObject.
00475   
00476    In the simplest instance, coded -1 for the down arm of the branch, +1 for
00477    the up arm. But see SbbBranchingObject::way() 
00478      Use nodeInfo--.numberBranchesLeft_ to see how active
00479   */
00480   inline int way() const
00481   {if (branch_) return branch_->way();else return 0;};
00483   inline int depth() const
00484   {return depth_;};
00486   inline int numberUnsatisfied() const
00487   {return numberUnsatisfied_;};
00488 
00489   // Guessed objective value (for solution)
00490   inline double guessedObjectiveValue() const
00491   {return guessedObjectiveValue_;};
00492   inline void setGuessedObjectiveValue(double value)
00493   {guessedObjectiveValue_=value;};
00494 
00495 private:
00496   // Data
00498   SbbNodeInfo * nodeInfo_;
00499   // Objective value
00500   double objectiveValue_;
00501   // Guessed satisfied Objective value
00502   double guessedObjectiveValue_;
00504   SbbBranchingObject * branch_;
00506   int depth_;
00508   int numberUnsatisfied_;
00509 };
00510 
00511 
00512 #endif

Generated on Wed Dec 3 14:36:21 2003 for Sbb by doxygen 1.3.5