CoinUtils trunk
|
00001 /* $Id$ */ 00002 // Last edit: 11/5/08 00003 // 00004 // Name: CoinLpIO.hpp; Support for Lp files 00005 // Author: Francois Margot 00006 // Tepper School of Business 00007 // Carnegie Mellon University, Pittsburgh, PA 15213 00008 // email: fmargot@andrew.cmu.edu 00009 // Date: 12/28/03 00010 //----------------------------------------------------------------------------- 00011 // Copyright (C) 2003, Francois Margot, International Business Machines 00012 // Corporation and others. All Rights Reserved. 00013 // This code is licensed under the terms of the Eclipse Public License (EPL). 00014 00015 00016 #include <cstdio> 00017 00018 class CoinPackedMatrix; 00019 #include "CoinMessage.hpp" 00020 00021 typedef int COINColumnIndex; 00022 00094 class CoinLpIO { 00095 00096 public: 00097 00100 00101 CoinLpIO(); 00102 00104 ~CoinLpIO(); 00105 00111 void freePreviousNames(const int section); 00112 00114 void freeAll(); 00116 00119 inline void 00120 convertBoundToSense(const double lower, const double upper, 00121 char& sense, double& right, double& range) const; 00122 00125 00127 const char * getProblemName() const; 00128 00130 void setProblemName(const char *name); 00131 00133 int getNumCols() const; 00134 00136 int getNumRows() const; 00137 00139 int getNumElements() const; 00140 00142 const double * getColLower() const; 00143 00145 const double * getColUpper() const; 00146 00148 const double * getRowLower() const; 00149 00151 const double * getRowUpper() const; 00161 const char * getRowSense() const; 00162 00174 const double * getRightHandSide() const; 00175 00189 const double * getRowRange() const; 00190 00192 const double * getObjCoefficients() const; 00193 00195 const CoinPackedMatrix * getMatrixByRow() const; 00196 00198 const CoinPackedMatrix * getMatrixByCol() const; 00199 00201 const char * getObjName() const; 00202 00208 void getPreviousRowNames(char const * const * prev, 00209 int *card_prev) const; 00210 00215 void getPreviousColNames(char const * const * prev, 00216 int *card_prev) const; 00217 00220 char const * const * getRowNames() const; 00221 00223 char const * const *getColNames() const; 00224 00228 const char * rowName(int index) const; 00229 00233 const char * columnName(int index) const; 00234 00238 int rowIndex(const char * name) const; 00239 00242 int columnIndex(const char * name) const; 00243 00245 double objectiveOffset() const; 00246 00248 inline void setObjectiveOffset(double value) 00249 { objectiveOffset_ = value;} 00250 00253 bool isInteger(int columnNumber) const; 00254 00256 const char * integerColumns() const; 00258 00261 00262 double getInfinity() const; 00263 00266 void setInfinity(const double); 00267 00269 double getEpsilon() const; 00270 00273 void setEpsilon(const double); 00274 00276 int getNumberAcross() const; 00277 00280 void setNumberAcross(const int); 00281 00283 int getDecimals() const; 00284 00287 void setDecimals(const int); 00289 00301 void setLpDataWithoutRowAndColNames( 00302 const CoinPackedMatrix& m, 00303 const double* collb, const double* colub, 00304 const double* obj_coeff, 00305 const char* integrality, 00306 const double* rowlb, const double* rowub); 00307 00320 int is_invalid_name(const char *buff, const bool ranged) const; 00321 00338 int are_invalid_names(char const * const *vnames, 00339 const int card_vnames, 00340 const bool check_ranged) const; 00341 00344 void setDefaultRowNames(); 00345 00347 void setDefaultColNames(); 00348 00368 void setLpDataRowAndColNames(char const * const * const rownames, 00369 char const * const * const colnames); 00370 00385 int writeLp(const char *filename, 00386 const double epsilon, 00387 const int numberAcross, 00388 const int decimals, 00389 const bool useRowNames = true); 00390 00405 int writeLp(FILE *fp, 00406 const double epsilon, 00407 const int numberAcross, 00408 const int decimals, 00409 const bool useRowNames = true); 00410 00413 int writeLp(const char *filename, const bool useRowNames = true); 00414 00417 int writeLp(FILE *fp, const bool useRowNames = true); 00418 00423 void readLp(const char *filename, const double epsilon); 00424 00429 void readLp(const char *filename); 00430 00436 void readLp(FILE *fp, const double epsilon); 00437 00442 void readLp(FILE *fp); 00443 00445 void print() const; 00447 00454 void passInMessageHandler(CoinMessageHandler * handler); 00455 00457 void newLanguage(CoinMessages::Language language); 00458 00460 inline void setLanguage(CoinMessages::Language language) {newLanguage(language);} 00461 00463 inline CoinMessageHandler * messageHandler() const {return handler_;} 00464 00466 inline CoinMessages messages() {return messages_;} 00468 inline CoinMessages * messagesPointer() {return & messages_;} 00470 00471 protected: 00473 char * problemName_; 00474 00476 CoinMessageHandler * handler_; 00482 bool defaultHandler_; 00484 CoinMessages messages_; 00485 00487 int numberRows_; 00488 00490 int numberColumns_; 00491 00493 int numberElements_; 00494 00496 mutable CoinPackedMatrix *matrixByColumn_; 00497 00499 CoinPackedMatrix *matrixByRow_; 00500 00502 double * rowlower_; 00503 00505 double * rowupper_; 00506 00508 double * collower_; 00509 00511 double * colupper_; 00512 00514 mutable double * rhs_; 00515 00519 mutable double *rowrange_; 00520 00522 mutable char * rowsense_; 00523 00525 double * objective_; 00526 00528 double objectiveOffset_; 00529 00532 char * integerType_; 00533 00535 char * fileName_; 00536 00538 double infinity_; 00539 00541 double epsilon_; 00542 00544 int numberAcross_; 00545 00547 int decimals_; 00548 00550 char *objName_; 00551 00558 char **previous_names_[2]; 00559 00564 int card_previous_names_[2]; 00565 00570 char **names_[2]; 00571 00572 typedef struct { 00573 int index, next; 00574 } CoinHashLink; 00575 00579 int maxHash_[2]; 00580 00584 int numberHash_[2]; 00585 00589 mutable CoinHashLink *hash_[2]; 00590 00596 void startHash(char const * const * const names, 00597 const COINColumnIndex number, 00598 int section); 00599 00603 void stopHash(int section); 00604 00609 COINColumnIndex findHash(const char *name, int section) const; 00610 00615 void insertHash(const char *thisName, int section); 00616 00619 void out_coeff(FILE *fp, double v, int print_1) const; 00620 00624 int find_obj(FILE *fp) const; 00625 00631 int is_subject_to(const char *buff) const; 00632 00635 int first_is_number(const char *buff) const; 00636 00639 int is_comment(const char *buff) const; 00640 00642 void skip_comment(char *buff, FILE *fp) const; 00643 00645 void scan_next(char *buff, FILE *fp) const; 00646 00649 int is_free(const char *buff) const; 00650 00653 int is_inf(const char *buff) const; 00654 00660 int is_sense(const char *buff) const; 00661 00671 int is_keyword(const char *buff) const; 00672 00675 int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt, 00676 char **obj_name); 00677 00682 int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name, 00683 int cnt_coeff) const; 00684 00686 void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const; 00687 00689 void realloc_row(char ***rowNames, int **start, double **rhs, 00690 double **rowlow, double **rowup, int *maxrow) const; 00691 00693 void realloc_col(double **collow, double **colup, char **is_int, 00694 int *maxcol) const; 00695 00697 void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames, 00698 int *cnt_coeff, int *maxcoeff, 00699 double *rhs, double *rowlow, double *rowup, 00700 int *cnt_row, double inf) const; 00701 00715 void checkRowNames(); 00716 00725 void checkColNames(); 00726 00727 }; 00728