00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <cstdio>
00014
00015 class CoinPackedMatrix;
00016
00017 typedef int COINColumnIndex;
00018
00090 class CoinLpIO {
00091
00092 public:
00093
00096
00097 CoinLpIO();
00098
00100 ~CoinLpIO();
00101
00107 void freePreviousNames(const int section);
00108
00110 void freeAll();
00112
00115 inline void
00116 convertBoundToSense(const double lower, const double upper,
00117 char& sense, double& right, double& range) const;
00118
00121
00123 const char * getProblemName() const;
00124
00126 void setProblemName(const char *name);
00127
00129 int getNumCols() const;
00130
00132 int getNumRows() const;
00133
00135 int getNumElements() const;
00136
00138 const double * getColLower() const;
00139
00141 const double * getColUpper() const;
00142
00144 const double * getRowLower() const;
00145
00147 const double * getRowUpper() const;
00157 const char * getRowSense() const;
00158
00170 const double * getRightHandSide() const;
00171
00185 const double * getRowRange() const;
00186
00188 const double * getObjCoefficients() const;
00189
00191 const CoinPackedMatrix * getMatrixByRow() const;
00192
00194 const CoinPackedMatrix * getMatrixByCol() const;
00195
00197 const char * getObjName() const;
00198
00204 void getPreviousRowNames(char const * const * prev,
00205 int *card_prev) const;
00206
00211 void getPreviousColNames(char const * const * prev,
00212 int *card_prev) const;
00213
00216 char const * const * getRowNames() const;
00217
00219 char const * const *getColNames() const;
00220
00224 const char * rowName(int index) const;
00225
00229 const char * columnName(int index) const;
00230
00234 int rowIndex(const char * name) const;
00235
00238 int columnIndex(const char * name) const;
00239
00241 double objectiveOffset() const;
00242
00244 inline void setObjectiveOffset(double value)
00245 { objectiveOffset_ = value;}
00246
00249 bool isInteger(int columnNumber) const;
00250
00252 const char * integerColumns() const;
00254
00257
00258 double getInfinity() const;
00259
00262 void setInfinity(const double);
00263
00265 double getEpsilon() const;
00266
00269 void setEpsilon(const double);
00270
00272 int getNumberAcross() const;
00273
00276 void setNumberAcross(const int);
00277
00279 int getDecimals() const;
00280
00283 void setDecimals(const int);
00285
00297 void setLpDataWithoutRowAndColNames(
00298 const CoinPackedMatrix& m,
00299 const double* collb, const double* colub,
00300 const double* obj_coeff,
00301 const char* integrality,
00302 const double* rowlb, const double* rowub);
00303
00316 int is_invalid_name(const char *buff, const bool ranged) const;
00317
00334 int are_invalid_names(char const * const *vnames,
00335 const int card_vnames,
00336 const bool check_ranged) const;
00337
00340 void setDefaultRowNames();
00341
00343 void setDefaultColNames();
00344
00364 void setLpDataRowAndColNames(char const * const * const rownames,
00365 char const * const * const colnames);
00366
00381 int writeLp(const char *filename,
00382 const double epsilon,
00383 const int numberAcross,
00384 const int decimals,
00385 const bool useRowNames = true);
00386
00401 int writeLp(FILE *fp,
00402 const double epsilon,
00403 const int numberAcross,
00404 const int decimals,
00405 const bool useRowNames = true);
00406
00409 int writeLp(const char *filename, const bool useRowNames = true);
00410
00413 int writeLp(FILE *fp, const bool useRowNames = true);
00414
00419 void readLp(const char *filename, const double epsilon);
00420
00425 void readLp(const char *filename);
00426
00432 void readLp(FILE *fp, const double epsilon);
00433
00438 void readLp(FILE *fp);
00439
00441 void print() const;
00443
00444 protected:
00446 char * problemName_;
00447
00449 int numberRows_;
00450
00452 int numberColumns_;
00453
00455 int numberElements_;
00456
00458 mutable CoinPackedMatrix *matrixByColumn_;
00459
00461 CoinPackedMatrix *matrixByRow_;
00462
00464 double * rowlower_;
00465
00467 double * rowupper_;
00468
00470 double * collower_;
00471
00473 double * colupper_;
00474
00476 mutable double * rhs_;
00477
00481 mutable double *rowrange_;
00482
00484 mutable char * rowsense_;
00485
00487 double * objective_;
00488
00490 double objectiveOffset_;
00491
00494 char * integerType_;
00495
00497 char * fileName_;
00498
00500 double infinity_;
00501
00503 double epsilon_;
00504
00506 int numberAcross_;
00507
00509 int decimals_;
00510
00512 char *objName_;
00513
00520 char **previous_names_[2];
00521
00526 int card_previous_names_[2];
00527
00532 char **names_[2];
00533
00534 typedef struct {
00535 int index, next;
00536 } CoinHashLink;
00537
00541 int maxHash_[2];
00542
00546 int numberHash_[2];
00547
00551 mutable CoinHashLink *hash_[2];
00552
00558 void startHash(char const * const * const names,
00559 const COINColumnIndex number,
00560 int section);
00561
00565 void stopHash(int section);
00566
00571 COINColumnIndex findHash(const char *name, int section) const;
00572
00577 void insertHash(const char *thisName, int section);
00578
00581 void out_coeff(FILE *fp, double v, int print_1) const;
00582
00586 int find_obj(FILE *fp) const;
00587
00593 int is_subject_to(const char *buff) const;
00594
00597 int first_is_number(const char *buff) const;
00598
00601 int is_comment(const char *buff) const;
00602
00604 void skip_comment(char *buff, FILE *fp) const;
00605
00607 void scan_next(char *buff, FILE *fp) const;
00608
00611 int is_free(const char *buff) const;
00612
00615 int is_inf(const char *buff) const;
00616
00622 int is_sense(const char *buff) const;
00623
00633 int is_keyword(const char *buff) const;
00634
00637 int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt,
00638 char **obj_name);
00639
00644 int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name,
00645 int cnt_coeff) const;
00646
00648 void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
00649
00651 void realloc_row(char ***rowNames, int **start, double **rhs,
00652 double **rowlow, double **rowup, int *maxrow) const;
00653
00655 void realloc_col(double **collow, double **colup, char **is_int,
00656 int *maxcol) const;
00657
00659 void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames,
00660 int *cnt_coeff, int *maxcoeff,
00661 double *rhs, double *rowlow, double *rowup,
00662 int *cnt_row, double inf) const;
00663
00677 void checkRowNames();
00678
00687 void checkColNames();
00688
00689 };
00690