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_;};
00152
00153 void addCuts(OsiCuts & cuts,int numberToBranch, int * whichGenerator);
00154 void addCuts(int numberCuts, CbcCountRowCut ** cuts,int numberToBranch);
00158 void deleteCuts(int numberToDelete,CbcCountRowCut ** cuts);
00159 void deleteCuts(int numberToDelete,int * which);
00160
00162 void deleteCut(int whichOne);
00163
00165 void decrementCuts(int change=1);
00166
00168 void decrementParentCuts(int change=1);
00169
00171 void incrementParentCuts(int change=1);
00172
00174 inline CbcCountRowCut ** cuts() const
00175 {return cuts_;};
00176
00178 inline int numberCuts() const
00179 {return numberCuts_;};
00180 inline void setNumberCuts(int value)
00181 {numberCuts_=value;};
00182
00184 inline void nullOwner()
00185 { owner_=NULL;};
00186 const inline CbcNode * owner() const
00187 { return owner_;};
00189 inline int nodeNumber() const
00190 { return nodeNumber_;};
00191 inline void setNodeNumber(int node)
00192 { nodeNumber_=node;};
00193 protected:
00194
00202 int numberPointingToThis_;
00203
00205 CbcNodeInfo * parent_;
00206
00208 CbcNode * owner_;
00209
00211 int numberCuts_;
00212
00214 int nodeNumber_;
00215
00217 CbcCountRowCut ** cuts_;
00218
00221 int numberRows_;
00222
00229 int numberBranchesLeft_;
00230
00231 private:
00232
00234 CbcNodeInfo & operator=(const CbcNodeInfo& rhs);
00235
00236 };
00237
00249 class CbcFullNodeInfo : public CbcNodeInfo {
00250
00251 public:
00252
00262 virtual void applyToModel (CbcModel *model, CoinWarmStartBasis *&basis,
00263 CbcCountRowCut **addCuts,
00264 int ¤tNumberCuts) const ;
00265
00270 virtual CbcNodeInfo * buildRowBasis(CoinWarmStartBasis & basis) const ;
00271
00272 CbcFullNodeInfo ();
00273
00276 CbcFullNodeInfo (CbcModel * model,
00277 int numberRowsAtContinuous);
00278
00279
00280 CbcFullNodeInfo ( const CbcFullNodeInfo &);
00281
00282
00283 ~CbcFullNodeInfo ();
00284
00286 virtual CbcNodeInfo * clone() const;
00287 protected:
00288
00294 CoinWarmStartBasis *basis_;
00295 int numberIntegers_;
00296
00297 double * lower_;
00298 double * upper_;
00299 private:
00301 CbcFullNodeInfo & operator=(const CbcFullNodeInfo& rhs);
00302 };
00303
00304
00305
00314 class CbcPartialNodeInfo : public CbcNodeInfo {
00315
00316 public:
00317
00323 virtual void applyToModel (CbcModel *model, CoinWarmStartBasis *&basis,
00324 CbcCountRowCut **addCuts,
00325 int ¤tNumberCuts) const ;
00326
00331 virtual CbcNodeInfo * buildRowBasis(CoinWarmStartBasis & basis ) const ;
00332
00333 CbcPartialNodeInfo ();
00334
00335
00336 CbcPartialNodeInfo (CbcNodeInfo * parent, CbcNode * owner,
00337 int numberChangedBounds,const int * variables,
00338 const double * boundChanges,
00339 const CoinWarmStartDiff *basisDiff) ;
00340
00341
00342 CbcPartialNodeInfo ( const CbcPartialNodeInfo &);
00343
00344
00345 ~CbcPartialNodeInfo ();
00346
00348 virtual CbcNodeInfo * clone() const;
00349 protected:
00350
00351
00353 CoinWarmStartDiff *basisDiff_ ;
00355 int * variables_;
00356
00357 double * newBounds_;
00359 int numberChangedBounds_;
00360 private:
00361
00363 CbcPartialNodeInfo & operator=(const CbcPartialNodeInfo& rhs);
00364 };
00365
00366
00367
00385 class CbcNode {
00386
00387 public:
00388
00390 CbcNode ();
00391
00393 CbcNode (CbcModel * model, CbcNode * lastNode);
00394
00396 CbcNode (const CbcNode &);
00397
00399 CbcNode & operator= (const CbcNode& rhs);
00400
00402 ~CbcNode ();
00403
00419 void
00420 createInfo(CbcModel * model,
00421 CbcNode * lastNode,
00422 const CoinWarmStartBasis *lastws,
00423 const double * lastLower, const double * lastUpper,
00424 int numberOldActiveCuts,int numberNewCuts);
00425
00446 int chooseBranch (CbcModel * model,
00447 CbcNode * lastNode,
00448 int numberPassesLeft);
00474 int chooseDynamicBranch (CbcModel * model,
00475 CbcNode * lastNode,
00476 OsiSolverBranch * & branches,
00477 int numberPassesLeft);
00478 int analyze(CbcModel * model,double * results);
00480 void decrementCuts(int change=1);
00481
00483 void decrementParentCuts(int change=1);
00484
00486 void nullNodeInfo();
00495 void initializeInfo();
00496
00498 int branch();
00499
00500
00501 inline CbcNodeInfo * nodeInfo() const
00502 {return nodeInfo_;};
00503
00504
00505 inline double objectiveValue() const
00506 { return objectiveValue_;};
00507 inline void setObjectiveValue(double value)
00508 { objectiveValue_=value;};
00510 inline int numberBranches() const
00511 { if (branch_)
00512 return (branch_->numberBranches()) ;
00513 else
00514 return (-1) ; } ;
00515
00521 inline int variable() const
00522 {if (branch_) return branch_->variable();else return -1;};
00523
00524
00525
00526
00527
00528
00529
00530 inline int way() const
00531 {if (branch_) return branch_->way();else return 0;};
00533 inline int depth() const
00534 {return depth_;};
00536 inline int numberUnsatisfied() const
00537 {return numberUnsatisfied_;};
00538
00539
00540 inline double guessedObjectiveValue() const
00541 {return guessedObjectiveValue_;};
00542 inline void setGuessedObjectiveValue(double value)
00543 {guessedObjectiveValue_=value;};
00545 const CbcBranchingObject * branchingObject() const
00546 { return branch_;};
00548 CbcBranchingObject * modifiableBranchingObject() const
00549 { return branch_;};
00550
00551 private:
00552
00554 CbcNodeInfo * nodeInfo_;
00555
00556 double objectiveValue_;
00557
00558 double guessedObjectiveValue_;
00560 CbcBranchingObject * branch_;
00562 int depth_;
00564 int numberUnsatisfied_;
00565 };
00566
00567
00568 #endif