00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <cstdio>
00015
00016 class CoinPackedMatrix;
00017
00018 typedef int COINColumnIndex;
00019
00091 class CoinLpIO {
00092
00093 public:
00094
00097
00098 CoinLpIO();
00099
00101 ~CoinLpIO();
00102
00108 void freePreviousNames(const int section);
00109
00111 void freeAll();
00113
00116 inline void
00117 convertBoundToSense(const double lower, const double upper,
00118 char& sense, double& right, double& range) const;
00119
00122
00124 const char * getProblemName() const;
00125
00127 void setProblemName(const char *name);
00128
00130 int getNumCols() const;
00131
00133 int getNumRows() const;
00134
00136 int getNumElements() const;
00137
00139 const double * getColLower() const;
00140
00142 const double * getColUpper() const;
00143
00145 const double * getRowLower() const;
00146
00148 const double * getRowUpper() const;
00158 const char * getRowSense() const;
00159
00171 const double * getRightHandSide() const;
00172
00186 const double * getRowRange() const;
00187
00189 const double * getObjCoefficients() const;
00190
00192 const CoinPackedMatrix * getMatrixByRow() const;
00193
00195 const CoinPackedMatrix * getMatrixByCol() const;
00196
00198 const char * getObjName() const;
00199
00205 void getPreviousRowNames(char const * const * prev,
00206 int *card_prev) const;
00207
00212 void getPreviousColNames(char const * const * prev,
00213 int *card_prev) const;
00214
00217 char const * const * getRowNames() const;
00218
00220 char const * const *getColNames() const;
00221
00225 const char * rowName(int index) const;
00226
00230 const char * columnName(int index) const;
00231
00235 int rowIndex(const char * name) const;
00236
00239 int columnIndex(const char * name) const;
00240
00242 double objectiveOffset() const;
00243
00245 inline void setObjectiveOffset(double value)
00246 { objectiveOffset_ = value;}
00247
00250 bool isInteger(int columnNumber) const;
00251
00253 const char * integerColumns() const;
00255
00258
00259 double getInfinity() const;
00260
00263 void setInfinity(const double);
00264
00266 double getEpsilon() const;
00267
00270 void setEpsilon(const double);
00271
00273 int getNumberAcross() const;
00274
00277 void setNumberAcross(const int);
00278
00280 int getDecimals() const;
00281
00284 void setDecimals(const int);
00286
00298 void setLpDataWithoutRowAndColNames(
00299 const CoinPackedMatrix& m,
00300 const double* collb, const double* colub,
00301 const double* obj_coeff,
00302 const char* integrality,
00303 const double* rowlb, const double* rowub);
00304
00317 int is_invalid_name(const char *buff, const bool ranged) const;
00318
00335 int are_invalid_names(char const * const *vnames,
00336 const int card_vnames,
00337 const bool check_ranged) const;
00338
00341 void setDefaultRowNames();
00342
00344 void setDefaultColNames();
00345
00365 void setLpDataRowAndColNames(char const * const * const rownames,
00366 char const * const * const colnames);
00367
00382 int writeLp(const char *filename,
00383 const double epsilon,
00384 const int numberAcross,
00385 const int decimals,
00386 const bool useRowNames = true);
00387
00402 int writeLp(FILE *fp,
00403 const double epsilon,
00404 const int numberAcross,
00405 const int decimals,
00406 const bool useRowNames = true);
00407
00410 int writeLp(const char *filename, const bool useRowNames = true);
00411
00414 int writeLp(FILE *fp, const bool useRowNames = true);
00415
00420 void readLp(const char *filename, const double epsilon);
00421
00426 void readLp(const char *filename);
00427
00433 void readLp(FILE *fp, const double epsilon);
00434
00439 void readLp(FILE *fp);
00440
00442 void print() const;
00444
00445 protected:
00447 char * problemName_;
00448
00450 int numberRows_;
00451
00453 int numberColumns_;
00454
00456 int numberElements_;
00457
00459 mutable CoinPackedMatrix *matrixByColumn_;
00460
00462 CoinPackedMatrix *matrixByRow_;
00463
00465 double * rowlower_;
00466
00468 double * rowupper_;
00469
00471 double * collower_;
00472
00474 double * colupper_;
00475
00477 mutable double * rhs_;
00478
00482 mutable double *rowrange_;
00483
00485 mutable char * rowsense_;
00486
00488 double * objective_;
00489
00491 double objectiveOffset_;
00492
00495 char * integerType_;
00496
00498 char * fileName_;
00499
00501 double infinity_;
00502
00504 double epsilon_;
00505
00507 int numberAcross_;
00508
00510 int decimals_;
00511
00513 char *objName_;
00514
00521 char **previous_names_[2];
00522
00527 int card_previous_names_[2];
00528
00533 char **names_[2];
00534
00535 typedef struct {
00536 int index, next;
00537 } CoinHashLink;
00538
00542 int maxHash_[2];
00543
00547 int numberHash_[2];
00548
00552 mutable CoinHashLink *hash_[2];
00553
00559 void startHash(char const * const * const names,
00560 const COINColumnIndex number,
00561 int section);
00562
00566 void stopHash(int section);
00567
00572 COINColumnIndex findHash(const char *name, int section) const;
00573
00578 void insertHash(const char *thisName, int section);
00579
00582 void out_coeff(FILE *fp, double v, int print_1) const;
00583
00587 int find_obj(FILE *fp) const;
00588
00594 int is_subject_to(const char *buff) const;
00595
00598 int first_is_number(const char *buff) const;
00599
00602 int is_comment(const char *buff) const;
00603
00605 void skip_comment(char *buff, FILE *fp) const;
00606
00608 void scan_next(char *buff, FILE *fp) const;
00609
00612 int is_free(const char *buff) const;
00613
00616 int is_inf(const char *buff) const;
00617
00623 int is_sense(const char *buff) const;
00624
00634 int is_keyword(const char *buff) const;
00635
00638 int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt,
00639 char **obj_name);
00640
00645 int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name,
00646 int cnt_coeff) const;
00647
00649 void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
00650
00652 void realloc_row(char ***rowNames, int **start, double **rhs,
00653 double **rowlow, double **rowup, int *maxrow) const;
00654
00656 void realloc_col(double **collow, double **colup, char **is_int,
00657 int *maxcol) const;
00658
00660 void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames,
00661 int *cnt_coeff, int *maxcoeff,
00662 double *rhs, double *rowlow, double *rowup,
00663 int *cnt_row, double inf) const;
00664
00678 void checkRowNames();
00679
00688 void checkColNames();
00689
00690 };
00691