00001
00002
00003 #ifndef CbcNode_H
00004 #define CbcNode_H
00005
00006 #include <string>
00007 #include <vector>
00008
00009 #include "CoinWarmStartBasis.hpp"
00010 #include "CbcBranchBase.hpp"
00011
00012 class OsiSolverInterface;
00013 class OsiSolverBranch;
00014
00015 class OsiCuts;
00016 class OsiRowCut;
00017 class OsiRowCutDebugger;
00018 class CoinWarmStartBasis;
00019 class CbcCountRowCut;
00020 class CbcModel;
00021 class CbcNode;
00022
00023
00060 class CbcNodeInfo {
00061
00062 public:
00063
00070 CbcNodeInfo ();
00071
00073 CbcNodeInfo ( const CbcNodeInfo &);
00074
00075
00081 CbcNodeInfo (CbcNodeInfo * parent);
00082
00087 CbcNodeInfo (CbcNodeInfo * parent, CbcNode * owner);
00088
00094 virtual ~CbcNodeInfo();
00096
00097
00103 virtual void applyToModel (CbcModel *model, CoinWarmStartBasis *&basis,
00104 CbcCountRowCut **addCuts,
00105 int ¤tNumberCuts) const = 0 ;
00106
00111 virtual CbcNodeInfo * buildRowBasis(CoinWarmStartBasis & basis) const = 0;
00113 virtual CbcNodeInfo * clone() const = 0;
00115 virtual void allBranchesGone() {};
00116
00118 inline void increment(int amount=1)
00119 {numberPointingToThis_+=amount;};
00120
00122 inline int decrement(int amount=1)
00123 {numberPointingToThis_-=amount;return numberPointingToThis_;};
00124
00130 inline void initializeInfo(int number)
00131 {numberPointingToThis_=number;numberBranchesLeft_=number;};
00132
00134 inline int numberBranchesLeft() const
00135 {return numberBranchesLeft_;};
00136
00138 inline int numberPointingToThis() const
00139 {return numberPointingToThis_;};
00140
00142 inline int branchedOn()
00143 {numberPointingToThis_--;numberBranchesLeft_--;return numberBranchesLeft_;};
00144
00146 inline void throwAway()
00147 {numberPointingToThis_-=numberBranchesLeft_;numberBranchesLeft_=0;};
00148
00150 CbcNodeInfo * parent() const
00151 {return parent_;};
00153 inline void nullParent()
00154 { parent_=NULL;};
00155
00156 void addCuts(OsiCuts & cuts,int numberToBranch, int * whichGenerator);
00157 void addCuts(int numberCuts, CbcCountRowCut ** cuts,int numberToBranch);
00161 void deleteCuts(int numberToDelete,CbcCountRowCut ** cuts);
00162 void deleteCuts(int numberToDelete,int * which);
00163
00165 void deleteCut(int whichOne);
00166
00168 void decrementCuts(int change=1);
00169
00171 void decrementParentCuts(int change=1);
00172
00174 void incrementParentCuts(int change=1);
00175
00177 inline CbcCountRowCut ** cuts() const
00178 {return cuts_;};
00179
00181 inline int numberCuts() const
00182 {return numberCuts_;};
00183 inline void setNumberCuts(int value)
00184 {numberCuts_=value;};
00185
00187 inline void nullOwner()
00188 { owner_=NULL;};
00189 const inline CbcNode * owner() const
00190 { return owner_;};
00192 inline int nodeNumber() const
00193 { return nodeNumber_;};
00194 inline void setNodeNumber(int node)
00195 { nodeNumber_=node;};
00196 protected:
00197
00205 int numberPointingToThis_;
00206
00208 CbcNodeInfo * parent_;
00209
00211 CbcNode * owner_;
00212
00214 int numberCuts_;
00215
00217 int nodeNumber_;
00218
00220 CbcCountRowCut ** cuts_;
00221
00224 int numberRows_;
00225
00232 int numberBranchesLeft_;
00233
00234 private:
00235
00237 CbcNodeInfo & operator=(const CbcNodeInfo& rhs);
00238
00239 };
00240
00252 class CbcFullNodeInfo : public CbcNodeInfo {
00253
00254 public:
00255
00265 virtual void applyToModel (CbcModel *model, CoinWarmStartBasis *&basis,
00266 CbcCountRowCut **addCuts,
00267 int ¤tNumberCuts) const ;
00268
00273 virtual CbcNodeInfo * buildRowBasis(CoinWarmStartBasis & basis) const ;
00274
00275 CbcFullNodeInfo ();
00276
00279 CbcFullNodeInfo (CbcModel * model,
00280 int numberRowsAtContinuous);
00281
00282
00283 CbcFullNodeInfo ( const CbcFullNodeInfo &);
00284
00285
00286 ~CbcFullNodeInfo ();
00287
00289 virtual CbcNodeInfo * clone() const;
00290 protected:
00291
00297 CoinWarmStartBasis *basis_;
00298 int numberIntegers_;
00299
00300 double * lower_;
00301 double * upper_;
00302 private:
00304 CbcFullNodeInfo & operator=(const CbcFullNodeInfo& rhs);
00305 };
00306
00307
00308
00317 class CbcPartialNodeInfo : public CbcNodeInfo {
00318
00319 public:
00320
00326 virtual void applyToModel (CbcModel *model, CoinWarmStartBasis *&basis,
00327 CbcCountRowCut **addCuts,
00328 int ¤tNumberCuts) const ;
00329
00334 virtual CbcNodeInfo * buildRowBasis(CoinWarmStartBasis & basis ) const ;
00335
00336 CbcPartialNodeInfo ();
00337
00338
00339 CbcPartialNodeInfo (CbcNodeInfo * parent, CbcNode * owner,
00340 int numberChangedBounds,const int * variables,
00341 const double * boundChanges,
00342 const CoinWarmStartDiff *basisDiff) ;
00343
00344
00345 CbcPartialNodeInfo ( const CbcPartialNodeInfo &);
00346
00347
00348 ~CbcPartialNodeInfo ();
00349
00351 virtual CbcNodeInfo * clone() const;
00352 protected:
00353
00354
00356 CoinWarmStartDiff *basisDiff_ ;
00358 int * variables_;
00359
00360 double * newBounds_;
00362 int numberChangedBounds_;
00363 private:
00364
00366 CbcPartialNodeInfo & operator=(const CbcPartialNodeInfo& rhs);
00367 };
00368
00369
00370
00388 class CbcNode {
00389
00390 public:
00391
00393 CbcNode ();
00394
00396 CbcNode (CbcModel * model, CbcNode * lastNode);
00397
00399 CbcNode (const CbcNode &);
00400
00402 CbcNode & operator= (const CbcNode& rhs);
00403
00405 ~CbcNode ();
00406
00422 void
00423 createInfo(CbcModel * model,
00424 CbcNode * lastNode,
00425 const CoinWarmStartBasis *lastws,
00426 const double * lastLower, const double * lastUpper,
00427 int numberOldActiveCuts,int numberNewCuts);
00428
00449 int chooseBranch (CbcModel * model,
00450 CbcNode * lastNode,
00451 int numberPassesLeft);
00477 int chooseDynamicBranch (CbcModel * model,
00478 CbcNode * lastNode,
00479 OsiSolverBranch * & branches,
00480 int numberPassesLeft);
00481 int analyze(CbcModel * model,double * results);
00483 void decrementCuts(int change=1);
00484
00486 void decrementParentCuts(int change=1);
00487
00489 void nullNodeInfo();
00498 void initializeInfo();
00499
00501 int branch();
00502
00503
00504 inline CbcNodeInfo * nodeInfo() const
00505 {return nodeInfo_;};
00506
00507
00508 inline double objectiveValue() const
00509 { return objectiveValue_;};
00510 inline void setObjectiveValue(double value)
00511 { objectiveValue_=value;};
00513 inline int numberBranches() const
00514 { if (branch_)
00515 return (branch_->numberBranches()) ;
00516 else
00517 return (-1) ; } ;
00518
00524 inline int variable() const
00525 {if (branch_) return branch_->variable();else return -1;};
00526
00527
00528
00529
00530
00531
00532
00533 inline int way() const
00534 {if (branch_) return branch_->way();else return 0;};
00536 inline int depth() const
00537 {return depth_;};
00539 inline int numberUnsatisfied() const
00540 {return numberUnsatisfied_;};
00541
00542
00543 inline double guessedObjectiveValue() const
00544 {return guessedObjectiveValue_;};
00545 inline void setGuessedObjectiveValue(double value)
00546 {guessedObjectiveValue_=value;};
00548 const CbcBranchingObject * branchingObject() const
00549 { return branch_;};
00551 CbcBranchingObject * modifiableBranchingObject() const
00552 { return branch_;};
00553
00554 private:
00555
00557 CbcNodeInfo * nodeInfo_;
00558
00559 double objectiveValue_;
00560
00561 double guessedObjectiveValue_;
00563 CbcBranchingObject * branch_;
00565 int depth_;
00567 int numberUnsatisfied_;
00568 };
00569
00570
00571 #endif