CoinUtils  2.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinLpIO.hpp
Go to the documentation of this file.
1 /* $Id: CoinLpIO.hpp 1411 2011-03-30 11:40:33Z forrest $ */
2 // Last edit: 11/5/08
3 //
4 // Name: CoinLpIO.hpp; Support for Lp files
5 // Author: Francois Margot
6 // Tepper School of Business
7 // Carnegie Mellon University, Pittsburgh, PA 15213
8 // email: fmargot@andrew.cmu.edu
9 // Date: 12/28/03
10 //-----------------------------------------------------------------------------
11 // Copyright (C) 2003, Francois Margot, International Business Machines
12 // Corporation and others. All Rights Reserved.
13 // This code is licensed under the terms of the Eclipse Public License (EPL).
14 
15 
16 #include <cstdio>
17 
19 #include "CoinMessage.hpp"
20 
21 typedef int COINColumnIndex;
22 
94 class CoinLpIO {
95 
96 public:
97 
100  CoinLpIO();
102 
104  ~CoinLpIO();
105 
111  void freePreviousNames(const int section);
112 
114  void freeAll();
116 
119  inline void
120  convertBoundToSense(const double lower, const double upper,
121  char& sense, double& right, double& range) const;
122 
125 
127  const char * getProblemName() const;
128 
130  void setProblemName(const char *name);
131 
133  int getNumCols() const;
134 
136  int getNumRows() const;
137 
139  int getNumElements() const;
140 
142  const double * getColLower() const;
143 
145  const double * getColUpper() const;
146 
148  const double * getRowLower() const;
149 
151  const double * getRowUpper() const;
161  const char * getRowSense() const;
162 
174  const double * getRightHandSide() const;
175 
189  const double * getRowRange() const;
190 
192  const double * getObjCoefficients() const;
193 
195  const CoinPackedMatrix * getMatrixByRow() const;
196 
198  const CoinPackedMatrix * getMatrixByCol() const;
199 
201  const char * getObjName() const;
202 
208  void getPreviousRowNames(char const * const * prev,
209  int *card_prev) const;
210 
215  void getPreviousColNames(char const * const * prev,
216  int *card_prev) const;
217 
220  char const * const * getRowNames() const;
221 
223  char const * const *getColNames() const;
224 
228  const char * rowName(int index) const;
229 
233  const char * columnName(int index) const;
234 
238  int rowIndex(const char * name) const;
239 
242  int columnIndex(const char * name) const;
243 
245  double objectiveOffset() const;
246 
248  inline void setObjectiveOffset(double value)
249  { objectiveOffset_ = value;}
250 
253  bool isInteger(int columnNumber) const;
254 
256  const char * integerColumns() const;
258 
261  double getInfinity() const;
263 
266  void setInfinity(const double);
267 
269  double getEpsilon() const;
270 
273  void setEpsilon(const double);
274 
276  int getNumberAcross() const;
277 
280  void setNumberAcross(const int);
281 
283  int getDecimals() const;
284 
287  void setDecimals(const int);
289 
302  const CoinPackedMatrix& m,
303  const double* collb, const double* colub,
304  const double* obj_coeff,
305  const char* integrality,
306  const double* rowlb, const double* rowub);
307 
320  int is_invalid_name(const char *buff, const bool ranged) const;
321 
338  int are_invalid_names(char const * const *vnames,
339  const int card_vnames,
340  const bool check_ranged) const;
341 
344  void setDefaultRowNames();
345 
347  void setDefaultColNames();
348 
368  void setLpDataRowAndColNames(char const * const * const rownames,
369  char const * const * const colnames);
370 
385  int writeLp(const char *filename,
386  const double epsilon,
387  const int numberAcross,
388  const int decimals,
389  const bool useRowNames = true);
390 
405  int writeLp(FILE *fp,
406  const double epsilon,
407  const int numberAcross,
408  const int decimals,
409  const bool useRowNames = true);
410 
413  int writeLp(const char *filename, const bool useRowNames = true);
414 
417  int writeLp(FILE *fp, const bool useRowNames = true);
418 
423  void readLp(const char *filename, const double epsilon);
424 
429  void readLp(const char *filename);
430 
436  void readLp(FILE *fp, const double epsilon);
437 
442  void readLp(FILE *fp);
443 
445  void print() const;
447 
455 
457  void newLanguage(CoinMessages::Language language);
458 
460  inline void setLanguage(CoinMessages::Language language) {newLanguage(language);}
461 
463  inline CoinMessageHandler * messageHandler() const {return handler_;}
464 
466  inline CoinMessages messages() {return messages_;}
468  inline CoinMessages * messagesPointer() {return & messages_;}
470 
471 protected:
473  char * problemName_;
474 
485 
488 
491 
494 
497 
500 
502  double * rowlower_;
503 
505  double * rowupper_;
506 
508  double * collower_;
509 
511  double * colupper_;
512 
514  mutable double * rhs_;
515 
519  mutable double *rowrange_;
520 
522  mutable char * rowsense_;
523 
525  double * objective_;
526 
529 
532  char * integerType_;
533 
535  char * fileName_;
536 
538  double infinity_;
539 
541  double epsilon_;
542 
545 
548 
550  char *objName_;
551 
558  char **previous_names_[2];
559 
565 
570  char **names_[2];
571 
572  typedef struct {
573  int index, next;
574  } CoinHashLink;
575 
579  int maxHash_[2];
580 
584  int numberHash_[2];
585 
589  mutable CoinHashLink *hash_[2];
590 
596  void startHash(char const * const * const names,
597  const COINColumnIndex number,
598  int section);
599 
603  void stopHash(int section);
604 
609  COINColumnIndex findHash(const char *name, int section) const;
610 
615  void insertHash(const char *thisName, int section);
616 
619  void out_coeff(FILE *fp, double v, int print_1) const;
620 
624  int find_obj(FILE *fp) const;
625 
631  int is_subject_to(const char *buff) const;
632 
635  int first_is_number(const char *buff) const;
636 
639  int is_comment(const char *buff) const;
640 
642  void skip_comment(char *buff, FILE *fp) const;
643 
645  void scan_next(char *buff, FILE *fp) const;
646 
649  int is_free(const char *buff) const;
650 
653  int is_inf(const char *buff) const;
654 
660  int is_sense(const char *buff) const;
661 
671  int is_keyword(const char *buff) const;
672 
675  int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt,
676  char **obj_name);
677 
682  int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name,
683  int cnt_coeff) const;
684 
686  void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
687 
689  void realloc_row(char ***rowNames, int **start, double **rhs,
690  double **rowlow, double **rowup, int *maxrow) const;
691 
693  void realloc_col(double **collow, double **colup, char **is_int,
694  int *maxcol) const;
695 
697  void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames,
698  int *cnt_coeff, int *maxcoeff,
699  double *rhs, double *rowlow, double *rowup,
700  int *cnt_row, double inf) const;
701 
715  void checkRowNames();
716 
725  void checkColNames();
726 
727 };
728