sub.h

Go to the documentation of this file.
00001 
00042 #ifndef ABA_SUB_H
00043 #define ABA_SUB_H
00044 #include <limits.h>
00045 
00046 #include "abacus/string.h"
00047 #include "abacus/list.h"
00048 #include "abacus/bstack.h"
00049 #include "abacus/lp.h"
00050 #include "abacus/fsvarstat.h"
00051 #include "abacus/buffer.h"
00052 #include "abacus/vartype.h"
00053 #include "abacus/cputimer.h"
00054 
00055 class ABA_LPSUB;
00056 class ABA_TAILOFF;
00057 class ABA_BRANCHRULE;
00058 class ABA_LPVARSTAT;
00059 class ABA_VARIABLE;
00060 class ABA_MASTER;
00061 class ABA_INFEASCON;
00062 class ABA_CONSTRAINT;
00063 template<class BaseType, class CoType> class ABA_CUTBUFFER;
00064 template<class BaseType, class CoType> class ABA_ACTIVE;
00065 template<class BaseType, class CoType> class ABA_POOL;
00066 template<class BaseType, class CoType> class ABA_POOLSLOT;
00067 template<class BaseType, class CoType> class ABA_LPSOLUTION;
00068 
00069 #ifdef ABACUS_PARALLEL
00070 #include "abacus/message.h"
00071 #include "abacus/id.h"
00072 #include "abacus/subserver.h"
00073 #endif
00074 
00075   class  ABA_SUB :  public ABA_ABACUSROOT  {
00076     friend class ABA_MASTER;
00077     friend class ABA_BOUNDBRANCHRULE;
00078     friend class ABA_OPENSUB;
00079     friend class ABA_LPSOLUTION<ABA_CONSTRAINT, ABA_VARIABLE>;
00080     friend class ABA_LPSOLUTION<ABA_VARIABLE, ABA_CONSTRAINT>;
00081 #ifdef ABACUS_PARALLEL
00082     friend class ABA_SUBSERVER;
00083 #endif
00084     public:
00085 
00098       enum STATUS {Unprocessed, Active, Dormant, Processed, Fathomed};
00099 
00111       enum PHASE {Done, Cutting, Branching, Fathoming};
00112 
00136       ABA_SUB(
00137           ABA_MASTER *master, 
00138           double conRes, 
00139           double varRes, 
00140           double nnzRes,
00141           bool relativeRes = true,
00142           ABA_BUFFER<ABA_POOLSLOT<ABA_CONSTRAINT, ABA_VARIABLE> *> *constraints = 0,
00143           ABA_BUFFER<ABA_POOLSLOT<ABA_VARIABLE, ABA_CONSTRAINT> *> *variables = 0);
00144 
00153       ABA_SUB(ABA_MASTER *master, ABA_SUB *father, ABA_BRANCHRULE *branchRule);
00154 
00166       virtual ~ABA_SUB();
00167 #ifdef ABACUS_PARALLEL
00168 
00180       ABA_SUB(ABA_MASTER *master, ABA_MESSAGE &msg);
00181 
00194       virtual void pack(ABA_MESSAGE &msg) const;
00195 #endif
00196 
00199       inline bool forceExactSolver() const;
00200       
00203       int level() const;
00204 
00207       int id() const;
00208 #ifdef ABACUS_PARALLEL
00209       int fatherId() const;
00210 #endif
00211 
00214       STATUS status() const;
00215 
00218       int nVar() const;
00219 
00222       int maxVar() const;
00223 
00226       int nCon() const;
00227 
00230       int maxCon() const;
00231 
00234       double lowerBound() const;
00235 
00238       double upperBound() const;
00239 
00246       double dualBound() const;
00247 
00260       void dualBound(double x);
00261 
00264       const ABA_SUB *father() const;
00265 
00268       ABA_LPSUB *lp() const;
00269 
00277       void maxIterations(int max);
00278 
00281       ABA_ACTIVE<ABA_CONSTRAINT, ABA_VARIABLE> *actCon() const;
00282 
00285       ABA_ACTIVE<ABA_VARIABLE, ABA_CONSTRAINT> *actVar() const;
00286 
00291       ABA_CONSTRAINT *constraint(int i) const;
00292 
00298       ABA_SLACKSTAT *slackStat(int i) const;
00299 
00304       ABA_VARIABLE *variable(int i) const;
00305 
00315       double lBound(int i) const;
00316 
00325       void lBound(int i, double l);
00326 
00336       double uBound(int i) const;
00337 
00347       void uBound(int i, double u);
00348 
00360       ABA_FSVARSTAT *fsVarStat(int i) const;
00361 
00366       ABA_LPVARSTAT *lpVarStat(int i) const;
00367 
00372       double xVal(int i) const;
00373 
00378       double yVal(int i) const;
00379 
00387       bool ancestor(const ABA_SUB *sub) const;
00388       ABA_MASTER *master() const;
00389 
00399       void removeVars(ABA_BUFFER<int> &remove);
00400 
00409       void removeVar(int i);
00410 
00414       double nnzReserve() const;
00415 
00421       bool relativeReserve() const;
00422 
00425       ABA_BRANCHRULE *branchRule() const;
00426 
00440       bool objAllInteger();
00441 
00448       virtual void removeCons(ABA_BUFFER<int> &remove);
00449 
00457       virtual void removeCon(int i);
00458 
00470       int addConBufferSpace() const;
00471 
00483       int addVarBufferSpace() const;
00484 
00487       int nDormantRounds() const;
00488 
00502       void ignoreInTailingOff();
00503 
00517       virtual int addBranchingConstraint(
00518                             ABA_POOLSLOT<ABA_CONSTRAINT, ABA_VARIABLE> *slot);
00519 
00520     protected:
00521 
00542       virtual int addCons(ABA_BUFFER<ABA_CONSTRAINT*> &constraints,
00543                   ABA_POOL<ABA_CONSTRAINT, ABA_VARIABLE> *pool = 0,
00544                   ABA_BUFFER<bool> *keepInPool = 0,
00545                   ABA_BUFFER<double> *rank = 0);
00546 
00554       virtual int addCons(
00555                    ABA_BUFFER<ABA_POOLSLOT<ABA_CONSTRAINT, ABA_VARIABLE>*> &newCons);
00556 
00577       virtual int addVars(ABA_BUFFER<ABA_VARIABLE*> &variables,
00578                           ABA_POOL<ABA_VARIABLE, ABA_CONSTRAINT> *pool = 0,
00579                           ABA_BUFFER<bool> *keepInPool = 0,
00580                           ABA_BUFFER<double> *rank = 0);
00581 
00596       virtual int addVars(
00597                     ABA_BUFFER<ABA_POOLSLOT<ABA_VARIABLE, ABA_CONSTRAINT>*> &newVars);
00598 
00618       virtual int variablePoolSeparation(
00619                               int ranking = 0,
00620                               ABA_POOL<ABA_VARIABLE, ABA_CONSTRAINT> *pool = 0,
00621                               double minViolation = 0.001);
00622 
00643       virtual int constraintPoolSeparation(
00644                               int ranking = 0,
00645                               ABA_POOL<ABA_CONSTRAINT, ABA_VARIABLE> *pool = 0,
00646                               double minViolation = 0.001);
00647 
00652       virtual void activate();
00653 
00662       virtual void deactivate ();
00663 
00677       virtual int generateBranchRules(ABA_BUFFER<ABA_BRANCHRULE*> &rules);
00678 
00696       virtual int branchingOnVariable(ABA_BUFFER<ABA_BRANCHRULE*> &rules);
00697 
00713       virtual int selectBranchingVariable(int &variable);
00714 
00750       virtual int selectBranchingVariableCandidates(ABA_BUFFER<int> &candidates);
00751 
00766       virtual int selectBestBranchingSample(int nSamples,
00767                                             ABA_BUFFER<ABA_BRANCHRULE*> **samples);
00768 
00777       virtual void rankBranchingSample(ABA_BUFFER<ABA_BRANCHRULE*> &sample,
00778                                        ABA_ARRAY<double> &rank);
00779 
00790       virtual double rankBranchingRule(ABA_BRANCHRULE *branchRule);
00791 
00811       double lpRankBranchingRule(ABA_BRANCHRULE *branchRule, int iterLimit = -1);
00812 
00825       virtual int compareBranchingSampleRanks(ABA_ARRAY<double> &rank1,
00826                                               ABA_ARRAY<double> &rank2);
00827 
00844       int closeHalfExpensive(int &branchVar, ABA_VARTYPE::TYPE branchVarType);
00845 
00866       int closeHalfExpensive(ABA_BUFFER<int> &variables, 
00867                              ABA_VARTYPE::TYPE branchVarType);
00868 
00880       int closeHalf(int &branchVar, ABA_VARTYPE::TYPE branchVarType);
00881 
00894       int closeHalf(ABA_BUFFER<int> &branchVar, ABA_VARTYPE::TYPE branchVarType);
00895 
00907       int findNonFixedSet(ABA_BUFFER<int> &branchVar, 
00908                           ABA_VARTYPE::TYPE branchVarType);
00909 
00921       int findNonFixedSet(int &branchVar, ABA_VARTYPE::TYPE branchVarType);
00922 
00941       virtual int initMakeFeas(ABA_BUFFER<ABA_INFEASCON*> &infeasCon,
00942                                ABA_BUFFER<ABA_VARIABLE*> &newVars,
00943                                ABA_POOL<ABA_VARIABLE, ABA_CONSTRAINT> **pool);
00944 
00965       virtual int makeFeasible();
00966 
00979       virtual bool goodCol(ABA_COLUMN &col, ABA_ARRAY<double> &row,
00980                            double x, double lb, double ub);
00981 
00991       virtual void setByLogImp(ABA_BUFFER<int> &variable, 
00992                                ABA_BUFFER<ABA_FSVARSTAT*> &status);
00993 
01004       virtual bool feasible() = 0;
01005 
01017       bool integerFeasible();
01018 
01032       virtual bool primalSeparation();
01033 
01040       virtual int separate();
01041 
01054       virtual void conEliminate(ABA_BUFFER<int> &remove);
01055 
01062       virtual void nonBindingConEliminate(ABA_BUFFER<int> &remove);
01063 
01068       virtual void basicConEliminate(ABA_BUFFER<int> &remove);
01069 
01080       virtual void varEliminate(ABA_BUFFER<int> &remove);
01081 
01087       void redCostVarEliminate(ABA_BUFFER<int> &remove);
01088 
01095       virtual int pricing();
01096 
01108       virtual int improve(double &primalValue);
01109 
01117       virtual ABA_SUB *generateSon(ABA_BRANCHRULE *rule) = 0;
01118 
01123       bool boundCrash()    const;
01124 
01137       virtual bool pausing();
01138 
01142       bool infeasible();
01143 
01150       virtual void varRealloc(int newSize);
01151 
01158       virtual void conRealloc(int newSize);
01159 
01174       virtual ABA_LP::METHOD chooseLpMethod(int nVarRemoved, int nConRemoved,
01175                                             int nVarAdded, int nConAdded);
01176 
01191       virtual bool tailingOff();
01192 
01197       bool betterDual(double x) const;
01198 
01205       virtual void selectVars();
01206 
01213       virtual void selectCons();
01214 
01228       virtual int fixByRedCost(bool &newValues, bool saveCand);
01229 
01241       virtual void fixByLogImp(ABA_BUFFER<int> &variable, 
01242                                ABA_BUFFER<ABA_FSVARSTAT*> &status);
01243 
01260       virtual int fixAndSet(bool &newValues);
01261 
01276       virtual int fixing(bool &newValues, bool saveCand = false);
01277 
01290       virtual int setting(bool &newValues);
01291 
01297       virtual int setByRedCost();
01298 
01327       virtual void fathom(bool reoptimize);
01328 
01336       virtual bool fixAndSetTime();
01337 
01355       virtual int fix(int i, ABA_FSVARSTAT *newStat, bool &newValue);
01356 
01370       virtual int set(int i, ABA_FSVARSTAT *newStat, bool &newValue);
01371 
01384        virtual int set(int i, ABA_FSVARSTAT::STATUS newStat, bool &newValue);
01385 
01399       virtual int set(int i, ABA_FSVARSTAT::STATUS newStat, double value,
01400                       bool &newValue);
01401 
01410       virtual double dualRound(double x);
01411 
01416       virtual double guarantee();
01417 
01422       virtual bool guaranteed();
01423 
01430       virtual bool removeNonLiftableCons();
01431 
01440       virtual int prepareBranching(bool &lastIteration);
01441 
01454       virtual void fathomTheSubTree();
01455 
01477       virtual int optimize();
01478 
01496       virtual void reoptimize();
01497 
01503       virtual void initializeVars(int maxVar);
01504 
01510       virtual void initializeCons(int maxCon);
01511 
01531       virtual PHASE branching();
01532 
01560       virtual PHASE fathoming();
01561 
01576       virtual PHASE cutting();
01577 
01587       virtual ABA_LPSUB *generateLp();
01588 
01602       virtual int initializeLp();
01603 
01620       virtual int solveLp();
01621 
01631       virtual bool exceptionFathom();
01632 
01642       virtual bool exceptionBranch();
01643 
01649       virtual bool solveApproxNow();
01650 
01656       ABA_MASTER *master_;
01657 
01660       ABA_ACTIVE<ABA_CONSTRAINT, ABA_VARIABLE> *actCon_;
01661 
01664       ABA_ACTIVE<ABA_VARIABLE, ABA_CONSTRAINT> *actVar_;
01665 
01668       ABA_SUB *father_;
01669 
01672       ABA_LPSUB *lp_;
01673 
01681       ABA_ARRAY<ABA_FSVARSTAT*> *fsVarStat_;
01682 
01686       ABA_ARRAY<ABA_LPVARSTAT*> *lpVarStat_;
01687 
01690       ABA_ARRAY<double> *lBound_;
01691 
01694       ABA_ARRAY<double> *uBound_;
01695 
01699       ABA_ARRAY<ABA_SLACKSTAT*> *slackStat_;
01700 
01703       ABA_TAILOFF *tailOff_;
01704 
01707       double dualBound_;
01708 
01711       int nIter_;
01712 
01715       int lastIterConAdd_;
01716 
01719       int lastIterVarAdd_;
01720 
01723       ABA_BRANCHRULE *branchRule_;
01724 
01729       bool allBranchOnSetVars_;
01730 
01733       ABA_LP::METHOD lpMethod_;
01734 
01737       ABA_CUTBUFFER<ABA_VARIABLE, ABA_CONSTRAINT> *addVarBuffer_;
01738 
01741       ABA_CUTBUFFER<ABA_CONSTRAINT, ABA_VARIABLE> *addConBuffer_;
01742 
01746       ABA_BUFFER<int> *removeVarBuffer_;
01747 
01751       ABA_BUFFER<int> *removeConBuffer_;
01752 
01755       double *xVal_;
01756 
01759       double *yVal_;
01760 
01764       double *bInvRow_;
01765 
01768       int infeasCon_;
01769 
01772       int infeasVar_;
01773 
01776       bool genNonLiftCons_;
01777     private:
01778 
01781       virtual int _separate();
01782 
01790       virtual int _conEliminate();
01791 
01796       virtual int _varEliminate();
01797 
01825       virtual int _pricing(bool &newValues, bool doFixSet = true);
01826 
01842       virtual int _improve(double &primalValue);
01843 
01851       virtual int _fixByLogImp(bool &newValues);
01852 
01853 
01859       virtual void updateBoundInLp(int i);
01860 
01864       virtual double fixSetNewBound(int i);
01865 
01872       virtual void newDormantRound();
01873 
01914       virtual PHASE _activate();
01915 
01929       virtual void _deactivate();
01930 
01947       virtual int _initMakeFeas();
01948 
01957       virtual int _makeFeasible();
01958 
01970       virtual int _setByLogImp(bool &newValues);
01971 
01976       virtual void infeasibleSub();
01977 
01980       virtual void getBase();
01981 
01989       virtual void activateVars(ABA_BUFFER<ABA_POOLSLOT<ABA_VARIABLE, ABA_CONSTRAINT>*> &newVars);
01990 
01999       virtual void addVarsToLp(ABA_BUFFER<ABA_POOLSLOT<ABA_VARIABLE, ABA_CONSTRAINT>*> &newVars,
02000                               ABA_BUFFER<ABA_FSVARSTAT*> *localStatus = 0);
02001 
02006       virtual void _selectVars(ABA_BUFFER<ABA_POOLSLOT<ABA_VARIABLE, ABA_CONSTRAINT>*> &newVars);
02007 
02012       virtual void _selectCons(ABA_BUFFER<ABA_POOLSLOT<ABA_CONSTRAINT, ABA_VARIABLE>*> &newCons);
02013 
02014 /* Removes the variables with numbers \a remove from the set of active variables.
02015  */
02016       virtual int _removeVars(ABA_BUFFER<int> &remove);
02017 
02020       virtual int _removeCons(ABA_BUFFER<int> &remove);
02021 
02024       int level_;
02025 
02028       int id_;
02029 #ifdef ABACUS_PARALLEL
02030       int fatherId_;
02031 #endif
02032 
02035       STATUS status_;
02036 
02039       ABA_BUFFER<ABA_SUB*> *sons_;
02040 
02043       int maxIterations_;
02044 
02047       int nOpt_;
02048 
02056       bool relativeReserve_;
02057 
02060       double varReserve_;
02061 
02064       double conReserve_;
02065 
02068       double nnzReserve_;
02069 
02073       int nDormantRounds_;
02074 
02080       bool activated_;
02081 
02086       bool ignoreInTailingOff_;
02089       ABA_LP::METHOD lastLP_;
02090 
02091       ABA_CPUTIMER localTimer_;
02092 
02096       bool forceExactSolver_;
02097  
02098       ABA_SUB(const ABA_SUB &rhs);
02099       const ABA_SUB &operator=(const ABA_SUB &rhs);
02100   };
02101 
02102 
02103 #include "abacus/constraint.h"
02104 #include "abacus/variable.h"
02105 #include "abacus/active.h"
02106 #include "abacus/lpsub.h"
02107 
02108 inline double ABA_SUB::xVal(int i) const
02109   {
02110     return xVal_[i];
02111   }
02112 
02113 inline double ABA_SUB::yVal(int i) const
02114   {
02115     return yVal_[i];
02116   }
02117 
02118 inline ABA_MASTER *ABA_SUB::master() const
02119   {
02120     return master_;
02121   }
02122 
02123 inline void ABA_SUB::removeVar(int i)
02124   {
02125     removeVarBuffer_->push(i);
02126   }
02127 
02128 inline double ABA_SUB::nnzReserve() const
02129   {
02130     return nnzReserve_;
02131   }
02132 
02133 inline bool ABA_SUB::relativeReserve() const
02134   {
02135     return relativeReserve_;
02136   }
02137 
02138 inline ABA_BRANCHRULE *ABA_SUB::branchRule() const
02139   {
02140     return branchRule_;
02141   }
02142 
02143 inline int ABA_SUB::addBranchingConstraint(ABA_POOLSLOT<ABA_CONSTRAINT, ABA_VARIABLE> *slot)
02144   {
02145     return addConBuffer_->insert(slot, true);
02146   }
02147 
02148 inline int ABA_SUB::addConBufferSpace() const
02149   {
02150     return addConBuffer_->space();
02151   }
02152 
02153 inline int ABA_SUB::addVarBufferSpace() const
02154   {
02155     return addVarBuffer_->space();
02156   }
02157 
02158 inline int ABA_SUB::nDormantRounds() const
02159   {
02160     return nDormantRounds_;
02161   }
02162 
02163 inline void ABA_SUB::newDormantRound()
02164   {
02165     ++nDormantRounds_;
02166   }
02167 
02168 inline double ABA_SUB::lBound(int i) const
02169   {
02170     return (*lBound_)[i];
02171   }
02172 
02173 inline void ABA_SUB::lBound(int i, double x)
02174   {
02175     (*lBound_)[i] = x;
02176     if (lp_)
02177       lp_->changeLBound(i, x);
02178   }
02179 
02180 inline double ABA_SUB::uBound(int i) const
02181   {
02182     return (*uBound_)[i];
02183   }
02184 
02185 inline void ABA_SUB::uBound(int i, double x)
02186   {
02187     (*uBound_)[i] = x;
02188     if (lp_)
02189       lp_->changeUBound(i, x);
02190   }
02191 
02192 inline ABA_FSVARSTAT *ABA_SUB::fsVarStat(int i) const
02193   {
02194     return (*fsVarStat_)[i];
02195   }
02196 
02197 inline ABA_LPVARSTAT *ABA_SUB::lpVarStat(int i) const
02198   {
02199     return (*lpVarStat_)[i];
02200   }
02201 
02202 inline ABA_SLACKSTAT *ABA_SUB::slackStat(int i) const
02203   {
02204     return (*slackStat_)[i];
02205   }
02206 
02207 inline bool ABA_SUB::forceExactSolver() const 
02208 {
02209    return forceExactSolver_;
02210 }
02211 
02212 inline int ABA_SUB::level() const
02213   {
02214     return level_;
02215   }
02216 
02217 inline int ABA_SUB::id() const
02218   {
02219     return id_;
02220   }
02221 
02222 #ifdef ABACUS_PARALLEL
02223 inline int ABA_SUB::fatherId() const
02224   {
02225     return fatherId_;
02226   }
02227 #endif
02228 
02229 inline double ABA_SUB::dualBound() const
02230   {
02231     return dualBound_;
02232   }
02233 
02234 inline const ABA_SUB *ABA_SUB::father() const
02235   {
02236     return father_;
02237   }
02238 
02239 inline ABA_LPSUB *ABA_SUB::lp() const
02240   {
02241     return lp_;
02242   }
02243 
02244 inline ABA_SUB::STATUS ABA_SUB::status() const
02245   {
02246     return status_;
02247   }
02248 
02249 inline ABA_ACTIVE<ABA_CONSTRAINT, ABA_VARIABLE> *ABA_SUB::actCon() const
02250   {
02251     return actCon_;
02252   }
02253 
02254 inline ABA_ACTIVE<ABA_VARIABLE, ABA_CONSTRAINT> *ABA_SUB::actVar() const
02255   {
02256     return actVar_;
02257   }
02258 
02259 inline int ABA_SUB::nVar() const
02260   {
02261     return actVar_->number();
02262   }
02263 
02264 inline int ABA_SUB::nCon() const
02265   {
02266     return actCon_->number();
02267   }
02268 
02269 inline int ABA_SUB::maxVar() const
02270   {
02271     return actVar_->max();
02272   }
02273 
02274 inline int ABA_SUB::maxCon() const
02275   {
02276     return actCon_->max();
02277   }
02278 
02279 
02280 #endif  // ABA_SUB_H
02281 

Generated on Tue Aug 14 18:09:54 2007 for ABACUS by  doxygen 1.5.1