CoinLpIO.hpp
Go to the documentation of this file.
1 /* $Id: CoinLpIO.hpp 1215 2009-11-05 11:03:04Z 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 
14 #include <cstdio>
15 
17 
18 typedef int COINColumnIndex;
19 
91 class CoinLpIO {
92 
93 public:
94 
97  CoinLpIO();
99 
101  ~CoinLpIO();
102 
108  void freePreviousNames(const int section);
109 
111  void freeAll();
113 
116  inline void
117  convertBoundToSense(const double lower, const double upper,
118  char& sense, double& right, double& range) const;
119 
122 
124  const char * getProblemName() const;
125 
127  void setProblemName(const char *name);
128 
130  int getNumCols() const;
131 
133  int getNumRows() const;
134 
136  int getNumElements() const;
137 
139  const double * getColLower() const;
140 
142  const double * getColUpper() const;
143 
145  const double * getRowLower() const;
146 
148  const double * getRowUpper() const;
158  const char * getRowSense() const;
159 
171  const double * getRightHandSide() const;
172 
186  const double * getRowRange() const;
187 
189  const double * getObjCoefficients() const;
190 
192  const CoinPackedMatrix * getMatrixByRow() const;
193 
195  const CoinPackedMatrix * getMatrixByCol() const;
196 
198  const char * getObjName() const;
199 
205  void getPreviousRowNames(char const * const * prev,
206  int *card_prev) const;
207 
212  void getPreviousColNames(char const * const * prev,
213  int *card_prev) const;
214 
217  char const * const * getRowNames() const;
218 
220  char const * const *getColNames() const;
221 
225  const char * rowName(int index) const;
226 
230  const char * columnName(int index) const;
231 
235  int rowIndex(const char * name) const;
236 
239  int columnIndex(const char * name) const;
240 
242  double objectiveOffset() const;
243 
245  inline void setObjectiveOffset(double value)
246  { objectiveOffset_ = value;}
247 
250  bool isInteger(int columnNumber) const;
251 
253  const char * integerColumns() const;
255 
258  double getInfinity() const;
260 
263  void setInfinity(const double);
264 
266  double getEpsilon() const;
267 
270  void setEpsilon(const double);
271 
273  int getNumberAcross() const;
274 
277  void setNumberAcross(const int);
278 
280  int getDecimals() const;
281 
284  void setDecimals(const int);
286 
299  const CoinPackedMatrix& m,
300  const double* collb, const double* colub,
301  const double* obj_coeff,
302  const char* integrality,
303  const double* rowlb, const double* rowub);
304 
317  int is_invalid_name(const char *buff, const bool ranged) const;
318 
335  int are_invalid_names(char const * const *vnames,
336  const int card_vnames,
337  const bool check_ranged) const;
338 
341  void setDefaultRowNames();
342 
344  void setDefaultColNames();
345 
365  void setLpDataRowAndColNames(char const * const * const rownames,
366  char const * const * const colnames);
367 
382  int writeLp(const char *filename,
383  const double epsilon,
384  const int numberAcross,
385  const int decimals,
386  const bool useRowNames = true);
387 
402  int writeLp(FILE *fp,
403  const double epsilon,
404  const int numberAcross,
405  const int decimals,
406  const bool useRowNames = true);
407 
410  int writeLp(const char *filename, const bool useRowNames = true);
411 
414  int writeLp(FILE *fp, const bool useRowNames = true);
415 
420  void readLp(const char *filename, const double epsilon);
421 
426  void readLp(const char *filename);
427 
433  void readLp(FILE *fp, const double epsilon);
434 
439  void readLp(FILE *fp);
440 
442  void print() const;
444 
445 protected:
447  char * problemName_;
448 
451 
454 
457 
460 
463 
465  double * rowlower_;
466 
468  double * rowupper_;
469 
471  double * collower_;
472 
474  double * colupper_;
475 
477  mutable double * rhs_;
478 
482  mutable double *rowrange_;
483 
485  mutable char * rowsense_;
486 
488  double * objective_;
489 
492 
495  char * integerType_;
496 
498  char * fileName_;
499 
501  double infinity_;
502 
504  double epsilon_;
505 
508 
511 
513  char *objName_;
514 
521  char **previous_names_[2];
522 
528 
533  char **names_[2];
534 
535  typedef struct {
536  int index, next;
537  } CoinHashLink;
538 
542  int maxHash_[2];
543 
547  int numberHash_[2];
548 
552  mutable CoinHashLink *hash_[2];
553 
559  void startHash(char const * const * const names,
560  const COINColumnIndex number,
561  int section);
562 
566  void stopHash(int section);
567 
572  COINColumnIndex findHash(const char *name, int section) const;
573 
578  void insertHash(const char *thisName, int section);
579 
582  void out_coeff(FILE *fp, double v, int print_1) const;
583 
587  int find_obj(FILE *fp) const;
588 
594  int is_subject_to(const char *buff) const;
595 
598  int first_is_number(const char *buff) const;
599 
602  int is_comment(const char *buff) const;
603 
605  void skip_comment(char *buff, FILE *fp) const;
606 
608  void scan_next(char *buff, FILE *fp) const;
609 
612  int is_free(const char *buff) const;
613 
616  int is_inf(const char *buff) const;
617 
623  int is_sense(const char *buff) const;
624 
634  int is_keyword(const char *buff) const;
635 
638  int read_monom_obj(FILE *fp, double *coeff, char **name, int *cnt,
639  char **obj_name);
640 
645  int read_monom_row(FILE *fp, char *start_str, double *coeff, char **name,
646  int cnt_coeff) const;
647 
649  void realloc_coeff(double **coeff, char ***colNames, int *maxcoeff) const;
650 
652  void realloc_row(char ***rowNames, int **start, double **rhs,
653  double **rowlow, double **rowup, int *maxrow) const;
654 
656  void realloc_col(double **collow, double **colup, char **is_int,
657  int *maxcol) const;
658 
660  void read_row(FILE *fp, char *buff, double **pcoeff, char ***pcolNames,
661  int *cnt_coeff, int *maxcoeff,
662  double *rhs, double *rowlow, double *rowup,
663  int *cnt_row, double inf) const;
664 
678  void checkRowNames();
679 
688  void checkColNames();
689 
690 };
691