Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

tableau.h

Go to the documentation of this file.
00001 /*Copyright (C) 2006/2007, Professorship (p.p.) for Land Use Economics in the Tropics and
00002 Subtropics, Institute for Agricultural Economics and Social Sciences in the Tropics
00003 and Subtropics, University of Hohenheim, Stuttgart
00004 Thomas Berger, Lutz Göhring
00005 All rights reserved
00006 */
00007 #ifndef LP_OLD
00008 
00009 #ifndef __TABLEAU__
00010 #define __TABLEAU__
00011 
00012 #include <exception>
00013 #include "MatrixDouble.h"
00014 #include "CoinPackedMatrix.hpp"
00015 
00016 //auxiliary class for specially ordered set
00017 class SpeciallyOrderedSet
00018 {   
00019    public:
00020         int getType()const;
00021         int getPriority()const;
00022         int getNumberOfMembers()const;
00023         int* getColumnIndices()const;
00024         double* getDownPseudoCosts()const;
00025         double* getReferenceRow()const;
00026    
00027          virtual void print()const;
00028          virtual void readFile(FILE*);
00029          virtual void writeFile(FILE*)const;
00031          SpeciallyOrderedSet();
00033          SpeciallyOrderedSet(const SpeciallyOrderedSet&);
00035          SpeciallyOrderedSet& operator=(const SpeciallyOrderedSet&);
00037          virtual ~SpeciallyOrderedSet() {gutsOfDestructor(); }
00038    
00039    private:
00040          int numberofmembers;        //number of members in set
00041          int type;        //SOS type 1, 2, and 3 or type 4 (= integer set)
00042          int priority;        //priority
00043          int* columnindices;      //column indices
00044          double* downpseudocosts;  //down pseudocosts
00045          double* referencerow;  //reference row (in case of SOS type 1, 2, and 3) or up-pseudocosts (in case of integer set = SOS type 4)
00046    
00047          void gutsOfDestructor(){
00048                 if(columnindices){
00049                         delete [] columnindices;
00050                         columnindices = NULL;
00051                 }
00052                 if(downpseudocosts)     {
00053                 delete [] downpseudocosts;
00054                 downpseudocosts = NULL;
00055                 }
00056         if(referencerow){       
00057                 delete [] referencerow;
00058                 referencerow = NULL;
00059         }
00060          }
00062          template <class Type> void allocateVector(Type*& pointertovector, long int sizeofvector);
00063 };
00064 
00065 template <class Type>
00066 void SpeciallyOrderedSet::allocateVector(Type*& pointertovector, long int sizeofvector){
00067         if (sizeofvector > 0)
00068                 if(pointertovector== NULL){
00069                         try{
00070                                 pointertovector= new Type[sizeofvector];
00071                         }
00072                         catch(exception& exceptionObject){
00073                                 cerr << "Exception: "<< exceptionObject.what()<<endl;
00074                                 cerr << "Error in "<< typeid(*this).name()<<"::allocateVector(): cannot allocate memory for Type"<< typeid(*pointertovector).name()<<"["<<sizeofvector<<"]" << endl;
00075                                 exit(0);
00076                         }
00077                 }
00078                 else {
00079                         delete[] pointertovector;
00080                         pointertovector = NULL;
00081                         try{
00082                                 pointertovector = new Type[sizeofvector];
00083                         }
00084                         catch(exception& exceptionObject){
00085                                 cerr << "Exception: "<< exceptionObject.what()<<endl;
00086                                 cerr << "Error in "<< typeid(*this).name()<<"::allocateVector(): cannot allocate memory for Type "<< typeid(*pointertovector).name()<<"["<<sizeofvector<<"]" << endl;
00087                                 exit(0);
00088                         }
00089                 }
00090         else cerr       << "Warning in "<< typeid(*this).name()<<"::allocateVector(): nothing to allocate:"
00091                                 << "length of array of "<<typeid(*pointertovector).name()<<" is: "<<sizeofvector<<"!" << endl;
00092 }
00093 
00094 //neu 2004 column indices for performance indicators
00095 typedef struct
00096 {       int numA; //number of activities
00097         int col0; //first column index
00098 } infoPerf;
00099 
00100 
00101 //neu 2004 MILP fine-tuning parameters
00102 typedef struct
00103 {       int    rowLP;  //row (=constraint) index
00104         int    colLP;  //column (=activity) index
00105    double origV;  //original fine-tuned parameter
00106    double consV;        //parameter for consumption mode
00107 } infoFine;
00108 
00109 
00110 //neu 2004 TSPC model auxiliary structures -------------------------------------
00111 typedef struct
00112 {  //data per cropping activity
00113    int colLP;  //activity column in LP
00114    int colOp;  //output column in LP ("Preisertragsspalte")
00115    int typCr;  //type of crop (yes/no)
00116    int roYLD;  //grain yield row in LP
00117    int roYSM;  //stover energy row in LP
00118 
00119 } infoTSPC;
00120 
00121 
00122 typedef struct
00123 {  int colStv;    //'stover fed to livestock' column in LP
00124 } infoResi;
00125 
00126 //------------------------------------------------------------------------------
00127 //Auxiliary structure and class for LP tableau
00128 typedef struct
00129 {  int brows;     //start rows of block
00130    int bcols;     //start column of block
00131    MatrixDouble bctyp;  //block column types
00132    MatrixDouble bzrow;  //block z-row
00133    MatrixDouble bmat;   //block MatrixDouble
00134 } matblock;
00135 
00136 
00137 class tableau
00138 {  protected:
00139    int numblx;       //Number of MatrixDouble blocks
00140    int trans;        //transposed (yes/no)
00141    matblock** matblx;//Pointer to MatrixDouble block pointers
00142    MatrixDouble infoblx;   //Matrix containing info for each block
00143 
00144    public:
00145    tableau();
00146    virtual ~tableau()
00147    {  deallocateTableau();
00148    }
00149 
00150    virtual void printToScreen();
00151    virtual void allocateTableau(int, int);
00152    virtual CoinPackedMatrix getInfoBlock();//added by lutz
00153    virtual void setInfoBlock(CoinPackedMatrix infoblock,int nrows, int ncols);// added by lutz
00154    virtual void readTableauFromFile(FILE* strm,
00155          MatrixDouble& ctx, MatrixDouble& zrx, MatrixDouble& mtx, int nrows, int ncols);
00156    virtual void writeTableauIntoFile(FILE* strm,
00157          const MatrixDouble& ctx, const MatrixDouble& zrx, const MatrixDouble& mtx);
00158 
00159    virtual void allocateBlock(int, int, int);
00160    virtual void readBlockFromFile(int, FILE*);
00161    virtual void writeBlockIntoFile(int, FILE*);
00162 
00163    virtual int getNumBlocks();
00164    virtual int getIfTrans();
00165    virtual void writeInfoblxInFile(FILE* strm);
00166 
00167    virtual void copyBlockIntoZRow(int bn, MatrixDouble& zrx, int zrxc);
00168    virtual void copyBlockIntoMatrix(int bn, MatrixDouble& mtx, int mtxr, int mtxc);
00169 
00170    virtual void copyZRowIntoBlock(int bn, const MatrixDouble& zrx, int zrxc);
00171    virtual void copyMatrixIntoBlock(int bn, const MatrixDouble& mtx, int mtxr, int mtxc);
00172 
00173    virtual void deallocateTableau();
00174    virtual void deallocateBlock(int);
00175 
00176 };
00177 
00178 #endif
00179 
00180 #endif /* LP_OLD */

Generated on Thu Aug 28 12:38:45 2008 for MPMAS by  doxygen 1.3.9.1