osiif.h

Go to the documentation of this file.
00001 
00029 #ifndef OSIIF_H
00030 #define OSIIF_H
00031 #include "abacus/lp.h"
00032 #include "abacus/optsense.h"
00033 #include "abacus/lpvarstat.h"
00034 #include "abacus/slackstat.h"
00035 #include "abacus/csense.h"
00036 #include "abacus/osiinclude.h"
00037 #include <CoinPackedVector.hpp>
00038 #include <CoinWarmStartBasis.hpp>
00039 #include <CoinBuild.hpp>
00040 
00041 class ABA_LPMASTEROSI;
00042 
00043   class  ABA_OSIIF :  public virtual ABA_LP  {
00044     public:
00045 
00053     ABA_OSIIF(ABA_MASTER *master);
00054 
00068       ABA_OSIIF(ABA_MASTER *master,
00069                   ABA_OPTSENSE sense, 
00070                   int nRow, 
00071                   int maxRow, 
00072                   int nCol, 
00073                   int maxCol,
00074                   ABA_ARRAY<double> &obj, 
00075                   ABA_ARRAY<double> &lb, 
00076                   ABA_ARRAY<double> &ub,
00077                   ABA_ARRAY<ABA_ROW*> &rows);
00078 
00080       virtual ~ABA_OSIIF();
00081 
00085       enum SOLVERTYPE {Exact, Approx};
00086 
00087       inline SOLVERTYPE currentSolverType()
00088       { return currentSolverType_; }
00089 
00090       inline OsiSolverInterface* osiLP();
00091          
00092 
00093     private:
00094 
00095       /****************************************************************
00096        * Pointer to the Osi solver interface. It is later typecast to 
00097        * a pointer to an object of a solver specific derived class.
00098        * See osiif.cc, ABA_OSIIF::_initialize.
00099        ****************************************************************/
00100       OsiSolverInterface *osiLP_;
00101 
00102       /***************************************************
00103        * Helper functions to free allocated memory
00104        **************************************************/
00105 
00106       void freeDouble(const double*&);
00107 
00108       void freeDouble(double*&);
00109 
00110       void freeInt(int*&);
00111       
00112       void freeChar(char*&);
00113 
00114       void freeChar(const char*&);
00115 
00116       void freeStatus(CoinWarmStartBasis::Status*&);
00117 
00132       virtual void    _initialize(ABA_OPTSENSE sense, int nRow, int maxRow,
00133                                   int nCol, int maxCol,
00134                                   ABA_ARRAY<double> &obj, ABA_ARRAY<double> &lBound,
00135                                   ABA_ARRAY<double> &uBound, ABA_ARRAY<ABA_ROW*> &rows);
00136 
00142       virtual void _loadBasis(ABA_ARRAY<ABA_LPVARSTAT::STATUS> &lpVarStat,
00143                               ABA_ARRAY<ABA_SLACKSTAT::STATUS> &slackStat);
00144 
00149       virtual ABA_OPTSENSE _sense() const;
00150 
00156       virtual void     _sense(const ABA_OPTSENSE &newSense);
00157 
00162       virtual int      _nRow()  const;
00163 
00168       virtual int      _maxRow() const;
00169 
00174       virtual int      _nCol() const;
00175 
00180       virtual int      _maxCol() const;
00181 
00186       virtual double   _obj(int i) const; 
00187 
00192       virtual double   _lBound(int i) const;
00193 
00198       virtual double   _uBound(int i) const;
00199 
00204       virtual double   _rhs(int i) const;
00205 
00210       virtual void     _row(int i, ABA_ROW &r) const;
00211 
00217       virtual int      _nnz() const;
00218 
00219 
00224       virtual OPTSTAT _primalSimplex();
00225 
00230       virtual OPTSTAT _dualSimplex();
00231 
00236       virtual OPTSTAT _barrier(bool doCrossover);
00237 
00242       virtual OPTSTAT _approx();
00243 
00248       virtual double _value() const;
00249 
00254       virtual double _xVal(int i);
00255 
00260       virtual double _barXVal(int i);
00261 
00266       virtual double _reco(int i);
00267 
00272       virtual double _slack(int i);
00273 
00278       virtual double _yVal(int i);
00279 
00284       virtual ABA_LPVARSTAT::STATUS _lpVarStat(int i);
00285 
00290       virtual ABA_SLACKSTAT::STATUS _slackStat(int i);
00291      
00308       virtual int  _getInfeas(int &infeasRow, int &infeasCol, double *bInvRow);
00309 
00314       virtual void _remRows(ABA_BUFFER<int> &ind);
00315 
00320       virtual void _addRows(ABA_BUFFER<ABA_ROW*> &newRows) ;
00321 
00326       virtual void _remCols(ABA_BUFFER<int> &vars);
00327 
00332       virtual void _addCols(ABA_BUFFER<ABA_COLUMN*> &newVars);
00333 
00340       virtual void _changeRhs(ABA_ARRAY<double> &newRhs);
00341 
00346       virtual void _changeLBound(int i, double newLb);
00347 
00352       virtual void _changeUBound(int i, double newUb);
00353 
00365       virtual int _pivotSlackVariableIn(ABA_BUFFER<int> &rows);
00366 
00372       void              getSol();
00373 
00377       char              csense2osi(ABA_CSENSE *sense)             const;
00378 
00382       ABA_CSENSE::SENSE     osi2csense(char sense)                const;
00383 
00386       CoinWarmStartBasis::Status lpVarStat2osi(ABA_LPVARSTAT::STATUS stat) const;
00387 
00390       ABA_LPVARSTAT::STATUS osi2lpVarStat(CoinWarmStartBasis::Status stat)               const;
00391 
00394       CoinWarmStartBasis::Status slackStat2osi(ABA_SLACKSTAT::STATUS stat) const;
00395 
00398       ABA_SLACKSTAT::STATUS osi2slackStat(CoinWarmStartBasis::Status stat)               const;
00399       
00402       OsiSolverInterface* getDefaultInterface();
00403 
00406       OsiSolverInterface* switchInterfaces(SOLVERTYPE newMethod);
00407 
00411       void loadDummyRow(OsiSolverInterface* s2, const double* lbounds, const double* ubounds, const double* objectives);
00412 
00425       void _rowRealloc(int newSize);
00426 
00433       void _colRealloc(int newSize);
00434      
00444       virtual int _setSimplexIterationLimit(int limit);
00445       
00453       virtual int _getSimplexIterationLimit(int &limit);
00454       ABA_LPMASTEROSI *lpMasterOsi_;
00455 
00458       double  value_;
00459 
00463       const double *xVal_;
00464       const double *barXVal_;
00465 
00469       const double *reco_;
00470 
00474       const double *yVal_;
00475 
00479       const char *cStat_;
00480 
00483       int numCols_;
00484 
00487       int numRows_;
00488 
00492       const char *rStat_;
00493 
00496       const double *rhs_;
00497  
00500       const double *rowactivity_;
00501 
00504       const char *rowsense_;
00505 
00508       const double *colupper_;
00509       
00512       const double *collower_;
00513 
00516       const double *objcoeff_;
00517 
00520       CoinWarmStartBasis *ws_;
00521 
00524       SOLVERTYPE currentSolverType_;
00525 
00526       ABA_OSIIF(const ABA_OSIIF &rhs);
00527       const ABA_OSIIF &operator=(const ABA_OSIIF &rhs);
00528 
00529 inline void
00530 convertSenseToBound(double inf, const char sense, const double right,
00531                                          const double range,
00532                                          double& lower, double& upper) const
00533  {
00534    switch (sense) {
00535    case 'E':
00536      lower = upper = right;
00537      break;
00538    case 'L':
00539      lower = -inf;
00540      upper = right;
00541      break;
00542    case 'G':
00543      lower = right;
00544      upper = inf;
00545      break;
00546    case 'R':
00547      lower = right - range;
00548      upper = right;
00549      break;
00550    case 'N':
00551      lower = -inf;
00552      upper = inf;
00553      break;
00554    }
00555  }
00556 
00557   };
00558 
00559 inline OsiSolverInterface* ABA_OSIIF::osiLP()
00560 { return osiLP_; }
00561 #endif

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