00001 00056 #ifndef ABA_LP_H 00057 #define ABA_LP_H 00058 00059 #include "abacus/array.h" 00060 #include "abacus/optsense.h" 00061 #include "abacus/lpvarstat.h" 00062 #include "abacus/slackstat.h" 00063 #include "abacus/cputimer.h" 00064 00065 class ABA_MASTER; 00066 class ABA_SPARVEC; 00067 class ABA_ROW; 00068 class ABA_COLUMN; 00069 00070 class ABA_LP : public ABA_ABACUSROOT { 00071 public: 00072 00087 enum OPTSTAT{Optimal, Unoptimized, Error, 00088 Feasible, Infeasible, Unbounded}; 00089 00096 enum SOLSTAT{Available, Missing}; 00097 00107 enum METHOD {Primal, Dual, BarrierAndCrossover, BarrierNoCrossover, Approximate}; 00108 00114 ABA_LP (ABA_MASTER *master); 00115 00117 virtual ~ABA_LP (); 00118 00135 friend ostream &operator<<(ostream& out, const ABA_LP& rhs); 00136 00160 void initialize(ABA_OPTSENSE sense, int nRow, int maxRow, 00161 int nCol, int maxCol, 00162 ABA_ARRAY<double> &obj, ABA_ARRAY<double> &lBound, 00163 ABA_ARRAY<double> &uBound, ABA_ARRAY<ABA_ROW*> &rows); 00164 00172 void initialize(ABA_OPTSENSE sense, int nRow, int maxRow, 00173 int nCol, int maxCol, 00174 ABA_ARRAY<double> &obj, ABA_ARRAY<double> &lBound, 00175 ABA_ARRAY<double> &uBound, ABA_ARRAY<ABA_ROW*> &rows, 00176 ABA_ARRAY<ABA_LPVARSTAT::STATUS> &lpVarStat, 00177 ABA_ARRAY<ABA_SLACKSTAT::STATUS> &slackStat); 00178 00184 virtual void loadBasis(ABA_ARRAY<ABA_LPVARSTAT::STATUS> &lpVarStat, 00185 ABA_ARRAY<ABA_SLACKSTAT::STATUS> &slackStat); 00186 ABA_OPTSENSE sense() const; 00187 void sense(const ABA_OPTSENSE &newSense); 00188 int nRow() const; 00189 int maxRow() const; 00190 int nCol() const; 00191 int maxCol() const; 00192 int nnz() const; 00193 double obj(int i) const; 00194 double lBound(int i) const; 00195 double uBound(int i) const; 00196 void row(int i, ABA_ROW &r) const; 00197 double rhs(int i) const; 00198 virtual double value() const; 00199 virtual double xVal(int i); 00200 virtual double barXVal(int i); 00201 virtual double reco(int i); 00202 virtual double yVal(int c); 00203 virtual double slack(int c); 00204 SOLSTAT xValStatus() const; 00205 SOLSTAT barXValStatus() const; 00206 SOLSTAT yValStatus() const; 00207 SOLSTAT recoStatus() const; 00208 SOLSTAT slackStatus() const; 00209 SOLSTAT basisStatus() const; 00210 int nOpt() const; 00211 virtual bool infeasible() const; 00212 00238 virtual int getInfeas(int &infeasRow, int &infeasCol, double *bInvRow); 00239 virtual ABA_LPVARSTAT::STATUS lpVarStat(int i); 00240 virtual ABA_SLACKSTAT::STATUS slackStat(int i); 00241 00248 virtual OPTSTAT optimize(METHOD method); 00249 00254 void remRows(ABA_BUFFER<int> &ind); 00255 00263 void addRows(ABA_BUFFER<ABA_ROW*> &newRows); 00264 00269 void remCols(ABA_BUFFER<int> &cols); 00270 00278 void addCols(ABA_BUFFER<ABA_COLUMN*> &newCols); 00279 00284 void changeRhs(ABA_ARRAY<double> &newRhs); 00285 00291 virtual void changeLBound(int i, double newLb); 00292 00298 virtual void changeUBound(int i, double newUb); 00299 00308 virtual int pivotSlackVariableIn(ABA_BUFFER<int> &rows); 00309 00314 void rowRealloc(int newSize); 00315 00320 void colRealloc(int newSize); 00321 00330 int writeBasisMatrix(const char *fileName); 00331 00339 int setSimplexIterationLimit(int limit); 00340 00346 int getSimplexIterationLimit(int &limit); 00347 ABA_CPUTIMER* lpSolverTime() { return &lpSolverTime_; } 00348 00349 protected: 00350 00359 void colsNnz(int nRow, ABA_ARRAY<ABA_ROW*> &rows, ABA_ARRAY<int> &nnz); 00360 00375 void rows2cols(int nRow, ABA_ARRAY<ABA_ROW*> &rows, 00376 ABA_ARRAY<ABA_SPARVEC*> &cols); 00377 00382 void rowRangeCheck(int r) const; 00383 00388 void colRangeCheck(int i) const; 00389 00393 virtual ABA_OPTSENSE _sense() const = 0; 00394 virtual void _sense(const ABA_OPTSENSE &newSense) = 0; 00395 00399 virtual int _nRow() const = 0; 00400 00404 virtual int _maxRow() const = 0; 00405 00409 virtual int _nCol() const = 0; 00410 00414 virtual int _maxCol() const = 0; 00415 00421 virtual int _nnz() const = 0; 00422 00427 virtual double _obj(int i) const = 0; 00428 00432 virtual double _lBound(int i) const = 0; 00433 00437 virtual double _uBound(int i) const = 0; 00438 00442 virtual double _rhs(int i) const = 0; 00443 00447 virtual void _row(int i, ABA_ROW &r) const = 0; 00448 00462 virtual void _initialize(ABA_OPTSENSE sense, int nRow, int maxRow, 00463 int nCol, int maxCol, 00464 ABA_ARRAY<double> &obj, ABA_ARRAY<double> &lBound, 00465 ABA_ARRAY<double> &uBound, ABA_ARRAY<ABA_ROW*> &rows) = 0; 00466 00472 virtual void _loadBasis(ABA_ARRAY<ABA_LPVARSTAT::STATUS> &lpVarStat, 00473 ABA_ARRAY<ABA_SLACKSTAT::STATUS> &slackStat) = 0; 00474 00479 virtual OPTSTAT _primalSimplex() = 0; 00480 00485 virtual OPTSTAT _dualSimplex() = 0; 00486 00491 virtual OPTSTAT _barrier(bool doCrossover) = 0; 00492 00497 virtual OPTSTAT _approx() = 0; 00498 00503 virtual double _value() const = 0; 00504 00509 virtual double _xVal(int i) = 0; 00510 virtual double _barXVal(int i) = 0; 00511 00515 virtual double _reco(int i) = 0; 00516 00520 virtual double _slack(int i) = 0; 00521 00526 virtual double _yVal(int i) = 0; 00527 00532 virtual ABA_LPVARSTAT::STATUS _lpVarStat(int i) = 0; 00533 00538 virtual ABA_SLACKSTAT::STATUS _slackStat(int i) = 0; 00539 00552 virtual int _getInfeas(int &infeasRow, int &infeasCol, 00553 double *bInvRow) = 0; 00554 00559 virtual void _remRows(ABA_BUFFER<int> &ind) = 0; 00560 00565 virtual void _addRows(ABA_BUFFER<ABA_ROW*> &newRows) = 0; 00566 00571 virtual void _remCols(ABA_BUFFER<int> &vars) = 0; 00572 00577 virtual void _addCols(ABA_BUFFER<ABA_COLUMN*> &newCols) = 0; 00578 00583 virtual void _changeRhs(ABA_ARRAY<double> &newRhs) = 0; 00584 00589 virtual void _changeLBound(int i, double newLb) = 0; 00590 00595 virtual void _changeUBound(int i, double newUb) = 0; 00596 00606 virtual int _pivotSlackVariableIn(ABA_BUFFER<int> &rows) = 0; 00607 00613 virtual void _rowRealloc(int newSize) = 0; 00614 00619 virtual void _colRealloc(int newSize) = 0; 00620 00629 virtual int _setSimplexIterationLimit(int limit) = 0; 00630 00640 virtual int _getSimplexIterationLimit(int &limit) = 0; 00641 00644 ABA_MASTER *master_; 00645 00648 OPTSTAT optStat_; 00649 00654 SOLSTAT xValStatus_; 00655 SOLSTAT barXValStatus_; 00656 00662 SOLSTAT yValStatus_; 00663 00668 SOLSTAT recoStatus_; 00669 00675 SOLSTAT slackStatus_; 00676 00683 SOLSTAT basisStatus_; 00684 00687 int nOpt_; 00688 ABA_CPUTIMER lpSolverTime_; 00689 00690 private: 00691 00699 void initPostOpt(); 00700 ABA_LP(const ABA_LP &rhs); 00701 const ABA_LP &operator=(const ABA_LP &rhs); 00702 }; 00703 00704 00705 inline ABA_OPTSENSE ABA_LP::sense() const 00706 { 00707 return _sense(); 00708 } 00709 00710 inline void ABA_LP::sense(const ABA_OPTSENSE &newSense) 00711 { 00712 _sense(newSense); 00713 } 00714 00715 inline int ABA_LP::nRow() const 00716 { 00717 return _nRow(); 00718 } 00719 00720 inline int ABA_LP::maxRow() const 00721 { 00722 return _maxRow(); 00723 } 00724 00725 inline int ABA_LP::nCol() const 00726 { 00727 return _nCol(); 00728 } 00729 00730 inline int ABA_LP::maxCol() const 00731 { 00732 return _maxCol(); 00733 } 00734 00735 inline int ABA_LP::nnz() const 00736 { 00737 return _nnz(); 00738 } 00739 00740 inline double ABA_LP::obj(int i) const 00741 { 00742 #ifdef ABACUSSAFE 00743 colRangeCheck(i); 00744 #endif 00745 return _obj(i); 00746 } 00747 00748 inline double ABA_LP::lBound(int i) const 00749 { 00750 #ifdef ABACUSSAFE 00751 colRangeCheck(i); 00752 #endif 00753 return _lBound(i); 00754 } 00755 00756 inline double ABA_LP::uBound(int i) const 00757 { 00758 #ifdef ABACUSSAFE 00759 colRangeCheck(i); 00760 #endif 00761 return _uBound(i); 00762 } 00763 00764 inline void ABA_LP::row(int i, ABA_ROW &r) const 00765 { 00766 #ifdef ABACUSSAFE 00767 rowRangeCheck(i); 00768 #endif 00769 _row(i, r); 00770 } 00771 00772 inline double ABA_LP::rhs(int i) const 00773 { 00774 #ifdef ABACUSSAFE 00775 rowRangeCheck(i); 00776 #endif 00777 return _rhs(i); 00778 } 00779 00780 inline double ABA_LP::value() const 00781 { 00782 return _value(); 00783 } 00784 00785 inline double ABA_LP::xVal(int i) 00786 { 00787 #ifdef ABACUSSAFE 00788 colRangeCheck(i); 00789 #endif 00790 return _xVal(i); 00791 } 00792 00793 inline double ABA_LP::barXVal(int i) 00794 { 00795 #ifdef ABACUSSAFE 00796 colRangeCheck(i); 00797 #endif 00798 return _barXVal(i); 00799 } 00800 00801 inline double ABA_LP::reco(int i) 00802 { 00803 #ifdef ABACUSSAFE 00804 colRangeCheck(i); 00805 #endif 00806 return _reco(i); 00807 } 00808 00809 inline double ABA_LP::yVal(int c) 00810 { 00811 #ifdef ABACUSSAFE 00812 rowRangeCheck(c); 00813 #endif 00814 return _yVal(c); 00815 } 00816 00817 inline double ABA_LP::slack(int c) 00818 { 00819 #ifdef ABACUSSAFE 00820 rowRangeCheck(c); 00821 #endif 00822 return _slack(c); 00823 } 00824 00825 inline ABA_LP::SOLSTAT ABA_LP::xValStatus() const 00826 { 00827 return xValStatus_; 00828 } 00829 00830 inline ABA_LP::SOLSTAT ABA_LP::barXValStatus() const 00831 { 00832 return barXValStatus_; 00833 } 00834 00835 inline ABA_LP::SOLSTAT ABA_LP::recoStatus() const 00836 { 00837 return recoStatus_; 00838 } 00839 00840 inline ABA_LP::SOLSTAT ABA_LP::yValStatus() const 00841 { 00842 return yValStatus_; 00843 } 00844 00845 inline ABA_LP::SOLSTAT ABA_LP::slackStatus() const 00846 { 00847 return slackStatus_; 00848 } 00849 00850 inline ABA_LP::SOLSTAT ABA_LP::basisStatus() const 00851 { 00852 return basisStatus_; 00853 } 00854 00855 inline int ABA_LP::nOpt() const 00856 { 00857 return nOpt_; 00858 } 00859 00860 inline bool ABA_LP::infeasible() const 00861 { 00862 if (optStat_ == Infeasible) return true; 00863 else return false; 00864 } 00865 00866 inline ABA_LPVARSTAT::STATUS ABA_LP::lpVarStat(int i) 00867 { 00868 #ifdef ABACUSSAFE 00869 colRangeCheck(i); 00870 #endif 00871 return _lpVarStat(i); 00872 } 00873 00874 inline ABA_SLACKSTAT::STATUS ABA_LP::slackStat(int i) 00875 { 00876 #ifdef ABACUSSAFE 00877 rowRangeCheck(i); 00878 #endif 00879 return _slackStat(i); 00880 } 00881 00882 00883 #endif // ABA_LP_H 00884