00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CoinLpIO_H
00016 #define CoinLpIO_H
00017
00018 #include <cstdio>
00019
00020 #include "CoinPackedMatrix.hpp"
00021 #include "CoinMessage.hpp"
00022
00023 const int MAX_OBJECTIVES = 2;
00024
00025 typedef int COINColumnIndex;
00026
00103 class CoinLpIO {
00104 friend void CoinLpIOUnitTest(const std::string & lpDir);
00105 public:
00106
00109
00110 CoinLpIO();
00111
00113 void gutsOfDestructor();
00114
00116 void gutsOfCopy(const CoinLpIO &);
00117
00119 CoinLpIO & operator = (const CoinLpIO& rhs) ;
00120
00122 CoinLpIO (const CoinLpIO &);
00123
00125 ~CoinLpIO();
00126
00132 void freePreviousNames(const int section);
00133
00135 void freeAll();
00137
00140 inline void
00141 convertBoundToSense(const double lower, const double upper,
00142 char& sense, double& right, double& range) const;
00143
00146
00148 const char * getProblemName() const;
00149
00151 void setProblemName(const char *name);
00152
00154 int getNumCols() const;
00155
00157 int getNumRows() const;
00158
00160 int getNumElements() const;
00161
00163 const double * getColLower() const;
00164
00166 const double * getColUpper() const;
00167
00169 const double * getRowLower() const;
00170
00172 const double * getRowUpper() const;
00182 const char * getRowSense() const;
00183
00195 const double * getRightHandSide() const;
00196
00210 const double * getRowRange() const;
00211
00213 const int getNumObjectives() const;
00214
00216 const double * getObjCoefficients() const;
00217
00219 const double * getObjCoefficients(int j) const;
00220
00222 const CoinPackedMatrix * getMatrixByRow() const;
00223
00225 const CoinPackedMatrix * getMatrixByCol() const;
00226
00228 const char * getObjName() const;
00229
00231 const char * getObjName(int j) const;
00232
00238 void getPreviousRowNames(char const * const * prev,
00239 int *card_prev) const;
00240
00245 void getPreviousColNames(char const * const * prev,
00246 int *card_prev) const;
00247
00250 char const * const * getRowNames() const;
00251
00253 char const * const *getColNames() const;
00254
00258 const char * rowName(int index) const;
00259
00263 const char * columnName(int index) const;
00264
00268 int rowIndex(const char * name) const;
00269
00272 int columnIndex(const char * name) const;
00273
00275 double objectiveOffset() const;
00276
00278 double objectiveOffset(int j) const;
00279
00281 inline void setObjectiveOffset(double value)
00282 { objectiveOffset_[0] = value;}
00283
00285 inline void setObjectiveOffset(double value, int j)
00286 { objectiveOffset_[j] = value;}
00287
00290 bool isInteger(int columnNumber) const;
00291
00293 const char * integerColumns() const;
00295
00298
00299 double getInfinity() const;
00300
00303 void setInfinity(const double);
00304
00306 double getEpsilon() const;
00307
00310 void setEpsilon(const double);
00311
00313 int getNumberAcross() const;
00314
00317 void setNumberAcross(const int);
00318
00320 int getDecimals() const;
00321
00324 void setDecimals(const int);
00326
00339 void setLpDataWithoutRowAndColNames(
00340 const CoinPackedMatrix& m,
00341 const double* collb, const double* colub,
00342 const double* obj_coeff,
00343 const char* integrality,
00344 const double* rowlb, const double* rowub);
00345
00346 void setLpDataWithoutRowAndColNames(
00347 const CoinPackedMatrix& m,
00348 const double* collb, const double* colub,
00349 const double* obj_coeff[MAX_OBJECTIVES],
00350 int num_objectives,
00351 const char* integrality,
00352 const double* rowlb, const double* rowub);
00353
00366 int is_invalid_name(const char *buff, const bool ranged) const;
00367
00384 int are_invalid_names(char const * const *vnames,
00385 const int card_vnames,
00386 const bool check_ranged) const;
00387
00390 void setDefaultRowNames();
00391
00393 void setDefaultColNames();
00394
00414 void setLpDataRowAndColNames(char const * const * const rownames,
00415 char const * const * const colnames);
00416
00431 int writeLp(const char *filename,
00432 const double epsilon,
00433 const int numberAcross,
00434 const int decimals,
00435 const bool useRowNames = true);
00436
00451 int writeLp(FILE *fp,
00452 const double epsilon,
00453 const int numberAcross,
00454 const int decimals,
00455 const bool useRowNames = true);
00456
00459 int writeLp(const char *filename, const bool useRowNames = true);
00460
00463 int writeLp(FILE *fp, const bool useRowNames = true);
00464
00469 void readLp(const char *filename, const double epsilon);
00470
00475 void readLp(const char *filename);
00476
00482 void readLp(FILE *fp, const double epsilon);
00483
00488 void readLp(FILE *fp);
00489
00491 void print() const;
00493
00500 void passInMessageHandler(CoinMessageHandler * handler);
00501
00503 void newLanguage(CoinMessages::Language language);
00504
00506 inline void setLanguage(CoinMessages::Language language) {newLanguage(language);}
00507
00509 inline CoinMessageHandler * messageHandler() const {return handler_;}
00510
00512 inline CoinMessages messages() {return messages_;}
00514 inline CoinMessages * messagesPointer() {return & messages_;}
00516
00517 protected:
00519 char * problemName_;
00520
00522 CoinMessageHandler * handler_;
00528 bool defaultHandler_;
00530 CoinMessages messages_;
00531
00533 int numberRows_;
00534
00536 int numberColumns_;
00537
00539 int numberElements_;
00540
00542 mutable CoinPackedMatrix *matrixByColumn_;
00543
00545 CoinPackedMatrix *matrixByRow_;
00546
00548 double * rowlower_;
00549
00551 double * rowupper_;
00552
00554 double * collower_;
00555
00557 double * colupper_;
00558
00560 mutable double * rhs_;
00561
00565 mutable double *rowrange_;
00566
00568 mutable char * rowsense_;
00569
00571 double * objective_[MAX_OBJECTIVES];
00572
00574 int num_objectives_;
00575
00577 double objectiveOffset_[MAX_OBJECTIVES];
00578
00581 char * integerType_;
00582
00584 char * fileName_;
00585
00587 double infinity_;
00588
00590 double epsilon_;
00591
00593 int numberAcross_;
00594
00596 int decimals_;
00597
00599 char *objName_[MAX_OBJECTIVES];
00600
00607 char **previous_names_[2];
00608
00613 int card_previous_names_[2];
00614
00619 char **names_[2];
00620
00621 typedef struct {
00622 int index, next;
00623 } CoinHashLink;
00624
00628 int maxHash_[2];
00629
00633 int numberHash_[2];
00634
00638 mutable CoinHashLink *hash_[2];
00639
00645 void startHash(char const * const * const names,
00646 const COINColumnIndex number,
00647 int section);
00648
00652 void stopHash(int section);
00653
00658 COINColumnIndex findHash(const char *name, int section) const;
00659
00664 void insertHash(const char *thisName, int section);
00665
00668 void out_coeff(FILE *fp, double v, int print_1) const;
00669
00673 int find_obj(FILE *fp) const;
00674
00680 int is_subject_to(const char *buff) const;
00681
00684 int first_is_number(const char *buff) const;
00685
00688 int is_comment(const char *buff) const;
00689
00691 void skip_comment(char *buff, FILE *fp) const;
00692
00694 void scan_next(char *buff, FILE *fp) const;
00695
00698 int is_free(const char *buff) const;
00699
00702 int is_inf(const char *buff) const;
00703
00709 int is_sense(const char *buff) const;
00710
00720 int is_keyword(const char *buff) const;
00721
00724 int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt,
00725 char **obj_name, int *num_objectives, int *obj_starts);
00726
00731 int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name,
00732 int cnt_coeff) const;
00733
00735 void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
00736
00738 void realloc_row(char ***rowNames, int **start, double **rhs,
00739 double **rowlow, double **rowup, int *maxrow) const;
00740
00742 void realloc_col(double **collow, double **colup, char **is_int,
00743 int *maxcol) const;
00744
00746 void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames,
00747 int *cnt_coeff, int *maxcoeff,
00748 double *rhs, double *rowlow, double *rowup,
00749 int *cnt_row, double inf) const;
00750
00764 void checkRowNames();
00765
00774 void checkColNames();
00775
00776 };
00777
00778 void
00779 CoinLpIOUnitTest(const std::string& lpDir);
00780
00781
00782 #endif