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
00101 class CoinLpIO {
00102 friend void CoinLpIOUnitTest(const std::string & lpDir);
00103 public:
00104
00107
00108 CoinLpIO();
00109
00111 void gutsOfDestructor();
00112
00114 void gutsOfCopy(const CoinLpIO &);
00115
00117 CoinLpIO & operator = (const CoinLpIO& rhs) ;
00118
00120 CoinLpIO (const CoinLpIO &);
00121
00123 ~CoinLpIO();
00124
00130 void freePreviousNames(const int section);
00131
00133 void freeAll();
00135
00138 inline void
00139 convertBoundToSense(const double lower, const double upper,
00140 char& sense, double& right, double& range) const;
00141
00144
00146 const char * getProblemName() const;
00147
00149 void setProblemName(const char *name);
00150
00152 int getNumCols() const;
00153
00155 int getNumRows() const;
00156
00158 int getNumElements() const;
00159
00161 const double * getColLower() const;
00162
00164 const double * getColUpper() const;
00165
00167 const double * getRowLower() const;
00168
00170 const double * getRowUpper() const;
00180 const char * getRowSense() const;
00181
00193 const double * getRightHandSide() const;
00194
00208 const double * getRowRange() const;
00209
00211 const int getNumObjectives() const;
00212
00214 const double * getObjCoefficients() const;
00215
00217 const double * getObjCoefficients(int j) const;
00218
00220 const CoinPackedMatrix * getMatrixByRow() const;
00221
00223 const CoinPackedMatrix * getMatrixByCol() const;
00224
00226 const char * getObjName() const;
00227
00229 const char * getObjName(int j) const;
00230
00236 void getPreviousRowNames(char const * const * prev,
00237 int *card_prev) const;
00238
00243 void getPreviousColNames(char const * const * prev,
00244 int *card_prev) const;
00245
00248 char const * const * getRowNames() const;
00249
00251 char const * const *getColNames() const;
00252
00256 const char * rowName(int index) const;
00257
00261 const char * columnName(int index) const;
00262
00266 int rowIndex(const char * name) const;
00267
00270 int columnIndex(const char * name) const;
00271
00273 double objectiveOffset() const;
00274
00276 double objectiveOffset(int j) const;
00277
00279 inline void setObjectiveOffset(double value)
00280 { objectiveOffset_[0] = value;}
00281
00283 inline void setObjectiveOffset(double value, int j)
00284 { objectiveOffset_[j] = value;}
00285
00288 bool isInteger(int columnNumber) const;
00289
00291 const char * integerColumns() const;
00293
00296
00297 double getInfinity() const;
00298
00301 void setInfinity(const double);
00302
00304 double getEpsilon() const;
00305
00308 void setEpsilon(const double);
00309
00311 int getNumberAcross() const;
00312
00315 void setNumberAcross(const int);
00316
00318 int getDecimals() const;
00319
00322 void setDecimals(const int);
00324
00337 void setLpDataWithoutRowAndColNames(
00338 const CoinPackedMatrix& m,
00339 const double* collb, const double* colub,
00340 const double* obj_coeff,
00341 const char* integrality,
00342 const double* rowlb, const double* rowub);
00343
00344 void setLpDataWithoutRowAndColNames(
00345 const CoinPackedMatrix& m,
00346 const double* collb, const double* colub,
00347 const double* obj_coeff[MAX_OBJECTIVES],
00348 int num_objectives,
00349 const char* integrality,
00350 const double* rowlb, const double* rowub);
00351
00364 int is_invalid_name(const char *buff, const bool ranged) const;
00365
00382 int are_invalid_names(char const * const *vnames,
00383 const int card_vnames,
00384 const bool check_ranged) const;
00385
00388 void setDefaultRowNames();
00389
00391 void setDefaultColNames();
00392
00412 void setLpDataRowAndColNames(char const * const * const rownames,
00413 char const * const * const colnames);
00414
00429 int writeLp(const char *filename,
00430 const double epsilon,
00431 const int numberAcross,
00432 const int decimals,
00433 const bool useRowNames = true);
00434
00449 int writeLp(FILE *fp,
00450 const double epsilon,
00451 const int numberAcross,
00452 const int decimals,
00453 const bool useRowNames = true);
00454
00457 int writeLp(const char *filename, const bool useRowNames = true);
00458
00461 int writeLp(FILE *fp, const bool useRowNames = true);
00462
00467 void readLp(const char *filename, const double epsilon);
00468
00473 void readLp(const char *filename);
00474
00480 void readLp(FILE *fp, const double epsilon);
00481
00486 void readLp(FILE *fp);
00487
00489 void print() const;
00491
00498 void passInMessageHandler(CoinMessageHandler * handler);
00499
00501 void newLanguage(CoinMessages::Language language);
00502
00504 inline void setLanguage(CoinMessages::Language language) {newLanguage(language);}
00505
00507 inline CoinMessageHandler * messageHandler() const {return handler_;}
00508
00510 inline CoinMessages messages() {return messages_;}
00512 inline CoinMessages * messagesPointer() {return & messages_;}
00514
00515 protected:
00517 char * problemName_;
00518
00520 CoinMessageHandler * handler_;
00526 bool defaultHandler_;
00528 CoinMessages messages_;
00529
00531 int numberRows_;
00532
00534 int numberColumns_;
00535
00537 int numberElements_;
00538
00540 mutable CoinPackedMatrix *matrixByColumn_;
00541
00543 CoinPackedMatrix *matrixByRow_;
00544
00546 double * rowlower_;
00547
00549 double * rowupper_;
00550
00552 double * collower_;
00553
00555 double * colupper_;
00556
00558 mutable double * rhs_;
00559
00563 mutable double *rowrange_;
00564
00566 mutable char * rowsense_;
00567
00569 double * objective_[MAX_OBJECTIVES];
00570
00572 int num_objectives_;
00573
00575 double objectiveOffset_[MAX_OBJECTIVES];
00576
00579 char * integerType_;
00580
00582 char * fileName_;
00583
00585 double infinity_;
00586
00588 double epsilon_;
00589
00591 int numberAcross_;
00592
00594 int decimals_;
00595
00597 char *objName_[MAX_OBJECTIVES];
00598
00605 char **previous_names_[2];
00606
00611 int card_previous_names_[2];
00612
00617 char **names_[2];
00618
00619 typedef struct {
00620 int index, next;
00621 } CoinHashLink;
00622
00626 int maxHash_[2];
00627
00631 int numberHash_[2];
00632
00636 mutable CoinHashLink *hash_[2];
00637
00643 void startHash(char const * const * const names,
00644 const COINColumnIndex number,
00645 int section);
00646
00650 void stopHash(int section);
00651
00656 COINColumnIndex findHash(const char *name, int section) const;
00657
00662 void insertHash(const char *thisName, int section);
00663
00666 void out_coeff(FILE *fp, double v, int print_1) const;
00667
00671 int find_obj(FILE *fp) const;
00672
00678 int is_subject_to(const char *buff) const;
00679
00682 int first_is_number(const char *buff) const;
00683
00686 int is_comment(const char *buff) const;
00687
00689 void skip_comment(char *buff, FILE *fp) const;
00690
00692 void scan_next(char *buff, FILE *fp) const;
00693
00696 int is_free(const char *buff) const;
00697
00700 int is_inf(const char *buff) const;
00701
00707 int is_sense(const char *buff) const;
00708
00718 int is_keyword(const char *buff) const;
00719
00722 int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt,
00723 char **obj_name, int *num_objectives, int *obj_starts);
00724
00729 int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name,
00730 int cnt_coeff) const;
00731
00733 void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
00734
00736 void realloc_row(char ***rowNames, int **start, double **rhs,
00737 double **rowlow, double **rowup, int *maxrow) const;
00738
00740 void realloc_col(double **collow, double **colup, char **is_int,
00741 int *maxcol) const;
00742
00744 void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames,
00745 int *cnt_coeff, int *maxcoeff,
00746 double *rhs, double *rowlow, double *rowup,
00747 int *cnt_row, double inf) const;
00748
00762 void checkRowNames();
00763
00772 void checkColNames();
00773
00774 };
00775
00776 void
00777 CoinLpIOUnitTest(const std::string& lpDir);
00778
00779
00780 #endif