CoinLpIO.hpp

Go to the documentation of this file.
00001 /* $Id: CoinLpIO.hpp 1602 2013-07-12 12:15:37Z tkr $ */
00002 // Last edit: 11/5/08
00003 //
00004 // Name:     CoinLpIO.hpp; Support for Lp files
00005 // Author:   Francois Margot
00006 //           Tepper School of Business
00007 //           Carnegie Mellon University, Pittsburgh, PA 15213
00008 //           email: fmargot@andrew.cmu.edu
00009 // Date:     12/28/03
00010 //-----------------------------------------------------------------------------
00011 // Copyright (C) 2003, Francois Margot, International Business Machines
00012 // Corporation and others.  All Rights Reserved.
00013 // This code is licensed under the terms of the Eclipse Public License (EPL).
00014 
00015 #ifndef CoinLpIO_H
00016 #define CoinLpIO_H
00017 
00018 #include <cstdio>
00019 
00020 #include "CoinPackedMatrix.hpp"
00021 #include "CoinMessage.hpp"
00022 
00023 typedef int COINColumnIndex;
00024 
00096 class CoinLpIO {
00097       friend void CoinLpIOUnitTest(const std::string & lpDir); 
00098 public:
00099 
00102 
00103   CoinLpIO(); 
00104   
00106   void gutsOfDestructor(); 
00107  
00109   void gutsOfCopy(const CoinLpIO &); 
00110  
00112   CoinLpIO & operator = (const CoinLpIO& rhs) ; 
00113  
00115   CoinLpIO (const CoinLpIO &); 
00116 
00118   ~CoinLpIO();
00119 
00125   void freePreviousNames(const int section);
00126 
00128   void freeAll();
00130 
00133     inline void
00134     convertBoundToSense(const double lower, const double upper,
00135                         char& sense, double& right, double& range) const;
00136 
00139 
00141   const char * getProblemName() const;
00142 
00144   void setProblemName(const char *name);
00145 
00147   int getNumCols() const;
00148 
00150   int getNumRows() const;
00151 
00153   int getNumElements() const;
00154   
00156   const double * getColLower() const;
00157 
00159   const double * getColUpper() const;
00160 
00162   const double * getRowLower() const;
00163   
00165   const double * getRowUpper() const;
00175   const char * getRowSense() const;
00176   
00188   const double * getRightHandSide() const;
00189   
00203   const double * getRowRange() const;
00204 
00206   const double * getObjCoefficients() const;
00207   
00209   const CoinPackedMatrix * getMatrixByRow() const;
00210 
00212   const CoinPackedMatrix * getMatrixByCol() const;
00213 
00215   const char * getObjName() const;
00216   
00222   void getPreviousRowNames(char const * const * prev, 
00223                            int *card_prev) const;
00224 
00229   void getPreviousColNames(char const * const * prev, 
00230                            int *card_prev) const;
00231 
00234   char const * const * getRowNames() const;
00235   
00237   char const * const *getColNames() const;
00238   
00242   const char * rowName(int index) const;
00243 
00247   const char * columnName(int index) const;
00248 
00252   int rowIndex(const char * name) const;
00253 
00256   int columnIndex(const char * name) const;
00257 
00259   double objectiveOffset() const;
00260   
00262   inline void setObjectiveOffset(double value)
00263   { objectiveOffset_ = value;}
00264   
00267   bool isInteger(int columnNumber) const;
00268   
00270   const char * integerColumns() const;
00272   
00275 
00276   double getInfinity() const;
00277 
00280   void setInfinity(const double);
00281 
00283   double getEpsilon() const;
00284 
00287   void setEpsilon(const double);
00288 
00290   int getNumberAcross() const;
00291 
00294   void setNumberAcross(const int);
00295 
00297   int getDecimals() const;
00298 
00301   void setDecimals(const int);
00303 
00315   void setLpDataWithoutRowAndColNames(
00316                               const CoinPackedMatrix& m,
00317                               const double* collb, const double* colub,
00318                               const double* obj_coeff, 
00319                               const char* integrality,
00320                               const double* rowlb, const double* rowub);
00321 
00334   int is_invalid_name(const char *buff, const bool ranged) const;
00335   
00352   int are_invalid_names(char const * const *vnames, 
00353                                   const int card_vnames,
00354                                   const bool check_ranged) const;
00355   
00358   void setDefaultRowNames();
00359 
00361   void setDefaultColNames();
00362 
00382   void setLpDataRowAndColNames(char const * const * const rownames,
00383                                char const * const * const colnames);
00384 
00399   int writeLp(const char *filename, 
00400               const double epsilon, 
00401               const int numberAcross,
00402               const int decimals,
00403               const bool useRowNames = true);
00404 
00419   int writeLp(FILE *fp, 
00420               const double epsilon, 
00421               const int numberAcross,
00422               const int decimals,
00423               const bool useRowNames = true);
00424 
00427   int writeLp(const char *filename, const bool useRowNames = true);
00428 
00431   int writeLp(FILE *fp, const bool useRowNames = true);
00432 
00437   void readLp(const char *filename, const double epsilon);
00438 
00443   void readLp(const char *filename);
00444 
00450   void readLp(FILE *fp, const double epsilon);
00451 
00456   void readLp(FILE *fp);
00457 
00459   void print() const;
00461 
00468   void passInMessageHandler(CoinMessageHandler * handler);
00469 
00471   void newLanguage(CoinMessages::Language language);
00472 
00474   inline void setLanguage(CoinMessages::Language language) {newLanguage(language);}
00475 
00477   inline CoinMessageHandler * messageHandler() const {return handler_;}
00478 
00480   inline CoinMessages messages() {return messages_;}
00482   inline CoinMessages * messagesPointer() {return & messages_;}
00484 
00485 protected:
00487   char * problemName_;
00488 
00490   CoinMessageHandler * handler_;
00496   bool defaultHandler_;
00498   CoinMessages messages_;
00499 
00501   int numberRows_;
00502   
00504   int numberColumns_;
00505   
00507   int numberElements_;
00508   
00510   mutable CoinPackedMatrix *matrixByColumn_;  
00511   
00513   CoinPackedMatrix *matrixByRow_;  
00514   
00516   double * rowlower_;
00517   
00519   double * rowupper_;
00520   
00522   double * collower_;
00523   
00525   double * colupper_;
00526   
00528   mutable double * rhs_;
00529   
00533   mutable double  *rowrange_;
00534 
00536   mutable char * rowsense_;
00537   
00539   double * objective_;
00540   
00542   double objectiveOffset_;
00543   
00546   char * integerType_;
00547   
00549   char * fileName_;
00550   
00552   double infinity_;
00553 
00555   double epsilon_;
00556 
00558   int numberAcross_;
00559 
00561   int decimals_;
00562 
00564   char *objName_;
00565 
00572   char **previous_names_[2];
00573 
00578   int card_previous_names_[2];
00579 
00584   char **names_[2];
00585 
00586   typedef struct {
00587     int index, next;
00588   } CoinHashLink;
00589 
00593   int maxHash_[2];
00594 
00598   int numberHash_[2];
00599 
00603   mutable CoinHashLink *hash_[2];
00604 
00610   void startHash(char const * const * const names, 
00611                  const COINColumnIndex number, 
00612                  int section);
00613 
00617   void stopHash(int section);
00618 
00623   COINColumnIndex findHash(const char *name, int section) const;
00624 
00629   void insertHash(const char *thisName, int section);
00630 
00633   void out_coeff(FILE *fp, double v, int print_1) const;
00634 
00638   int find_obj(FILE *fp) const;
00639 
00645   int is_subject_to(const char *buff) const;
00646 
00649   int first_is_number(const char *buff) const;
00650 
00653   int is_comment(const char *buff) const;
00654 
00656   void skip_comment(char *buff, FILE *fp) const;
00657 
00659   void scan_next(char *buff, FILE *fp) const;
00660 
00663   int is_free(const char *buff) const;
00664   
00667   int is_inf(const char *buff) const;
00668   
00674   int is_sense(const char *buff) const;
00675 
00685   int is_keyword(const char *buff) const;
00686 
00689   int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt, 
00690                      char **obj_name);
00691 
00696   int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name, 
00697                      int cnt_coeff) const;
00698 
00700   void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
00701 
00703   void realloc_row(char ***rowNames, int **start, double **rhs, 
00704                    double **rowlow, double **rowup, int *maxrow) const;
00705     
00707   void realloc_col(double **collow, double **colup, char **is_int,
00708                    int *maxcol) const;
00709 
00711   void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames, 
00712                 int *cnt_coeff, int *maxcoeff,
00713                      double *rhs, double *rowlow, double *rowup, 
00714                      int *cnt_row, double inf) const;
00715 
00729   void checkRowNames();
00730 
00739   void checkColNames();
00740 
00741 };
00742 
00743 void
00744 CoinLpIOUnitTest(const std::string& lpDir);
00745 
00746 
00747 #endif 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 17 Oct 2013 for CoinUtils by  doxygen 1.6.1