00001
00002
00003 #ifndef CbcNode_H
00004 #define CbcNode_H
00005
00006 #include <string>
00007 #include <vector>
00008
00009 #include "CoinWarmStartBasis.hpp"
00010 #include "CoinSearchTree.hpp"
00011 #include "CbcBranchBase.hpp"
00012
00013 class OsiSolverInterface;
00014 class OsiSolverBranch;
00015
00016 class OsiCuts;
00017 class OsiRowCut;
00018 class OsiRowCutDebugger;
00019 class CoinWarmStartBasis;
00020 class CbcCountRowCut;
00021 class CbcModel;
00022 class CbcNode;
00023
00024
00061 class CbcNodeInfo {
00062
00063 public:
00064
00071 CbcNodeInfo ();
00072
00074 CbcNodeInfo ( const CbcNodeInfo &);
00075
00076
00082 CbcNodeInfo (CbcNodeInfo * parent);
00083
00088 CbcNodeInfo (CbcNodeInfo * parent, CbcNode * owner);
00089
00095 virtual ~CbcNodeInfo();
00097
00098
00104 virtual void applyToModel (CbcModel *model, CoinWarmStartBasis *&basis,
00105 CbcCountRowCut **addCuts,
00106 int ¤tNumberCuts) const = 0 ;
00107
00112 virtual CbcNodeInfo * buildRowBasis(CoinWarmStartBasis & basis) const = 0;
00114 virtual CbcNodeInfo * clone() const = 0;
00116 virtual void allBranchesGone() {}
00117
00119 inline void increment(int amount=1)
00120 {numberPointingToThis_+=amount;}
00121
00123 inline int decrement(int amount=1)
00124 {numberPointingToThis_-=amount;return numberPointingToThis_;}
00125
00131 inline void initializeInfo(int number)
00132 {numberPointingToThis_=number;numberBranchesLeft_=number;}
00133
00135 inline int numberBranchesLeft() const
00136 {return numberBranchesLeft_;}
00137
00139 inline int numberPointingToThis() const
00140 {return numberPointingToThis_;}
00141
00143 inline int branchedOn()
00144 {numberPointingToThis_--;numberBranchesLeft_--;return numberBranchesLeft_;}
00145
00147 inline void throwAway()
00148 {numberPointingToThis_-=numberBranchesLeft_;numberBranchesLeft_=0;}
00149
00151 CbcNodeInfo * parent() const
00152 {return parent_;}
00154 inline void nullParent()
00155 { parent_=NULL;}
00156
00157 void addCuts(OsiCuts & cuts,int numberToBranch, int * whichGenerator);
00158 void addCuts(int numberCuts, CbcCountRowCut ** cuts,int numberToBranch);
00162 void deleteCuts(int numberToDelete,CbcCountRowCut ** cuts);
00163 void deleteCuts(int numberToDelete,int * which);
00164
00166 void deleteCut(int whichOne);
00167
00169 void decrementCuts(int change=1);
00170
00172 void decrementParentCuts(int change=1);
00173
00175 void incrementParentCuts(int change=1);
00176
00178 inline CbcCountRowCut ** cuts() const
00179 {return cuts_;}
00180
00182 inline int numberCuts() const
00183 {return numberCuts_;}
00184 inline void setNumberCuts(int value)
00185 {numberCuts_=value;}
00186
00188 inline void nullOwner()
00189 { owner_=NULL;}
00190 const inline CbcNode * owner() const
00191 { return owner_;}
00193 inline int nodeNumber() const
00194 { return nodeNumber_;}
00195 inline void setNodeNumber(int node)
00196 { nodeNumber_=node;}
00197 protected:
00198
00206 int numberPointingToThis_;
00207
00209 CbcNodeInfo * parent_;
00210
00212 CbcNode * owner_;
00213
00215 int numberCuts_;
00216
00218 int nodeNumber_;
00219
00221 CbcCountRowCut ** cuts_;
00222
00225 int numberRows_;
00226
00233 int numberBranchesLeft_;
00234
00235 private:
00236
00238 CbcNodeInfo & operator=(const CbcNodeInfo& rhs);
00239
00240 };
00241
00253 class CbcFullNodeInfo : public CbcNodeInfo {
00254
00255 public:
00256
00266 virtual void applyToModel (CbcModel *model, CoinWarmStartBasis *&basis,
00267 CbcCountRowCut **addCuts,
00268 int ¤tNumberCuts) const ;
00269
00274 virtual CbcNodeInfo * buildRowBasis(CoinWarmStartBasis & basis) const ;
00275
00276 CbcFullNodeInfo ();
00277
00280 CbcFullNodeInfo (CbcModel * model,
00281 int numberRowsAtContinuous);
00282
00283
00284 CbcFullNodeInfo ( const CbcFullNodeInfo &);
00285
00286
00287 ~CbcFullNodeInfo ();
00288
00290 virtual CbcNodeInfo * clone() const;
00291 protected:
00292
00298 CoinWarmStartBasis *basis_;
00299 int numberIntegers_;
00300
00301 double * lower_;
00302 double * upper_;
00303 private:
00305 CbcFullNodeInfo & operator=(const CbcFullNodeInfo& rhs);
00306 };
00307
00308
00309
00318 class CbcPartialNodeInfo : public CbcNodeInfo {
00319
00320 public:
00321
00327 virtual void applyToModel (CbcModel *model, CoinWarmStartBasis *&basis,
00328 CbcCountRowCut **addCuts,
00329 int ¤tNumberCuts) const ;
00330
00335 virtual CbcNodeInfo * buildRowBasis(CoinWarmStartBasis & basis ) const ;
00336
00337 CbcPartialNodeInfo ();
00338
00339
00340 CbcPartialNodeInfo (CbcNodeInfo * parent, CbcNode * owner,
00341 int numberChangedBounds,const int * variables,
00342 const double * boundChanges,
00343 const CoinWarmStartDiff *basisDiff) ;
00344
00345
00346 CbcPartialNodeInfo ( const CbcPartialNodeInfo &);
00347
00348
00349 ~CbcPartialNodeInfo ();
00350
00352 virtual CbcNodeInfo * clone() const;
00353 protected:
00354
00355
00357 CoinWarmStartDiff *basisDiff_ ;
00359 int * variables_;
00360
00361 double * newBounds_;
00363 int numberChangedBounds_;
00364 private:
00365
00367 CbcPartialNodeInfo & operator=(const CbcPartialNodeInfo& rhs);
00368 };
00369
00370
00371
00389 class CbcNode : public CoinTreeNode {
00390
00391 public:
00392
00394 CbcNode ();
00395
00397 CbcNode (CbcModel * model, CbcNode * lastNode);
00398
00400 CbcNode (const CbcNode &);
00401
00403 CbcNode & operator= (const CbcNode& rhs);
00404
00406 ~CbcNode ();
00407
00423 void
00424 createInfo(CbcModel * model,
00425 CbcNode * lastNode,
00426 const CoinWarmStartBasis *lastws,
00427 const double * lastLower, const double * lastUpper,
00428 int numberOldActiveCuts,int numberNewCuts);
00429
00450 int chooseBranch (CbcModel * model,
00451 CbcNode * lastNode,
00452 int numberPassesLeft);
00478 int chooseDynamicBranch (CbcModel * model,
00479 CbcNode * lastNode,
00480 OsiSolverBranch * & branches,
00481 int numberPassesLeft);
00508 int chooseOsiBranch (CbcModel * model,
00509 CbcNode * lastNode,
00510 OsiBranchingInformation * usefulInfo,
00511 int branchState);
00512 int analyze(CbcModel * model,double * results);
00514 void decrementCuts(int change=1);
00515
00517 void decrementParentCuts(int change=1);
00518
00520 void nullNodeInfo();
00529 void initializeInfo();
00530
00532 int branch(OsiSolverInterface * solver);
00533
00534
00535 inline CbcNodeInfo * nodeInfo() const
00536 {return nodeInfo_;}
00537
00538
00539 inline double objectiveValue() const
00540 { return objectiveValue_;}
00541 inline void setObjectiveValue(double value)
00542 { objectiveValue_=value;}
00544 inline int numberBranches() const
00545 { if (branch_)
00546 return (branch_->numberBranches()) ;
00547 else
00548 return (-1) ; }
00549
00550
00551
00552
00553
00554
00555
00556 int way() const;
00558 inline int depth() const
00559 {return depth_;}
00561 inline int numberUnsatisfied() const
00562 {return numberUnsatisfied_;}
00564 inline double sumInfeasibilities() const
00565 { return sumInfeasibilities_;}
00566
00567 inline double guessedObjectiveValue() const
00568 {return guessedObjectiveValue_;}
00569 inline void setGuessedObjectiveValue(double value)
00570 {guessedObjectiveValue_=value;}
00572 inline const OsiBranchingObject * branchingObject() const
00573 { return branch_;}
00575 inline OsiBranchingObject * modifiableBranchingObject() const
00576 { return branch_;}
00578 inline void setBranchingObject(OsiBranchingObject * branchingObject)
00579 { branch_ = branchingObject;}
00580
00581 private:
00582
00584 CbcNodeInfo * nodeInfo_;
00586 double objectiveValue_;
00588 double guessedObjectiveValue_;
00590 double sumInfeasibilities_;
00592 OsiBranchingObject * branch_;
00594 int depth_;
00596 int numberUnsatisfied_;
00597 };
00598
00599
00600 #endif