CoinLpIO.hpp

Go to the documentation of this file.
00001 /* $Id: CoinLpIO.hpp 1749 2014-10-24 20:00:14Z 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 class CoinSet;
00023 
00024 const int MAX_OBJECTIVES = 2;
00025 
00026 typedef int COINColumnIndex;
00027 
00104 class CoinLpIO {
00105       friend void CoinLpIOUnitTest(const std::string & lpDir); 
00106 public:
00107 
00110 
00111   CoinLpIO(); 
00112   
00114   void gutsOfDestructor(); 
00115  
00117   void gutsOfCopy(const CoinLpIO &); 
00118  
00120   CoinLpIO & operator = (const CoinLpIO& rhs) ; 
00121  
00123   CoinLpIO (const CoinLpIO &); 
00124 
00126   ~CoinLpIO();
00127 
00133   void freePreviousNames(const int section);
00134 
00136   void freeAll();
00138 
00141     inline void
00142     convertBoundToSense(const double lower, const double upper,
00143                         char& sense, double& right, double& range) const;
00144 
00147 
00149   const char * getProblemName() const;
00150 
00152   void setProblemName(const char *name);
00153 
00155   int getNumCols() const;
00156 
00158   int getNumRows() const;
00159 
00161   int getNumElements() const;
00162   
00164   const double * getColLower() const;
00165 
00167   const double * getColUpper() const;
00168 
00170   const double * getRowLower() const;
00171   
00173   const double * getRowUpper() const;
00183   const char * getRowSense() const;
00184   
00196   const double * getRightHandSide() const;
00197   
00211   const double * getRowRange() const;
00212 
00214   const int getNumObjectives() const;
00215   
00217   const double * getObjCoefficients() const;
00218   
00220   const double * getObjCoefficients(int j) const;
00221   
00223   const CoinPackedMatrix * getMatrixByRow() const;
00224 
00226   const CoinPackedMatrix * getMatrixByCol() const;
00227 
00229   const char * getObjName() const;
00230   
00232   const char * getObjName(int j) const;
00233   
00239   void getPreviousRowNames(char const * const * prev, 
00240                            int *card_prev) const;
00241 
00246   void getPreviousColNames(char const * const * prev, 
00247                            int *card_prev) const;
00248 
00251   char const * const * getRowNames() const;
00252   
00254   char const * const *getColNames() const;
00255   
00259   const char * rowName(int index) const;
00260 
00264   const char * columnName(int index) const;
00265 
00269   int rowIndex(const char * name) const;
00270 
00273   int columnIndex(const char * name) const;
00274 
00276   double objectiveOffset() const;
00277   
00279   double objectiveOffset(int j) const;
00280   
00282   inline void setObjectiveOffset(double value)
00283   { objectiveOffset_[0] = value;}
00284   
00286    inline void setObjectiveOffset(double value, int j)
00287   { objectiveOffset_[j] = value;}
00288   
00291   bool isInteger(int columnNumber) const;
00292   
00294   const char * integerColumns() const;
00296   
00299 
00300   double getInfinity() const;
00301 
00304   void setInfinity(const double);
00305 
00307   double getEpsilon() const;
00308 
00311   void setEpsilon(const double);
00312 
00314   int getNumberAcross() const;
00315 
00318   void setNumberAcross(const int);
00319 
00321   int getDecimals() const;
00322 
00325   void setDecimals(const int);
00327 
00340   void setLpDataWithoutRowAndColNames(
00341                               const CoinPackedMatrix& m,
00342                               const double* collb, const double* colub,
00343                               const double* obj_coeff,
00344                               const char* integrality,
00345                               const double* rowlb, const double* rowub);
00346 
00347   void setLpDataWithoutRowAndColNames(
00348                               const CoinPackedMatrix& m,
00349                               const double* collb, const double* colub,
00350                               const double* obj_coeff[MAX_OBJECTIVES],
00351                               int num_objectives,
00352                               const char* integrality,
00353                               const double* rowlb, const double* rowub);
00354 
00367   int is_invalid_name(const char *buff, const bool ranged) const;
00368   
00385   int are_invalid_names(char const * const *vnames, 
00386                                   const int card_vnames,
00387                                   const bool check_ranged) const;
00388   
00391   void setDefaultRowNames();
00392 
00394   void setDefaultColNames();
00395 
00415   void setLpDataRowAndColNames(char const * const * const rownames,
00416                                char const * const * const colnames);
00417 
00432   int writeLp(const char *filename, 
00433               const double epsilon, 
00434               const int numberAcross,
00435               const int decimals,
00436               const bool useRowNames = true);
00437 
00452   int writeLp(FILE *fp, 
00453               const double epsilon, 
00454               const int numberAcross,
00455               const int decimals,
00456               const bool useRowNames = true);
00457 
00460   int writeLp(const char *filename, const bool useRowNames = true);
00461 
00464   int writeLp(FILE *fp, const bool useRowNames = true);
00465 
00470   void readLp(const char *filename, const double epsilon);
00471 
00476   void readLp(const char *filename);
00477 
00483   void readLp(FILE *fp, const double epsilon);
00484 
00489   void readLp(FILE *fp);
00490 
00492   void print() const;
00493   
00495   void loadSOS(int numberSets,const CoinSet * sets);
00496   
00498   void loadSOS(int numberSets,const CoinSet ** sets);
00499   
00501   inline int numberSets() const
00502   { return numberSets_;}
00503 
00505   inline CoinSet ** setInformation() const
00506   { return set_;}
00508 
00515   void passInMessageHandler(CoinMessageHandler * handler);
00516 
00518   void newLanguage(CoinMessages::Language language);
00519 
00521   inline void setLanguage(CoinMessages::Language language) {newLanguage(language);}
00522 
00524   inline CoinMessageHandler * messageHandler() const {return handler_;}
00525 
00527   inline CoinMessages messages() {return messages_;}
00529   inline CoinMessages * messagesPointer() {return & messages_;}
00531 
00532 protected:
00534   char * problemName_;
00535 
00537   CoinMessageHandler * handler_;
00543   bool defaultHandler_;
00545   CoinMessages messages_;
00546 
00548   int numberRows_;
00549   
00551   int numberColumns_;
00552   
00554   int numberElements_;
00555   
00557   mutable CoinPackedMatrix *matrixByColumn_;  
00558   
00560   CoinPackedMatrix *matrixByRow_;  
00561   
00563   double * rowlower_;
00564   
00566   double * rowupper_;
00567   
00569   double * collower_;
00570   
00572   double * colupper_;
00573   
00575   mutable double * rhs_;
00576   
00580   mutable double  *rowrange_;
00581 
00583   mutable char * rowsense_;
00584   
00586   double * objective_[MAX_OBJECTIVES];
00587 
00589   int num_objectives_;
00590   
00592   double objectiveOffset_[MAX_OBJECTIVES];
00593   
00596   char * integerType_;
00597   
00599   CoinSet ** set_;
00600 
00602   int numberSets_;
00603   
00605   char * fileName_;
00606   
00608   double infinity_;
00609 
00611   double epsilon_;
00612 
00614   int numberAcross_;
00615 
00617   int decimals_;
00618 
00620   char *objName_[MAX_OBJECTIVES];
00621 
00628   char **previous_names_[2];
00629 
00634   int card_previous_names_[2];
00635 
00640   char **names_[2];
00641 
00642   typedef struct {
00643     int index, next;
00644   } CoinHashLink;
00645 
00649   int maxHash_[2];
00650 
00654   int numberHash_[2];
00655 
00659   mutable CoinHashLink *hash_[2];
00660 
00666   void startHash(char const * const * const names, 
00667                  const COINColumnIndex number, 
00668                  int section);
00669 
00673   void stopHash(int section);
00674 
00679   COINColumnIndex findHash(const char *name, int section) const;
00680 
00685   void insertHash(const char *thisName, int section);
00686 
00689   void out_coeff(FILE *fp, double v, int print_1) const;
00690 
00694   int find_obj(FILE *fp) const;
00695 
00701   int is_subject_to(const char *buff) const;
00702 
00705   int first_is_number(const char *buff) const;
00706 
00709   int is_comment(const char *buff) const;
00710 
00712   void skip_comment(char *buff, FILE *fp) const;
00713 
00715   void scan_next(char *buff, FILE *fp) const;
00716 
00719   int is_free(const char *buff) const;
00720   
00723   int is_inf(const char *buff) const;
00724   
00730   int is_sense(const char *buff) const;
00731 
00743   int is_keyword(const char *buff) const;
00744 
00747   int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt, 
00748                      char **obj_name, int *num_objectives, int *obj_starts);
00749 
00754   int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name, 
00755                      int cnt_coeff) const;
00756 
00758   void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
00759 
00761   void realloc_row(char ***rowNames, int **start, double **rhs, 
00762                    double **rowlow, double **rowup, int *maxrow) const;
00763     
00765   void realloc_col(double **collow, double **colup, char **is_int,
00766                    int *maxcol) const;
00767 
00769   void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames, 
00770                 int *cnt_coeff, int *maxcoeff,
00771                      double *rhs, double *rowlow, double *rowup, 
00772                      int *cnt_row, double inf) const;
00773 
00787   void checkRowNames();
00788 
00797   void checkColNames();
00798 
00799 };
00800 
00801 void
00802 CoinLpIOUnitTest(const std::string& lpDir);
00803 
00804 
00805 #endif 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 28 Aug 2016 for CoinUtils by  doxygen 1.6.1