CoinUtils  2.9.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinModel.hpp
Go to the documentation of this file.
1 /* $Id: CoinModel.hpp 1581 2013-04-06 12:48:50Z stefan $ */
2 // Copyright (C) 2005, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 #ifndef CoinModel_H
7 #define CoinModel_H
8 
9 #include "CoinModelUseful.hpp"
10 #include "CoinPackedMatrix.hpp"
11 #include "CoinFinite.hpp"
13 
14 public:
15 
16 
19  CoinBaseModel ();
21 
23  CoinBaseModel ( const CoinBaseModel &rhs);
24 
26  CoinBaseModel & operator=( const CoinBaseModel& rhs);
27 
29  virtual CoinBaseModel * clone() const=0;
30 
32  virtual ~CoinBaseModel () ;
34 
37  inline int numberRows() const
39  { return numberRows_;}
41  inline int numberColumns() const
42  { return numberColumns_;}
44  virtual CoinBigIndex numberElements() const = 0;
48  inline double objectiveOffset() const
49  { return objectiveOffset_;}
51  inline void setObjectiveOffset(double value)
52  { objectiveOffset_=value;}
54  inline double optimizationDirection() const {
56  }
58  inline void setOptimizationDirection(double value)
59  { optimizationDirection_=value;}
61  inline int logLevel() const
62  { return logLevel_;}
64  void setLogLevel(int value);
66  inline const char * getProblemName() const
67  { return problemName_.c_str();}
69  void setProblemName(const char *name) ;
71  void setProblemName(const std::string &name) ;
73  inline const std::string & getRowBlock() const
74  { return rowBlockName_;}
76  inline void setRowBlock(const std::string &name)
77  { rowBlockName_ = name;}
79  inline const std::string & getColumnBlock() const
80  { return columnBlockName_;}
82  inline void setColumnBlock(const std::string &name)
83  { columnBlockName_ = name;}
85 
86 protected:
89  int numberRows_;
98  std::string problemName_;
100  std::string rowBlockName_;
102  std::string columnBlockName_;
112 
114 };
115 
152 class CoinModel : public CoinBaseModel {
153 
154 public:
158  void addRow(int numberInRow, const int * columns,
159  const double * elements, double rowLower=-COIN_DBL_MAX,
160  double rowUpper=COIN_DBL_MAX, const char * name=NULL);
162  void addColumn(int numberInColumn, const int * rows,
163  const double * elements,
164  double columnLower=0.0,
165  double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
166  const char * name=NULL, bool isInteger=false);
168  inline void addCol(int numberInColumn, const int * rows,
169  const double * elements,
170  double columnLower=0.0,
171  double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
172  const char * name=NULL, bool isInteger=false)
173  { addColumn(numberInColumn, rows, elements, columnLower, columnUpper, objectiveValue,
174  name,isInteger);}
176  inline void operator() (int i,int j,double value)
177  { setElement(i,j,value);}
179  void setElement(int i,int j,double value) ;
185  int getRow(int whichRow, int * column, double * element);
191  int getColumn(int whichColumn, int * column, double * element);
193  void setQuadraticElement(int i,int j,double value) ;
195  inline void operator() (int i,int j,const char * value)
196  { setElement(i,j,value);}
198  void setElement(int i,int j,const char * value) ;
200  int associateElement(const char * stringValue, double value);
204  void setRowLower(int whichRow,double rowLower);
208  void setRowUpper(int whichRow,double rowUpper);
212  void setRowBounds(int whichRow,double rowLower,double rowUpper);
216  void setRowName(int whichRow,const char * rowName);
220  void setColumnLower(int whichColumn,double columnLower);
224  void setColumnUpper(int whichColumn,double columnUpper);
228  void setColumnBounds(int whichColumn,double columnLower,double columnUpper);
232  void setColumnObjective(int whichColumn,double columnObjective);
236  void setColumnName(int whichColumn,const char * columnName);
240  void setColumnIsInteger(int whichColumn,bool columnIsInteger);
244  inline void setObjective(int whichColumn,double columnObjective)
245  { setColumnObjective( whichColumn, columnObjective);}
249  inline void setIsInteger(int whichColumn,bool columnIsInteger)
250  { setColumnIsInteger( whichColumn, columnIsInteger);}
254  inline void setInteger(int whichColumn)
255  { setColumnIsInteger( whichColumn, true);}
259  inline void setContinuous(int whichColumn)
260  { setColumnIsInteger( whichColumn, false);}
264  inline void setColLower(int whichColumn,double columnLower)
265  { setColumnLower( whichColumn, columnLower);}
269  inline void setColUpper(int whichColumn,double columnUpper)
270  { setColumnUpper( whichColumn, columnUpper);}
274  inline void setColBounds(int whichColumn,double columnLower,double columnUpper)
275  { setColumnBounds( whichColumn, columnLower, columnUpper);}
279  inline void setColObjective(int whichColumn,double columnObjective)
280  { setColumnObjective( whichColumn, columnObjective);}
284  inline void setColName(int whichColumn,const char * columnName)
285  { setColumnName( whichColumn, columnName);}
289  inline void setColIsInteger(int whichColumn,bool columnIsInteger)
290  { setColumnIsInteger( whichColumn, columnIsInteger);}
294  void setRowLower(int whichRow,const char * rowLower);
298  void setRowUpper(int whichRow,const char * rowUpper);
302  void setColumnLower(int whichColumn,const char * columnLower);
306  void setColumnUpper(int whichColumn,const char * columnUpper);
310  void setColumnObjective(int whichColumn,const char * columnObjective);
314  void setColumnIsInteger(int whichColumn,const char * columnIsInteger);
318  inline void setObjective(int whichColumn,const char * columnObjective)
319  { setColumnObjective( whichColumn, columnObjective);}
323  inline void setIsInteger(int whichColumn,const char * columnIsInteger)
324  { setColumnIsInteger( whichColumn, columnIsInteger);}
327  void deleteRow(int whichRow);
330  void deleteColumn(int whichColumn);
333  inline void deleteCol(int whichColumn)
334  { deleteColumn(whichColumn);}
336  int deleteElement(int row, int column);
338  void deleteThisElement(int row, int column,int position);
341  int packRows();
344  int packColumns();
347  inline int packCols()
348  { return packColumns();}
353  int pack();
354 
357  void setObjective(int numberColumns,const double * objective) ;
360  void setColumnLower(int numberColumns,const double * columnLower);
363  inline void setColLower(int numberColumns,const double * columnLower)
364  { setColumnLower( numberColumns, columnLower);}
367  void setColumnUpper(int numberColumns,const double * columnUpper);
370  inline void setColUpper(int numberColumns,const double * columnUpper)
371  { setColumnUpper( numberColumns, columnUpper);}
374  void setRowLower(int numberRows,const double * rowLower);
377  void setRowUpper(int numberRows,const double * rowUpper);
378 
404  int writeMps(const char *filename, int compression = 0,
405  int formatType = 0, int numberAcross = 2, bool keepStrings=false) ;
406 
411  int differentModel(CoinModel & other, bool ignoreNames);
413 
414 
417  void passInMatrix(const CoinPackedMatrix & matrix);
421  int convertMatrix();
423  inline const CoinPackedMatrix * packedMatrix() const
424  { return packedMatrix_;}
426  inline const int * originalRows() const
427  { return rowType_;}
429  inline const int * originalColumns() const
430  { return columnType_;}
432 
433 
436  inline CoinBigIndex numberElements() const
438  { return numberElements_;}
440  inline const CoinModelTriple * elements() const
441  { return elements_;}
443  inline double operator() (int i,int j) const
444  { return getElement(i,j);}
446  double getElement(int i,int j) const;
448  inline double operator() (const char * rowName,const char * columnName) const
449  { return getElement(rowName,columnName);}
451  double getElement(const char * rowName,const char * columnName) const;
453  double getQuadraticElement(int i,int j) const;
458  const char * getElementAsString(int i,int j) const;
462  double * pointer (int i,int j) const;
466  int position (int i,int j) const;
467 
468 
472  CoinModelLink firstInRow(int whichRow) const ;
476  CoinModelLink lastInRow(int whichRow) const ;
480  CoinModelLink firstInColumn(int whichColumn) const ;
484  CoinModelLink lastInColumn(int whichColumn) const ;
489  CoinModelLink next(CoinModelLink & current) const ;
495  CoinModelLink previous(CoinModelLink & current) const ;
500  CoinModelLink firstInQuadraticColumn(int whichColumn) const ;
504  CoinModelLink lastInQuadraticColumn(int whichColumn) const ;
507  double getRowLower(int whichRow) const ;
510  double getRowUpper(int whichRow) const ;
513  const char * getRowName(int whichRow) const ;
514  inline double rowLower(int whichRow) const
515  { return getRowLower(whichRow);}
518  inline double rowUpper(int whichRow) const
519  { return getRowUpper(whichRow) ;}
522  inline const char * rowName(int whichRow) const
523  { return getRowName(whichRow);}
526  double getColumnLower(int whichColumn) const ;
529  double getColumnUpper(int whichColumn) const ;
532  double getColumnObjective(int whichColumn) const ;
535  const char * getColumnName(int whichColumn) const ;
538  bool getColumnIsInteger(int whichColumn) const ;
541  inline double columnLower(int whichColumn) const
542  { return getColumnLower(whichColumn);}
545  inline double columnUpper(int whichColumn) const
546  { return getColumnUpper(whichColumn) ;}
549  inline double columnObjective(int whichColumn) const
550  { return getColumnObjective(whichColumn);}
553  inline double objective(int whichColumn) const
554  { return getColumnObjective(whichColumn);}
557  inline const char * columnName(int whichColumn) const
558  { return getColumnName(whichColumn);}
561  inline bool columnIsInteger(int whichColumn) const
562  { return getColumnIsInteger(whichColumn);}
565  inline bool isInteger(int whichColumn) const
566  { return getColumnIsInteger(whichColumn);}
569  inline double getColLower(int whichColumn) const
570  { return getColumnLower(whichColumn);}
573  inline double getColUpper(int whichColumn) const
574  { return getColumnUpper(whichColumn) ;}
577  inline double getColObjective(int whichColumn) const
578  { return getColumnObjective(whichColumn);}
581  inline const char * getColName(int whichColumn) const
582  { return getColumnName(whichColumn);}
585  inline bool getColIsInteger(int whichColumn) const
586  { return getColumnIsInteger(whichColumn);}
589  const char * getRowLowerAsString(int whichRow) const ;
592  const char * getRowUpperAsString(int whichRow) const ;
593  inline const char * rowLowerAsString(int whichRow) const
594  { return getRowLowerAsString(whichRow);}
597  inline const char * rowUpperAsString(int whichRow) const
598  { return getRowUpperAsString(whichRow) ;}
601  const char * getColumnLowerAsString(int whichColumn) const ;
604  const char * getColumnUpperAsString(int whichColumn) const ;
607  const char * getColumnObjectiveAsString(int whichColumn) const ;
610  const char * getColumnIsIntegerAsString(int whichColumn) const ;
613  inline const char * columnLowerAsString(int whichColumn) const
614  { return getColumnLowerAsString(whichColumn);}
617  inline const char * columnUpperAsString(int whichColumn) const
618  { return getColumnUpperAsString(whichColumn) ;}
621  inline const char * columnObjectiveAsString(int whichColumn) const
622  { return getColumnObjectiveAsString(whichColumn);}
625  inline const char * objectiveAsString(int whichColumn) const
626  { return getColumnObjectiveAsString(whichColumn);}
629  inline const char * columnIsIntegerAsString(int whichColumn) const
630  { return getColumnIsIntegerAsString(whichColumn);}
633  inline const char * isIntegerAsString(int whichColumn) const
634  { return getColumnIsIntegerAsString(whichColumn);}
636  int row(const char * rowName) const;
638  int column(const char * columnName) const;
640  inline int type() const
641  { return type_;}
643  inline double unsetValue() const
644  { return -1.23456787654321e-97;}
646  int createPackedMatrix(CoinPackedMatrix & matrix,
647  const double * associated);
653  int countPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
654  const double * associated);
657  void createPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
658  int * indices,
659  const double * associated);
661  int createArrays(double * & rowLower, double * & rowUpper,
662  double * & columnLower, double * & columnUpper,
663  double * & objective, int * & integerType,
664  double * & associated);
666  inline bool stringsExist() const
667  { return string_.numberItems()!=0;}
669  inline const CoinModelHash * stringArray() const
670  { return &string_;}
672  inline double * associatedArray() const
673  { return associated_;}
675  inline double * rowLowerArray() const
676  { return rowLower_;}
678  inline double * rowUpperArray() const
679  { return rowUpper_;}
681  inline double * columnLowerArray() const
682  { return columnLower_;}
684  inline double * columnUpperArray() const
685  { return columnUpper_;}
687  inline double * objectiveArray() const
688  { return objective_;}
690  inline int * integerTypeArray() const
691  { return integerType_;}
693  inline const CoinModelHash * rowNames() const
694  { return &rowName_;}
696  inline const CoinModelHash * columnNames() const
697  { return &columnName_;}
699  inline void zapRowNames()
700  { rowName_=CoinModelHash();}
702  inline void zapColumnNames()
705  inline const int * cutMarker() const
706  { return cut_;}
708  inline double optimizationDirection() const {
709  return optimizationDirection_;
710  }
712  inline void setOptimizationDirection(double value)
713  { optimizationDirection_=value;}
715  inline void * moreInfo() const
716  { return moreInfo_;}
718  inline void setMoreInfo(void * info)
719  { moreInfo_ = info;}
728  int whatIsSet() const;
730 
748  void loadBlock (const CoinPackedMatrix& matrix,
749  const double* collb, const double* colub,
750  const double* obj,
751  const double* rowlb, const double* rowub) ;
768  void loadBlock (const CoinPackedMatrix& matrix,
769  const double* collb, const double* colub,
770  const double* obj,
771  const char* rowsen, const double* rowrhs,
772  const double* rowrng) ;
773 
786  void loadBlock (const int numcols, const int numrows,
787  const CoinBigIndex * start, const int* index,
788  const double* value,
789  const double* collb, const double* colub,
790  const double* obj,
791  const double* rowlb, const double* rowub) ;
792 
805  void loadBlock (const int numcols, const int numrows,
806  const CoinBigIndex * start, const int* index,
807  const double* value,
808  const double* collb, const double* colub,
809  const double* obj,
810  const char* rowsen, const double* rowrhs,
811  const double* rowrng) ;
812 
814 
818  CoinModel();
820  CoinModel(int firstRows, int firstColumns, int firstElements,bool noNames=false);
823  CoinModel(const char *fileName, int allowStrings=0);
827  CoinModel( int nonLinear, const char * fileName,const void * info);
830  const CoinPackedMatrix * matrix,
831  const double * rowLower, const double * rowUpper,
832  const double * columnLower, const double * columnUpper,
833  const double * objective);
835  virtual CoinBaseModel * clone() const;
836 
838  virtual ~CoinModel();
840 
844  CoinModel(const CoinModel&);
846  CoinModel& operator=(const CoinModel&);
848 
851  void validateLinks() const;
854 private:
856  void resize(int maximumRows, int maximumColumns, int maximumElements);
858  void fillRows(int which,bool forceCreation,bool fromAddRow=false);
860  void fillColumns(int which,bool forceCreation,bool fromAddColumn=false);
863  void fillList(int which, CoinModelLinkedList & list,int type) const ;
867  void createList(int type) const;
869  int addString(const char * string);
873  double getDoubleFromString(CoinYacc & info, const char * string);
875  void freeStringMemory(CoinYacc & info);
876 public:
878  int computeAssociated(double * associated);
884  CoinPackedMatrix * quadraticRow(int rowNumber,double * linear,
885  int & numberBad) const;
887  void replaceQuadraticRow(int rowNumber,const double * linear, const CoinPackedMatrix * quadraticPart);
892  CoinModel * reorder(const char * mark) const;
903  int expandKnapsack(int knapsackRow, int & numberOutput,double * buildObj, CoinBigIndex * buildStart,
904  int * buildRow, double * buildElement,int reConstruct=-1) const;
906  void setCutMarker(int size,const int * marker);
908  void setPriorities(int size,const int * priorities);
910  inline const int * priorities() const
911  { return priority_;}
913  void setOriginalIndices(const int * row, const int * column);
914 
915 private:
919  void gdb( int nonLinear, const char * fileName, const void * info);
921  int decodeBit(char * phrase, char * & nextPhrase, double & coefficient, bool ifFirst) const;
923  void badType() const;
926  int maximumRows_;
939  double * rowLower_;
941  double * rowUpper_;
951  int * rowType_;
953  double * objective_;
955  double * columnLower_;
957  double * columnUpper_;
973  int * columnType_;
975  int * start_;
993  double * sortElements_;
1003  double * associated_;
1007  int * startSOS_;
1009  int * memberSOS_;
1011  int * typeSOS_;
1015  double * referenceSOS_;
1017  int * priority_;
1019  int * cut_;
1021  void * moreInfo_;
1029  mutable int type_;
1031  bool noNames_;
1038  mutable int links_;
1040 };
1042 double getFunctionValueFromString(const char * string, const char * x, double xValue);
1044 double getDoubleFromString(CoinYacc & info, const char * string, const char * x, double xValue);
1045 #endif
int addString(const char *string)
Adds one string, returns index.
const char * isIntegerAsString(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:633
void zapColumnNames()
Reset column names.
Definition: CoinModel.hpp:702
const char * columnLowerAsString(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:613
bool noNames_
True if no names EVER being used (for users who know what they are doing)
Definition: CoinModel.hpp:1031
double columnUpper(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:545
CoinPackedMatrix * packedMatrix_
Actual elements as CoinPackedMatrix.
Definition: CoinModel.hpp:979
void setRowBounds(int whichRow, double rowLower, double rowUpper)
Sets rowLower and rowUpper (if row does not exist then all rows up to this are defined with default v...
void setColumnObjective(int whichColumn, double columnObjective)
Sets columnObjective (if column does not exist then all columns up to this are defined with default v...
CoinModelTriple * quadraticElements_
Actual quadratic elements (always linked lists)
Definition: CoinModel.hpp:987
void setColIsInteger(int whichColumn, bool columnIsInteger)
Sets integer (if column does not exist then all columns up to this are defined with default values an...
Definition: CoinModel.hpp:289
int decodeBit(char *phrase, char *&nextPhrase, double &coefficient, bool ifFirst) const
returns jColumn (-2 if linear term, -1 if unknown) and coefficient
void resize(int maximumRows, int maximumColumns, int maximumElements)
Resize.
int sizeAssociated_
Size of associated values.
Definition: CoinModel.hpp:1001
double * associatedArray() const
Returns associated array.
Definition: CoinModel.hpp:672
void setPriorities(int size, const int *priorities)
Sets priority array.
int packCols()
Packs down all columns i.e.
Definition: CoinModel.hpp:347
double unsetValue() const
returns unset value
Definition: CoinModel.hpp:643
const CoinModelHash * rowNames() const
Return row names array.
Definition: CoinModel.hpp:693
const int * priorities() const
priorities (given for all columns (-1 if not integer)
Definition: CoinModel.hpp:910
void createPlusMinusOne(CoinBigIndex *startPositive, CoinBigIndex *startNegative, int *indices, const double *associated)
Creates +-1 matrix given startPositive and startNegative counts for +-1 matrix.
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:708
CoinModelLink firstInQuadraticColumn(int whichColumn) const
Returns first element in given quadratic column - index is -1 if none.
const char * columnObjectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:621
double optimizationDirection_
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:94
const int * originalColumns() const
Return pointers to original columns (for decomposition)
Definition: CoinModel.hpp:429
double * rowUpperArray() const
Return rowUpper array.
Definition: CoinModel.hpp:678
void setColObjective(int whichColumn, double columnObjective)
Sets columnObjective (if column does not exist then all columns up to this are defined with default v...
Definition: CoinModel.hpp:279
void setRowLower(int whichRow, double rowLower)
Sets rowLower (if row does not exist then all rows up to this are defined with default values and no ...
const CoinModelHash * stringArray() const
Return string array.
Definition: CoinModel.hpp:669
int type() const
Returns type.
Definition: CoinModel.hpp:640
void createList(int type) const
Create a linked list and synchronize free type 1 for row 2 for column Marked as const as list is muta...
CoinModelLinkedList rowList_
Linked list for rows.
Definition: CoinModel.hpp:983
bool stringsExist() const
Says if strings exist.
Definition: CoinModel.hpp:666
const char * getColumnObjectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
int row(const char *rowName) const
Row index from row name (-1 if no names or no match)
int * start_
If simple then start of each row/column.
Definition: CoinModel.hpp:975
int numberQuadraticElements_
Current number of quadratic elements.
Definition: CoinModel.hpp:935
CoinModelLink previous(CoinModelLink &current) const
Returns previous element in current row or column - index is -1 if none.
void deleteCol(int whichColumn)
Deletes all entries in column and bounds.
Definition: CoinModel.hpp:333
const char * getColumnName(int whichColumn) const
Gets name (if column does not exist then NULL)
void setColumnBlock(const std::string &name)
Set column block name.
Definition: CoinModel.hpp:82
int numberElements_
Current number of elements.
Definition: CoinModel.hpp:931
int getRow(int whichRow, int *column, double *element)
Gets sorted row - user must provide enough space (easiest is allocate number of columns).
CoinPackedMatrix * quadraticRow(int rowNumber, double *linear, int &numberBad) const
Gets correct form for a quadratic row - user to delete If row is not quadratic then returns which oth...
double * rowLower_
Row lower.
Definition: CoinModel.hpp:939
void fillList(int which, CoinModelLinkedList &list, int type) const
Fill in default linked list information (1= row, 2 = column) Marked as const as list is mutable...
void setColLower(int numberColumns, const double *columnLower)
Sets columnLower array.
Definition: CoinModel.hpp:363
void operator()(int i, int j, double value)
Sets value for row i and column j.
Definition: CoinModel.hpp:176
virtual CoinBigIndex numberElements() const =0
Return number of elements.
CoinModel * reorder(const char *mark) const
If possible return a model where if all variables marked nonzero are fixed the problem will be linear...
int sortSize_
Size of sort arrays.
Definition: CoinModel.hpp:995
int * cut_
Nonzero if row is cut - done in one go e.g. from ampl.
Definition: CoinModel.hpp:1019
const char * columnUpperAsString(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:617
void setColumnIsInteger(int whichColumn, bool columnIsInteger)
Sets integer state (if column does not exist then all columns up to this are defined with default val...
int expandKnapsack(int knapsackRow, int &numberOutput, double *buildObj, CoinBigIndex *buildStart, int *buildRow, double *buildElement, int reConstruct=-1) const
Expands out all possible combinations for a knapsack If buildObj NULL then just computes space needed...
This is a simple minded model which is stored in a format which makes it easier to construct and modi...
Definition: CoinModel.hpp:152
double rowLower(int whichRow) const
Definition: CoinModel.hpp:514
const char * getColumnIsIntegerAsString(int whichColumn) const
Gets if integer (if column does not exist then false)
int * memberSOS_
SOS members.
Definition: CoinModel.hpp:1009
void passInMatrix(const CoinPackedMatrix &matrix)
Pass in CoinPackedMatrix (and switch off element updates)
For int,int hashing.
const char * getProblemName() const
Return the problem name.
Definition: CoinModel.hpp:66
int pack()
Packs down all rows and columns.
double * rowUpper_
Row upper.
Definition: CoinModel.hpp:941
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:54
bool columnIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:561
int maximumRows_
Maximum number of rows.
Definition: CoinModel.hpp:927
void badType() const
Aborts with message about packedMatrix.
int createPackedMatrix(CoinPackedMatrix &matrix, const double *associated)
Creates a packed matrix - return number of errors.
int createArrays(double *&rowLower, double *&rowUpper, double *&columnLower, double *&columnUpper, double *&objective, int *&integerType, double *&associated)
Creates copies of various arrays - return number of errors.
void setIsInteger(int whichColumn, bool columnIsInteger)
Sets integer state (if column does not exist then all columns up to this are defined with default val...
Definition: CoinModel.hpp:249
int * rowType_
Row types.
Definition: CoinModel.hpp:951
int * typeSOS_
SOS type.
Definition: CoinModel.hpp:1011
void * moreInfo() const
Return pointer to more information.
Definition: CoinModel.hpp:715
int convertMatrix()
Convert elements to CoinPackedMatrix (and switch off element updates).
int maximumElements_
Maximum number of elements.
Definition: CoinModel.hpp:933
double getElement(int i, int j) const
Returns value for row i and column j.
void setQuadraticElement(int i, int j, double value)
Sets quadratic value for column i and j.
void addColumn(int numberInColumn, const int *rows, const double *elements, double columnLower=0.0, double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0, const char *name=NULL, bool isInteger=false)
add a column - numberInColumn may be zero */
CoinModel()
Default constructor.
double * columnUpper_
Column Upper.
Definition: CoinModel.hpp:957
void deleteColumn(int whichColumn)
Deletes all entries in column and bounds and objective.
void fillRows(int which, bool forceCreation, bool fromAddRow=false)
Fill in default row information.
int maximumQuadraticElements_
Maximum number of quadratic elements.
Definition: CoinModel.hpp:937
int * columnType_
Column types.
Definition: CoinModel.hpp:973
int whatIsSet() const
Returns which parts of model are set 1 - matrix 2 - rhs 4 - row names 8 - column bounds and/or object...
int * priority_
priorities (given for all columns (-1 if not integer)
Definition: CoinModel.hpp:1017
void setOptimizationDirection(double value)
Set direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:712
void fillColumns(int which, bool forceCreation, bool fromAddColumn=false)
Fill in default column information.
const char * getRowUpperAsString(int whichRow) const
Gets rowUpper (if row does not exist then +COIN_DBL_MAX)
double * objective_
Objective.
Definition: CoinModel.hpp:953
double * referenceSOS_
SOS reference.
Definition: CoinModel.hpp:1015
void setRowName(int whichRow, const char *rowName)
Sets name (if row does not exist then all rows up to this are defined with default values and no elem...
CoinModelHash string_
Strings.
Definition: CoinModel.hpp:963
int numberColumns() const
Return number of columns.
Definition: CoinModel.hpp:41
void setColName(int whichColumn, const char *columnName)
Sets name (if column does not exist then all columns up to this are defined with default values and n...
Definition: CoinModel.hpp:284
const char * rowLowerAsString(int whichRow) const
Definition: CoinModel.hpp:593
double * columnLower_
Column Lower.
Definition: CoinModel.hpp:955
double getRowUpper(int whichRow) const
Gets rowUpper (if row does not exist then +COIN_DBL_MAX)
virtual ~CoinModel()
Destructor.
int packColumns()
Packs down all columns i.e.
virtual CoinBaseModel * clone() const
Clone.
double getQuadraticElement(int i, int j) const
Returns quadratic value for columns i and j.
void freeStringMemory(CoinYacc &info)
Frees value memory.
CoinModelTriple * elements_
Actual elements.
Definition: CoinModel.hpp:977
void setContinuous(int whichColumn)
Sets continuous (if column does not exist then all columns up to this are defined with default values...
Definition: CoinModel.hpp:259
CoinModelLinkedList quadraticRowList_
Linked list for quadratic rows.
Definition: CoinModel.hpp:997
double * columnLowerArray() const
Return columnLower array.
Definition: CoinModel.hpp:681
void setColumnLower(int whichColumn, double columnLower)
Sets columnLower (if column does not exist then all columns up to this are defined with default value...
for linked lists
double objective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:553
const char * columnName(int whichColumn) const
Gets name (if column does not exist then NULL)
Definition: CoinModel.hpp:557
double * associated_
Associated values.
Definition: CoinModel.hpp:1003
void deleteThisElement(int row, int column, int position)
Takes element out of matrix when position known.
CoinModelLink firstInColumn(int whichColumn) const
Returns first element in given column - index is -1 if none.
bool isInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:565
CoinModelHash2 hashQuadraticElements_
Hash for quadratic elements.
Definition: CoinModel.hpp:989
const char * getColumnUpperAsString(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
double columnLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:541
double getColLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:569
const CoinPackedMatrix * packedMatrix() const
Return a pointer to CoinPackedMatrix (or NULL)
Definition: CoinModel.hpp:423
void deleteRow(int whichRow)
Deletes all entries in row and bounds.
CoinModelLinkedList quadraticColumnList_
Linked list for quadratic columns.
Definition: CoinModel.hpp:999
const char * getElementAsString(int i, int j) const
Returns value for row i and column j as string.
void setColumnName(int whichColumn, const char *columnName)
Sets name (if column does not exist then all columns up to this are defined with default values and n...
CoinBaseModel()
Default Constructor.
double getColumnObjective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
const char * columnIsIntegerAsString(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:629
void setIsInteger(int whichColumn, const char *columnIsInteger)
Sets integer (if column does not exist then all columns up to this are defined with default values an...
Definition: CoinModel.hpp:323
double * columnUpperArray() const
Return columnUpper array.
Definition: CoinModel.hpp:684
CoinModel & operator=(const CoinModel &)
=
int deleteElement(int row, int column)
Takes element out of matrix - returning position (<0 if not there);.
int numberSOS_
Number of SOS - all these are done in one go e.g. from ampl.
Definition: CoinModel.hpp:1005
double rowUpper(int whichRow) const
Gets rowUpper (if row does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:518
std::string rowBlockName_
Rowblock name.
Definition: CoinModel.hpp:100
int differentModel(CoinModel &other, bool ignoreNames)
Check two models against each other.
void setMoreInfo(void *info)
Set pointer to more information.
Definition: CoinModel.hpp:718
void gdb(int nonLinear, const char *fileName, const void *info)
Read a problem from AMPL nl file so not constructor so gdb will work.
void setColUpper(int whichColumn, double columnUpper)
Sets columnUpper (if column does not exist then all columns up to this are defined with default value...
Definition: CoinModel.hpp:269
void setColumnBounds(int whichColumn, double columnLower, double columnUpper)
Sets columnLower and columnUpper (if column does not exist then all columns up to this are defined wi...
CoinModelLink lastInColumn(int whichColumn) const
Returns last element in given column - index is -1 if none.
int numberColumns_
Current number of columns.
Definition: CoinModel.hpp:92
void setOriginalIndices(const int *row, const int *column)
For decomposition set original row and column indices.
Sparse Matrix Base Class.
int logLevel() const
Get print level 0 - off, 1 - errors, 2 - more.
Definition: CoinModel.hpp:61
int type_
Type of build - -1 unset, 0 for row, 1 for column, 2 linked.
Definition: CoinModel.hpp:1029
int column(const char *columnName) const
Column index from column name (-1 if no names or no match)
int associateElement(const char *stringValue, double value)
Associates a string with a value. Returns string id (or -1 if does not exist)
CoinModelLink lastInRow(int whichRow) const
Returns last element in given row - index is -1 if none.
CoinModelLinkedList columnList_
Linked list for columns.
Definition: CoinModel.hpp:985
int * startSOS_
SOS starts.
Definition: CoinModel.hpp:1007
void setCutMarker(int size, const int *marker)
Sets cut marker array.
int * prioritySOS_
SOS priority.
Definition: CoinModel.hpp:1013
double getColUpper(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:573
void * moreInfo_
Pointer to more information.
Definition: CoinModel.hpp:1021
const char * rowName(int whichRow) const
Gets name (if row does not exist then NULL)
Definition: CoinModel.hpp:522
void setRowUpper(int whichRow, double rowUpper)
Sets rowUpper (if row does not exist then all rows up to this are defined with default values and no ...
virtual CoinBaseModel * clone() const =0
Clone.
int CoinBigIndex
bool getColIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:585
int numberItems() const
Number of items i.e. rows if just row names.
void setProblemName(const char *name)
Set problem name.
void validateLinks() const
Checks that links are consistent.
double getRowLower(int whichRow) const
Gets rowLower (if row does not exist then -COIN_DBL_MAX)
int numberRows_
Current number of rows.
Definition: CoinModel.hpp:90
const char * objectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:625
const std::string & getRowBlock() const
Return the row block name.
Definition: CoinModel.hpp:73
int writeMps(const char *filename, int compression=0, int formatType=0, int numberAcross=2, bool keepStrings=false)
Write the problem in MPS format to a file with the given filename.
void zapRowNames()
Reset row names.
Definition: CoinModel.hpp:699
const char * getColumnLowerAsString(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
double getColObjective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:577
double * sortElements_
Array for sorting elements.
Definition: CoinModel.hpp:993
void setColumnUpper(int whichColumn, double columnUpper)
Sets columnUpper (if column does not exist then all columns up to this are defined with default value...
void setObjective(int whichColumn, const char *columnObjective)
Sets columnObjective (if column does not exist then all columns up to this are defined with default v...
Definition: CoinModel.hpp:318
int getColumn(int whichColumn, int *column, double *element)
Gets sorted column - user must provide enough space (easiest is allocate number of rows)...
double objectiveOffset_
Objective offset to be passed on.
Definition: CoinModel.hpp:96
int position(int i, int j) const
Returns position in elements for row i column j.
int * integerTypeArray() const
Return integerType array.
Definition: CoinModel.hpp:690
int computeAssociated(double *associated)
Fills in all associated - returning number of errors.
const char * getRowName(int whichRow) const
Gets name (if row does not exist then NULL)
const char * getColName(int whichColumn) const
Gets name (if column does not exist then NULL)
Definition: CoinModel.hpp:581
CoinModelHash2 hashElements_
Hash for elements.
Definition: CoinModel.hpp:981
double getDoubleFromString(CoinYacc &info, const char *string)
Gets a double from a string possibly containing named strings, returns unset if not found...
int links_
Links present (could be tested by sizes of objects) 0 - none, 1 - row links, 2 - column links...
Definition: CoinModel.hpp:1038
double objectiveOffset() const
Returns the (constant) objective offset This is the RHS entry for the objective row.
Definition: CoinModel.hpp:48
const CoinModelHash * columnNames() const
Return column names array.
Definition: CoinModel.hpp:696
void setRowBlock(const std::string &name)
Set row block name.
Definition: CoinModel.hpp:76
void setElement(int i, int j, double value)
Sets value for row i and column j.
double getColumnUpper(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
std::string columnBlockName_
Columnblock name.
Definition: CoinModel.hpp:102
void setOptimizationDirection(double value)
Set direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:58
double columnObjective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:549
const std::string & getColumnBlock() const
Return the column block name.
Definition: CoinModel.hpp:79
int numberRows() const
Return number of rows.
Definition: CoinModel.hpp:38
double getDoubleFromString(CoinYacc &info, const char *string, const char *x, double xValue)
faster version
int maximumColumns_
Maximum number of columns.
Definition: CoinModel.hpp:929
CoinBigIndex numberElements() const
Return number of elements.
Definition: CoinModel.hpp:437
const double COIN_DBL_MAX
Definition: CoinFinite.hpp:18
void addCol(int numberInColumn, const int *rows, const double *elements, double columnLower=0.0, double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0, const char *name=NULL, bool isInteger=false)
add a column - numberInColumn may be zero */
Definition: CoinModel.hpp:168
void setLogLevel(int value)
Set print level 0 - off, 1 - errors, 2 - more.
double * rowLowerArray() const
Return rowLower array.
Definition: CoinModel.hpp:675
int * sortIndices_
Array for sorting indices.
Definition: CoinModel.hpp:991
CoinBaseModel & operator=(const CoinBaseModel &rhs)
Assignment operator.
int countPlusMinusOne(CoinBigIndex *startPositive, CoinBigIndex *startNegative, const double *associated)
Fills in startPositive and startNegative with counts for +-1 matrix.
double getColumnLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
const char * getRowLowerAsString(int whichRow) const
Gets rowLower (if row does not exist then -COIN_DBL_MAX)
void setColLower(int whichColumn, double columnLower)
Sets columnLower (if column does not exist then all columns up to this are defined with default value...
Definition: CoinModel.hpp:264
void loadBlock(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub)
Load in a problem by copying the arguments.
virtual ~CoinBaseModel()
Destructor.
bool getColumnIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
CoinModelLink lastInQuadraticColumn(int whichColumn) const
Returns last element in given quadratic column - index is -1 if none.
int logLevel_
Print level.
Definition: CoinModel.hpp:110
void setColUpper(int numberColumns, const double *columnUpper)
Sets columnUpper array.
Definition: CoinModel.hpp:370
double * objectiveArray() const
Return objective array.
Definition: CoinModel.hpp:687
CoinModelLink firstInRow(int whichRow) const
Returns first element in given row - index is -1 if none.
void setInteger(int whichColumn)
Sets integer (if column does not exist then all columns up to this are defined with default values an...
Definition: CoinModel.hpp:254
void replaceQuadraticRow(int rowNumber, const double *linear, const CoinPackedMatrix *quadraticPart)
Replaces a quadratic row.
const int * originalRows() const
Return pointers to original rows (for decomposition)
Definition: CoinModel.hpp:426
CoinModelLink next(CoinModelLink &current) const
Returns next element in current row or column - index is -1 if none.
void setColBounds(int whichColumn, double columnLower, double columnUpper)
Sets columnLower and columnUpper (if column does not exist then all columns up to this are defined wi...
Definition: CoinModel.hpp:274
std::string problemName_
Problem name.
Definition: CoinModel.hpp:98
void addRow(int numberInRow, const int *columns, const double *elements, double rowLower=-COIN_DBL_MAX, double rowUpper=COIN_DBL_MAX, const char *name=NULL)
add a row - numberInRow may be zero
CoinModelHash columnName_
Column names.
Definition: CoinModel.hpp:959
double * pointer(int i, int j) const
Returns pointer to element for row i column j.
CoinModelHash rowName_
Row names.
Definition: CoinModel.hpp:943
int * integerType_
Integer information.
Definition: CoinModel.hpp:961
double getFunctionValueFromString(const char *string, const char *x, double xValue)
Just function of single variable x.
void setObjective(int whichColumn, double columnObjective)
Sets columnObjective (if column does not exist then all columns up to this are defined with default v...
Definition: CoinModel.hpp:244
const char * rowUpperAsString(int whichRow) const
Gets rowUpper (if row does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:597
const int * cutMarker() const
Returns array of 0 or nonzero if can be a cut (or returns NULL)
Definition: CoinModel.hpp:705
int packRows()
Packs down all rows i.e.
void setObjectiveOffset(double value)
Set objective offset.
Definition: CoinModel.hpp:51
const CoinModelTriple * elements() const
Return elements as triples.
Definition: CoinModel.hpp:440