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
00087 class CoinLpIO {
00088
00089 public:
00090
00093
00094 CoinLpIO();
00095
00097 ~CoinLpIO();
00098
00104 void freePreviousNames(const int section);
00105
00107 void freeAll();
00109
00112 inline void
00113 convertBoundToSense(const double lower, const double upper,
00114 char& sense, double& right, double& range) const;
00115
00118
00120 const char * getProblemName() const;
00121
00123 int getNumCols() const;
00124
00126 int getNumRows() const;
00127
00129 int getNumElements() const;
00130
00132 const double * getColLower() const;
00133
00135 const double * getColUpper() const;
00136
00138 const double * getRowLower() const;
00139
00141 const double * getRowUpper() const;
00151 const char * getRowSense() const;
00152
00164 const double * getRightHandSide() const;
00165
00179 const double * getRowRange() const;
00180
00182 const double * getObjCoefficients() const;
00183
00185 const CoinPackedMatrix * getMatrixByRow() const;
00186
00188 const CoinPackedMatrix * getMatrixByCol() const;
00189
00191 const char * getObjName() const;
00192
00198 void getPreviousRowNames(char const * const * prev,
00199 int *card_prev) const;
00200
00205 void getPreviousColNames(char const * const * prev,
00206 int *card_prev) const;
00207
00210 char const * const * getRowNames() const;
00211
00213 char const * const *getColNames() const;
00214
00218 const char * rowName(int index) const;
00219
00223 const char * columnName(int index) const;
00224
00228 int rowIndex(const char * name) const;
00229
00232 int columnIndex(const char * name) const;
00233
00235 double objectiveOffset() const;
00236
00238 inline void setObjectiveOffset(double value)
00239 { objectiveOffset_ = value;};
00240
00243 bool isInteger(int columnNumber) const;
00244
00246 const char * integerColumns() const;
00248
00251
00252 double getInfinity() const;
00253
00256 void setInfinity(const double);
00257
00259 double getEpsilon() const;
00260
00263 void setEpsilon(const double);
00264
00266 int getNumberAcross() const;
00267
00270 void setNumberAcross(const int);
00271
00273 int getDecimals() const;
00274
00277 void setDecimals(const int);
00279
00291 void setLpDataWithoutRowAndColNames(
00292 const CoinPackedMatrix& m,
00293 const double* collb, const double* colub,
00294 const double* obj_coeff,
00295 const char* integrality,
00296 const double* rowlb, const double* rowub);
00297
00310 int is_invalid_name(const char *buff, const bool ranged) const;
00311
00328 int are_invalid_names(char const * const *vnames,
00329 const int card_vnames,
00330 const bool check_ranged) const;
00331
00334 void setDefaultRowNames();
00335
00337 void setDefaultColNames();
00338
00358 void setLpDataRowAndColNames(char const * const * const rownames,
00359 char const * const * const colnames);
00360
00375 int writeLp(const char *filename,
00376 const double epsilon,
00377 const int numberAcross,
00378 const int decimals,
00379 const bool useRowNames = true);
00380
00395 int writeLp(FILE *fp,
00396 const double epsilon,
00397 const int numberAcross,
00398 const int decimals,
00399 const bool useRowNames = true);
00400
00403 int writeLp(const char *filename, const bool useRowNames = true);
00404
00407 int writeLp(FILE *fp, const bool useRowNames = true);
00408
00413 void readLp(const char *filename, const double epsilon);
00414
00419 void readLp(const char *filename);
00420
00426 void readLp(FILE *fp, const double epsilon);
00427
00432 void readLp(FILE *fp);
00433
00435 void print() const;
00437
00438 protected:
00440 char * problemName_;
00441
00443 int numberRows_;
00444
00446 int numberColumns_;
00447
00449 int numberElements_;
00450
00452 mutable CoinPackedMatrix *matrixByColumn_;
00453
00455 CoinPackedMatrix *matrixByRow_;
00456
00458 double * rowlower_;
00459
00461 double * rowupper_;
00462
00464 double * collower_;
00465
00467 double * colupper_;
00468
00470 mutable double * rhs_;
00471
00475 mutable double *rowrange_;
00476
00478 mutable char * rowsense_;
00479
00481 double * objective_;
00482
00484 double objectiveOffset_;
00485
00488 char * integerType_;
00489
00491 char * fileName_;
00492
00494 double infinity_;
00495
00497 double epsilon_;
00498
00500 int numberAcross_;
00501
00503 int decimals_;
00504
00506 char *objName_;
00507
00514 char **previous_names_[2];
00515
00520 int card_previous_names_[2];
00521
00526 char **names_[2];
00527
00528 typedef struct {
00529 int index, next;
00530 } CoinHashLink;
00531
00535 int maxHash_[2];
00536
00540 int numberHash_[2];
00541
00545 mutable CoinHashLink *hash_[2];
00546
00552 void startHash(char const * const * const names,
00553 const COINColumnIndex number,
00554 int section);
00555
00559 void stopHash(int section);
00560
00565 COINColumnIndex findHash(const char *name, int section) const;
00566
00571 void insertHash(const char *thisName, int section);
00572
00575 void out_coeff(FILE *fp, double v, int print_1) const;
00576
00580 int find_obj(FILE *fp) const;
00581
00587 int is_subject_to(const char *buff) const;
00588
00591 int first_is_number(const char *buff) const;
00592
00595 int is_comment(const char *buff) const;
00596
00598 void skip_comment(char *buff, FILE *fp) const;
00599
00601 void scan_next(char *buff, FILE *fp) const;
00602
00605 int is_free(const char *buff) const;
00606
00612 int is_sense(const char *buff) const;
00613
00623 int is_keyword(const char *buff) const;
00624
00627 int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt,
00628 char **obj_name);
00629
00634 int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name,
00635 int cnt_coeff) const;
00636
00638 void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
00639
00641 void realloc_row(char ***rowNames, int **start, double **rhs,
00642 double **rowlow, double **rowup, int *maxrow) const;
00643
00645 void realloc_col(double **collow, double **colup, char **is_int,
00646 int *maxcol) const;
00647
00649 void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames,
00650 int *cnt_coeff, int *maxcoeff,
00651 double *rhs, double *rowlow, double *rowup,
00652 int *cnt_row, double inf) const;
00653
00667 void checkRowNames();
00668
00677 void checkColNames();
00678
00679 };
00680