/home/coin/SVN-release/Cbc-1.1.1/CoinUtils/src/CoinLpIO.hpp

Go to the documentation of this file.
00001 // Last edit: 2/10/07
00002 //
00003 // Name:     CoinLpIO.hpp; Support for Lp files
00004 // Author:   Francois Margot
00005 //           Tepper School of Business
00006 //           Carnegie Mellon University, Pittsburgh, PA 15213
00007 //           email: fmargot@andrew.cmu.edu
00008 // Date:     12/28/03
00009 //-----------------------------------------------------------------------------
00010 // Copyright (C) 2003, Francois Margot, International Business Machines
00011 // Corporation and others.  All Rights Reserved.
00012 
00013 #include <cstdio>
00014 
00015 class CoinPackedMatrix;
00016 
00017 typedef int COINColumnIndex;
00018 
00089 class CoinLpIO {
00090 
00091 public:
00092 
00095 
00096   CoinLpIO(); 
00097   
00099   ~CoinLpIO();
00100 
00106   void freePreviousNames(const int section);
00107 
00109   void freeAll();
00111 
00114     inline void
00115     convertBoundToSense(const double lower, const double upper,
00116                         char& sense, double& right, double& range) const;
00117 
00120 
00122   const char * getProblemName() const;
00123 
00125   int getNumCols() const;
00126 
00128   int getNumRows() const;
00129 
00131   int getNumElements() const;
00132   
00134   const double * getColLower() const;
00135 
00137   const double * getColUpper() const;
00138 
00140   const double * getRowLower() const;
00141   
00143   const double * getRowUpper() const;
00153   const char * getRowSense() const;
00154   
00166   const double * getRightHandSide() const;
00167   
00181   const double * getRowRange() const;
00182 
00184   const double * getObjCoefficients() const;
00185   
00187   const CoinPackedMatrix * getMatrixByRow() const;
00188 
00190   const CoinPackedMatrix * getMatrixByCol() const;
00191 
00193   const char * getObjName() const;
00194   
00200   void getPreviousRowNames(char const * const * prev, 
00201                            int *card_prev) const;
00202 
00207   void getPreviousColNames(char const * const * prev, 
00208                            int *card_prev) const;
00209 
00212   char const * const * getRowNames() const;
00213   
00215   char const * const *getColNames() const;
00216   
00220   const char * rowName(int index) const;
00221 
00225   const char * columnName(int index) const;
00226 
00230   int rowIndex(const char * name) const;
00231 
00234   int columnIndex(const char * name) const;
00235 
00237   double objectiveOffset() const;
00238   
00240   inline void setObjectiveOffset(double value)
00241   { objectiveOffset_ = value;};
00242   
00245   bool isInteger(int columnNumber) const;
00246   
00248   const char * integerColumns() const;
00250   
00253 
00254   double getInfinity() const;
00255 
00258   void setInfinity(const double);
00259 
00261   double getEpsilon() const;
00262 
00265   void setEpsilon(const double);
00266 
00268   int getNumberAcross() const;
00269 
00272   void setNumberAcross(const int);
00273 
00275   int getDecimals() const;
00276 
00279   void setDecimals(const int);
00281 
00293   void setLpDataWithoutRowAndColNames(
00294                               const CoinPackedMatrix& m,
00295                               const double* collb, const double* colub,
00296                               const double* obj_coeff, 
00297                               const char* integrality,
00298                               const double* rowlb, const double* rowub);
00299 
00312   int is_invalid_name(const char *buff, const bool ranged) const;
00313   
00330   int are_invalid_names(char const * const *vnames, 
00331                                   const int card_vnames,
00332                                   const bool check_ranged) const;
00333   
00336   void setDefaultRowNames();
00337 
00339   void setDefaultColNames();
00340 
00360   void setLpDataRowAndColNames(char const * const * const rownames,
00361                                char const * const * const colnames);
00362 
00377   int writeLp(const char *filename, 
00378               const double epsilon, 
00379               const int numberAcross,
00380               const int decimals,
00381               const bool useRowNames = true);
00382 
00397   int writeLp(FILE *fp, 
00398               const double epsilon, 
00399               const int numberAcross,
00400               const int decimals,
00401               const bool useRowNames = true);
00402 
00405   int writeLp(const char *filename, const bool useRowNames = true);
00406 
00409   int writeLp(FILE *fp, const bool useRowNames = true);
00410 
00415   void readLp(const char *filename, const double epsilon);
00416 
00421   void readLp(const char *filename);
00422 
00428   void readLp(FILE *fp, const double epsilon);
00429 
00434   void readLp(FILE *fp);
00435 
00437   void print() const;
00439 
00440 protected:
00442   char * problemName_;
00443 
00445   int numberRows_;
00446   
00448   int numberColumns_;
00449   
00451   int numberElements_;
00452   
00454   mutable CoinPackedMatrix *matrixByColumn_;  
00455   
00457   CoinPackedMatrix *matrixByRow_;  
00458   
00460   double * rowlower_;
00461   
00463   double * rowupper_;
00464   
00466   double * collower_;
00467   
00469   double * colupper_;
00470   
00472   mutable double * rhs_;
00473   
00477   mutable double  *rowrange_;
00478 
00480   mutable char * rowsense_;
00481   
00483   double * objective_;
00484   
00486   double objectiveOffset_;
00487   
00490   char * integerType_;
00491   
00493   char * fileName_;
00494   
00496   double infinity_;
00497 
00499   double epsilon_;
00500 
00502   int numberAcross_;
00503 
00505   int decimals_;
00506 
00508   char *objName_;
00509 
00516   char **previous_names_[2];
00517 
00522   int card_previous_names_[2];
00523 
00528   char **names_[2];
00529 
00530   typedef struct {
00531     int index, next;
00532   } CoinHashLink;
00533 
00537   int maxHash_[2];
00538 
00542   int numberHash_[2];
00543 
00547   mutable CoinHashLink *hash_[2];
00548 
00554   void startHash(char const * const * const names, 
00555                  const COINColumnIndex number, 
00556                  int section);
00557 
00561   void stopHash(int section);
00562 
00567   COINColumnIndex findHash(const char *name, int section) const;
00568 
00573   void insertHash(const char *thisName, int section);
00574 
00577   void out_coeff(FILE *fp, double v, int print_1) const;
00578 
00582   int find_obj(FILE *fp) const;
00583 
00589   int is_subject_to(const char *buff) const;
00590 
00593   int first_is_number(const char *buff) const;
00594 
00597   int is_comment(const char *buff) const;
00598 
00600   void skip_comment(char *buff, FILE *fp) const;
00601 
00603   void scan_next(char *buff, FILE *fp) const;
00604 
00607   int is_free(const char *buff) const;
00608   
00614   int is_sense(const char *buff) const;
00615 
00625   int is_keyword(const char *buff) const;
00626 
00629   int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt, 
00630                      char **obj_name);
00631 
00636   int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name, 
00637                      int cnt_coeff) const;
00638 
00640   void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
00641 
00643   void realloc_row(char ***rowNames, int **start, double **rhs, 
00644                    double **rowlow, double **rowup, int *maxrow) const;
00645     
00647   void realloc_col(double **collow, double **colup, char **is_int,
00648                    int *maxcol) const;
00649 
00651   void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames, 
00652                 int *cnt_coeff, int *maxcoeff,
00653                      double *rhs, double *rowlow, double *rowup, 
00654                      int *cnt_row, double inf) const;
00655 
00669   void checkRowNames();
00670 
00679   void checkColNames();
00680 
00681 };
00682 

Generated on Thu May 15 21:59:05 2008 by  doxygen 1.4.7