CoinModel.hpp
Go to the documentation of this file.
1 /* $Id: CoinModel.hpp 1215 2009-11-05 11:03:04Z forrest $ */
2 // Copyright (C) 2005, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 #ifndef CoinModel_H
5 #define CoinModel_H
6 
7 #include "CoinModelUseful.hpp"
8 #include "CoinPackedMatrix.hpp"
9 class CoinBaseModel {
10 
11 public:
12 
13 
16  CoinBaseModel ();
18 
20  CoinBaseModel ( const CoinBaseModel &rhs);
21 
23  CoinBaseModel & operator=( const CoinBaseModel& rhs);
24 
26  virtual CoinBaseModel * clone() const=0;
27 
29  virtual ~CoinBaseModel () ;
31 
34  inline int numberRows() const
36  { return numberRows_;}
38  inline int numberColumns() const
39  { return numberColumns_;}
41  virtual CoinBigIndex numberElements() const = 0;
45  inline double objectiveOffset() const
46  { return objectiveOffset_;}
48  inline void setObjectiveOffset(double value)
49  { objectiveOffset_=value;}
51  inline double optimizationDirection() const {
53  }
55  inline void setOptimizationDirection(double value)
56  { optimizationDirection_=value;}
58  inline int logLevel() const
59  { return logLevel_;}
61  void setLogLevel(int value);
63  inline const char * getProblemName() const
64  { return problemName_.c_str();}
66  void setProblemName(const char *name) ;
68  void setProblemName(const std::string &name) ;
70  inline const std::string & getRowBlock() const
71  { return rowBlockName_;}
73  inline void setRowBlock(const std::string &name)
74  { rowBlockName_ = name;}
76  inline const std::string & getColumnBlock() const
77  { return columnBlockName_;}
79  inline void setColumnBlock(const std::string &name)
80  { columnBlockName_ = name;}
82 
83 protected:
86  int numberRows_;
95  std::string problemName_;
97  std::string rowBlockName_;
99  std::string columnBlockName_;
109 
111 };
112 
149 class CoinModel : public CoinBaseModel {
150 
151 public:
155  void addRow(int numberInRow, const int * columns,
156  const double * elements, double rowLower=-COIN_DBL_MAX,
157  double rowUpper=COIN_DBL_MAX, const char * name=NULL);
159  void addColumn(int numberInColumn, const int * rows,
160  const double * elements,
161  double columnLower=0.0,
162  double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
163  const char * name=NULL, bool isInteger=false);
165  inline void addCol(int numberInColumn, const int * rows,
166  const double * elements,
167  double columnLower=0.0,
168  double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
169  const char * name=NULL, bool isInteger=false)
170  { addColumn(numberInColumn, rows, elements, columnLower, columnUpper, objectiveValue,
171  name,isInteger);}
173  inline void operator() (int i,int j,double value)
174  { setElement(i,j,value);}
176  void setElement(int i,int j,double value) ;
182  int getRow(int whichRow, int * column, double * element);
188  int getColumn(int whichColumn, int * column, double * element);
190  void setQuadraticElement(int i,int j,double value) ;
192  inline void operator() (int i,int j,const char * value)
193  { setElement(i,j,value);}
195  void setElement(int i,int j,const char * value) ;
197  int associateElement(const char * stringValue, double value);
201  void setRowLower(int whichRow,double rowLower);
205  void setRowUpper(int whichRow,double rowUpper);
209  void setRowBounds(int whichRow,double rowLower,double rowUpper);
213  void setRowName(int whichRow,const char * rowName);
217  void setColumnLower(int whichColumn,double columnLower);
221  void setColumnUpper(int whichColumn,double columnUpper);
225  void setColumnBounds(int whichColumn,double columnLower,double columnUpper);
229  void setColumnObjective(int whichColumn,double columnObjective);
233  void setColumnName(int whichColumn,const char * columnName);
237  void setColumnIsInteger(int whichColumn,bool columnIsInteger);
241  inline void setObjective(int whichColumn,double columnObjective)
242  { setColumnObjective( whichColumn, columnObjective);}
246  inline void setIsInteger(int whichColumn,bool columnIsInteger)
247  { setColumnIsInteger( whichColumn, columnIsInteger);}
251  inline void setInteger(int whichColumn)
252  { setColumnIsInteger( whichColumn, true);}
256  inline void setContinuous(int whichColumn)
257  { setColumnIsInteger( whichColumn, false);}
261  inline void setColLower(int whichColumn,double columnLower)
262  { setColumnLower( whichColumn, columnLower);}
266  inline void setColUpper(int whichColumn,double columnUpper)
267  { setColumnUpper( whichColumn, columnUpper);}
271  inline void setColBounds(int whichColumn,double columnLower,double columnUpper)
272  { setColumnBounds( whichColumn, columnLower, columnUpper);}
276  inline void setColObjective(int whichColumn,double columnObjective)
277  { setColumnObjective( whichColumn, columnObjective);}
281  inline void setColName(int whichColumn,const char * columnName)
282  { setColumnName( whichColumn, columnName);}
286  inline void setColIsInteger(int whichColumn,bool columnIsInteger)
287  { setColumnIsInteger( whichColumn, columnIsInteger);}
291  void setRowLower(int whichRow,const char * rowLower);
295  void setRowUpper(int whichRow,const char * rowUpper);
299  void setColumnLower(int whichColumn,const char * columnLower);
303  void setColumnUpper(int whichColumn,const char * columnUpper);
307  void setColumnObjective(int whichColumn,const char * columnObjective);
311  void setColumnIsInteger(int whichColumn,const char * columnIsInteger);
315  inline void setObjective(int whichColumn,const char * columnObjective)
316  { setColumnObjective( whichColumn, columnObjective);}
320  inline void setIsInteger(int whichColumn,const char * columnIsInteger)
321  { setColumnIsInteger( whichColumn, columnIsInteger);}
324  void deleteRow(int whichRow);
327  void deleteColumn(int whichColumn);
330  inline void deleteCol(int whichColumn)
331  { deleteColumn(whichColumn);}
333  int deleteElement(int row, int column);
335  void deleteThisElement(int row, int column,int position);
338  int packRows();
341  int packColumns();
344  inline int packCols()
345  { return packColumns();}
350  int pack();
351 
354  void setObjective(int numberColumns,const double * objective) ;
357  void setColumnLower(int numberColumns,const double * columnLower);
360  inline void setColLower(int numberColumns,const double * columnLower)
361  { setColumnLower( numberColumns, columnLower);}
364  void setColumnUpper(int numberColumns,const double * columnUpper);
367  inline void setColUpper(int numberColumns,const double * columnUpper)
368  { setColumnUpper( numberColumns, columnUpper);}
371  void setRowLower(int numberRows,const double * rowLower);
374  void setRowUpper(int numberRows,const double * rowUpper);
375 
401  int writeMps(const char *filename, int compression = 0,
402  int formatType = 0, int numberAcross = 2, bool keepStrings=false) ;
403 
408  int differentModel(CoinModel & other, bool ignoreNames);
410 
411 
414  void passInMatrix(const CoinPackedMatrix & matrix);
418  int convertMatrix();
420  inline const CoinPackedMatrix * packedMatrix() const
421  { return packedMatrix_;}
423  inline const int * originalRows() const
424  { return rowType_;}
426  inline const int * originalColumns() const
427  { return columnType_;}
429 
430 
433  inline CoinBigIndex numberElements() const
435  { return numberElements_;}
437  inline const CoinModelTriple * elements() const
438  { return elements_;}
440  inline double operator() (int i,int j) const
441  { return getElement(i,j);}
443  double getElement(int i,int j) const;
445  inline double operator() (const char * rowName,const char * columnName) const
446  { return getElement(rowName,columnName);}
448  double getElement(const char * rowName,const char * columnName) const;
450  double getQuadraticElement(int i,int j) const;
455  const char * getElementAsString(int i,int j) const;
459  double * pointer (int i,int j) const;
463  int position (int i,int j) const;
464 
465 
469  CoinModelLink firstInRow(int whichRow) const ;
473  CoinModelLink lastInRow(int whichRow) const ;
477  CoinModelLink firstInColumn(int whichColumn) const ;
481  CoinModelLink lastInColumn(int whichColumn) const ;
486  CoinModelLink next(CoinModelLink & current) const ;
492  CoinModelLink previous(CoinModelLink & current) const ;
497  CoinModelLink firstInQuadraticColumn(int whichColumn) const ;
501  CoinModelLink lastInQuadraticColumn(int whichColumn) const ;
504  double getRowLower(int whichRow) const ;
507  double getRowUpper(int whichRow) const ;
510  const char * getRowName(int whichRow) const ;
511  inline double rowLower(int whichRow) const
512  { return getRowLower(whichRow);}
515  inline double rowUpper(int whichRow) const
516  { return getRowUpper(whichRow) ;}
519  inline const char * rowName(int whichRow) const
520  { return getRowName(whichRow);}
523  double getColumnLower(int whichColumn) const ;
526  double getColumnUpper(int whichColumn) const ;
529  double getColumnObjective(int whichColumn) const ;
532  const char * getColumnName(int whichColumn) const ;
535  bool getColumnIsInteger(int whichColumn) const ;
538  inline double columnLower(int whichColumn) const
539  { return getColumnLower(whichColumn);}
542  inline double columnUpper(int whichColumn) const
543  { return getColumnUpper(whichColumn) ;}
546  inline double columnObjective(int whichColumn) const
547  { return getColumnObjective(whichColumn);}
550  inline double objective(int whichColumn) const
551  { return getColumnObjective(whichColumn);}
554  inline const char * columnName(int whichColumn) const
555  { return getColumnName(whichColumn);}
558  inline bool columnIsInteger(int whichColumn) const
559  { return getColumnIsInteger(whichColumn);}
562  inline bool isInteger(int whichColumn) const
563  { return getColumnIsInteger(whichColumn);}
566  inline double getColLower(int whichColumn) const
567  { return getColumnLower(whichColumn);}
570  inline double getColUpper(int whichColumn) const
571  { return getColumnUpper(whichColumn) ;}
574  inline double getColObjective(int whichColumn) const
575  { return getColumnObjective(whichColumn);}
578  inline const char * getColName(int whichColumn) const
579  { return getColumnName(whichColumn);}
582  inline bool getColIsInteger(int whichColumn) const
583  { return getColumnIsInteger(whichColumn);}
586  const char * getRowLowerAsString(int whichRow) const ;
589  const char * getRowUpperAsString(int whichRow) const ;
590  inline const char * rowLowerAsString(int whichRow) const
591  { return getRowLowerAsString(whichRow);}
594  inline const char * rowUpperAsString(int whichRow) const
595  { return getRowUpperAsString(whichRow) ;}
598  const char * getColumnLowerAsString(int whichColumn) const ;
601  const char * getColumnUpperAsString(int whichColumn) const ;
604  const char * getColumnObjectiveAsString(int whichColumn) const ;
607  const char * getColumnIsIntegerAsString(int whichColumn) const ;
610  inline const char * columnLowerAsString(int whichColumn) const
611  { return getColumnLowerAsString(whichColumn);}
614  inline const char * columnUpperAsString(int whichColumn) const
615  { return getColumnUpperAsString(whichColumn) ;}
618  inline const char * columnObjectiveAsString(int whichColumn) const
619  { return getColumnObjectiveAsString(whichColumn);}
622  inline const char * objectiveAsString(int whichColumn) const
623  { return getColumnObjectiveAsString(whichColumn);}
626  inline const char * columnIsIntegerAsString(int whichColumn) const
627  { return getColumnIsIntegerAsString(whichColumn);}
630  inline const char * isIntegerAsString(int whichColumn) const
631  { return getColumnIsIntegerAsString(whichColumn);}
633  int row(const char * rowName) const;
635  int column(const char * columnName) const;
637  inline int type() const
638  { return type_;}
640  inline double unsetValue() const
641  { return -1.23456787654321e-97;}
643  int createPackedMatrix(CoinPackedMatrix & matrix,
644  const double * associated);
650  int countPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
651  const double * associated);
654  void createPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
655  int * indices,
656  const double * associated);
658  int createArrays(double * & rowLower, double * & rowUpper,
659  double * & columnLower, double * & columnUpper,
660  double * & objective, int * & integerType,
661  double * & associated);
663  inline bool stringsExist() const
664  { return string_.numberItems()!=0;}
666  inline const CoinModelHash * stringArray() const
667  { return &string_;}
669  inline double * associatedArray() const
670  { return associated_;}
672  inline double * rowLowerArray() const
673  { return rowLower_;}
675  inline double * rowUpperArray() const
676  { return rowUpper_;}
678  inline double * columnLowerArray() const
679  { return columnLower_;}
681  inline double * columnUpperArray() const
682  { return columnUpper_;}
684  inline double * objectiveArray() const
685  { return objective_;}
687  inline int * integerTypeArray() const
688  { return integerType_;}
690  inline const CoinModelHash * rowNames() const
691  { return &rowName_;}
693  inline const CoinModelHash * columnNames() const
694  { return &columnName_;}
696  inline const int * cutMarker() const
697  { return cut_;}
699  inline double optimizationDirection() const {
700  return optimizationDirection_;
701  }
703  inline void setOptimizationDirection(double value)
704  { optimizationDirection_=value;}
706  inline void * moreInfo() const
707  { return moreInfo_;}
709  inline void setMoreInfo(void * info)
710  { moreInfo_ = info;}
719  int whatIsSet() const;
721 
739  void loadBlock (const CoinPackedMatrix& matrix,
740  const double* collb, const double* colub,
741  const double* obj,
742  const double* rowlb, const double* rowub) ;
759  void loadBlock (const CoinPackedMatrix& matrix,
760  const double* collb, const double* colub,
761  const double* obj,
762  const char* rowsen, const double* rowrhs,
763  const double* rowrng) ;
764 
777  void loadBlock (const int numcols, const int numrows,
778  const CoinBigIndex * start, const int* index,
779  const double* value,
780  const double* collb, const double* colub,
781  const double* obj,
782  const double* rowlb, const double* rowub) ;
783 
796  void loadBlock (const int numcols, const int numrows,
797  const CoinBigIndex * start, const int* index,
798  const double* value,
799  const double* collb, const double* colub,
800  const double* obj,
801  const char* rowsen, const double* rowrhs,
802  const double* rowrng) ;
803 
805 
809  CoinModel();
812  CoinModel(const char *fileName, int allowStrings=0);
816  CoinModel( int nonLinear, const char * fileName,const void * info);
819  const CoinPackedMatrix * matrix,
820  const double * rowLower, const double * rowUpper,
821  const double * columnLower, const double * columnUpper,
822  const double * objective);
824  virtual CoinBaseModel * clone() const;
825 
827  virtual ~CoinModel();
829 
833  CoinModel(const CoinModel&);
835  CoinModel& operator=(const CoinModel&);
837 
840  void validateLinks() const;
843 private:
845  void resize(int maximumRows, int maximumColumns, int maximumElements);
847  void fillRows(int which,bool forceCreation,bool fromAddRow=false);
849  void fillColumns(int which,bool forceCreation,bool fromAddColumn=false);
852  void fillList(int which, CoinModelLinkedList & list,int type) const ;
856  void createList(int type) const;
858  int addString(const char * string);
862  double getDoubleFromString(CoinYacc & info, const char * string);
864  void freeStringMemory(CoinYacc & info);
865 public:
867  int computeAssociated(double * associated);
873  CoinPackedMatrix * quadraticRow(int rowNumber,double * linear,
874  int & numberBad) const;
876  void replaceQuadraticRow(int rowNumber,const double * linear, const CoinPackedMatrix * quadraticPart);
881  CoinModel * reorder(const char * mark) const;
892  int expandKnapsack(int knapsackRow, int & numberOutput,double * buildObj, CoinBigIndex * buildStart,
893  int * buildRow, double * buildElement,int reConstruct=-1) const;
895  void setCutMarker(int size,const int * marker);
897  void setPriorities(int size,const int * priorities);
899  inline const int * priorities() const
900  { return priority_;}
902  void setOriginalIndices(const int * row, const int * column);
903 
904 private:
908  void gdb( int nonLinear, const char * fileName, const void * info);
910  int decodeBit(char * phrase, char * & nextPhrase, double & coefficient, bool ifFirst) const;
912  void badType() const;
915  int maximumRows_;
928  double * rowLower_;
930  double * rowUpper_;
940  int * rowType_;
942  double * objective_;
944  double * columnLower_;
946  double * columnUpper_;
962  int * columnType_;
964  int * start_;
982  double * sortElements_;
992  double * associated_;
996  int * startSOS_;
998  int * memberSOS_;
1000  int * typeSOS_;
1004  double * referenceSOS_;
1006  int * priority_;
1008  int * cut_;
1010  void * moreInfo_;
1018  mutable int type_;
1025  mutable int links_;
1027 };
1029 double getFunctionValueFromString(const char * string, const char * x, double xValue);
1031 double getDoubleFromString(CoinYacc & info, const char * string, const char * x, double xValue);
1032 #endif
int maximumQuadraticElements_
Maximum number of quadratic elements.
Definition: CoinModel.hpp:926
int CoinBigIndex
double getColLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:566
const char * getRowName(int whichRow) const
Gets name (if row does not exist then NULL)
const char * objectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:622
int * rowType_
Row types.
Definition: CoinModel.hpp:940
int associateElement(const char *stringValue, double value)
Associates a string with a value. Returns string id (or -1 if does not exist)
This is a simple minded model which is stored in a format which makes it easier to construct and modi...
Definition: CoinModel.hpp:149
double objective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:550
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 */
void * moreInfo() const
Return pointer to more information.
Definition: CoinModel.hpp:706
const char * getRowLowerAsString(int whichRow) const
Gets rowLower (if row does not exist then -COIN_DBL_MAX)
int * sortIndices_
Array for sorting indices.
Definition: CoinModel.hpp:980
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:241
int * startSOS_
SOS starts.
Definition: CoinModel.hpp:996
const char * getElementAsString(int i, int j) const
Returns value for row i and column j as string.
const int * priorities() const
priorities (given for all columns (-1 if not integer)
Definition: CoinModel.hpp:899
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 ...
int type() const
Returns type.
Definition: CoinModel.hpp:637
void * moreInfo_
Pointer to more information.
Definition: CoinModel.hpp:1010
double getQuadraticElement(int i, int j) const
Returns quadratic value for columns i and j.
double unsetValue() const
returns unset value
Definition: CoinModel.hpp:640
int * priority_
priorities (given for all columns (-1 if not integer)
Definition: CoinModel.hpp:1006
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 getColumnUpper(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
CoinModel()
Default constructor.
CoinModelHash rowName_
Row names.
Definition: CoinModel.hpp:932
int * integerType_
Integer information.
Definition: CoinModel.hpp:950
CoinModelLinkedList quadraticColumnList_
Linked list for quadratic columns.
Definition: CoinModel.hpp:988
CoinModelLink firstInQuadraticColumn(int whichColumn) const
Returns first element in given quadratic column - index is -1 if none.
int numberItems() const
Number of items i.e. rows if just row names.
CoinPackedMatrix * packedMatrix_
Actual elements as CoinPackedMatrix.
Definition: CoinModel.hpp:968
int * integerTypeArray() const
Return integerType array.
Definition: CoinModel.hpp:687
const int * originalRows() const
Return pointers to original rows (for decomposition)
Definition: CoinModel.hpp:423
std::string rowBlockName_
Rowblock name.
Definition: CoinModel.hpp:97
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:51
double * columnLowerArray() const
Return columnLower 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:276
const CoinModelHash * columnNames() const
Return column names array.
Definition: CoinModel.hpp:693
double * columnLower_
Column Lower.
Definition: CoinModel.hpp:944
int * columnType_
Column types.
Definition: CoinModel.hpp:962
std::string problemName_
Problem name.
Definition: CoinModel.hpp:95
int addString(const char *string)
Adds one string, returns index.
const int * originalColumns() const
Return pointers to original columns (for decomposition)
Definition: CoinModel.hpp:426
double * rowLower_
Row lower.
Definition: CoinModel.hpp:928
const CoinModelHash * stringArray() const
Return string array.
Definition: CoinModel.hpp:666
CoinModelLinkedList columnList_
Linked list for columns.
Definition: CoinModel.hpp:974
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...
int maximumColumns_
Maximum number of columns.
Definition: CoinModel.hpp:918
const char * columnLowerAsString(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:610
bool getColumnIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
double getColUpper(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:570
int differentModel(CoinModel &other, bool ignoreNames)
Check two models against each other.
CoinModelLink firstInColumn(int whichColumn) const
Returns first element in given column - index is -1 if none.
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:256
CoinModelHash string_
Strings.
Definition: CoinModel.hpp:952
int whatIsSet() const
Returns which parts of model are set 1 - matrix 2 - rhs 4 - row names 8 - column bounds and/or object...
double rowUpper(int whichRow) const
Gets rowUpper (if row does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:515
void createPlusMinusOne(CoinBigIndex *startPositive, CoinBigIndex *startNegative, int *indices, const double *associated)
Creates +-1 matrix given startPositive and startNegative counts for +-1 matrix.
void setOptimizationDirection(double value)
Set direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:55
void fillColumns(int which, bool forceCreation, bool fromAddColumn=false)
Fill in default column information.
Sparse Matrix Base Class.
int numberSOS_
Number of SOS - all these are done in one go e.g. from ampl.
Definition: CoinModel.hpp:994
void badType() const
Aborts with message about packedMatrix.
int getRow(int whichRow, int *column, double *element)
Gets sorted row - user must provide enough space (easiest is allocate number of columns).
double getFunctionValueFromString(const char *string, const char *x, double xValue)
Just function of single variable x.
const char * getColumnObjectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
CoinModelTriple * elements_
Actual elements.
Definition: CoinModel.hpp:966
int numberQuadraticElements_
Current number of quadratic elements.
Definition: CoinModel.hpp:924
bool columnIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:558
const char * getColumnLowerAsString(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
int deleteElement(int row, int column)
Takes element out of matrix - returning position (<0 if not there);.
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 deleteThisElement(int row, int column, int position)
Takes element out of matrix when position known.
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 ...
void setOriginalIndices(const int *row, const int *column)
For decomposition set original row and column indices.
double * objective_
Objective.
Definition: CoinModel.hpp:942
CoinBaseModel & operator=(const CoinBaseModel &rhs)
Assignment operator.
const char * getColName(int whichColumn) const
Gets name (if column does not exist then NULL)
Definition: CoinModel.hpp:578
double * rowUpper_
Row upper.
Definition: CoinModel.hpp:930
double * referenceSOS_
SOS reference.
Definition: CoinModel.hpp:1004
void setElement(int i, int j, double value)
Sets value for row i and column j.
CoinModelHash columnName_
Column names.
Definition: CoinModel.hpp:948
const char * rowUpperAsString(int whichRow) const
Gets rowUpper (if row does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:594
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...
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...
CoinModelLink previous(CoinModelLink &current) const
Returns previous element in current row or column - index is -1 if none.
void fillRows(int which, bool forceCreation, bool fromAddRow=false)
Fill in default row information.
void setLogLevel(int value)
Set print level 0 - off, 1 - errors, 2 - more.
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...
CoinModel & operator=(const CoinModel &)
=
void validateLinks() const
Checks that links are consistent.
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:271
virtual ~CoinBaseModel()
Destructor.
int numberColumns() const
Return number of columns.
Definition: CoinModel.hpp:38
void setOptimizationDirection(double value)
Set direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:703
int * cut_
Nonzero if row is cut - done in one go e.g. from ampl.
Definition: CoinModel.hpp:1008
int sizeAssociated_
Size of associated values.
Definition: CoinModel.hpp:990
void setRowBlock(const std::string &name)
Set row block name.
Definition: CoinModel.hpp:73
CoinModelHash2 hashElements_
Hash for elements.
Definition: CoinModel.hpp:970
double * rowLowerArray() const
Return rowLower array.
Definition: CoinModel.hpp:672
int logLevel_
Print level.
Definition: CoinModel.hpp:107
void setColLower(int numberColumns, const double *columnLower)
Sets columnLower array.
Definition: CoinModel.hpp:360
int sortSize_
Size of sort arrays.
Definition: CoinModel.hpp:984
int getColumn(int whichColumn, int *column, double *element)
Gets sorted column - user must provide enough space (easiest is allocate number of rows)...
CoinModelLink lastInRow(int whichRow) const
Returns last element in given row - index is -1 if none.
double getColumnObjective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
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:266
const char * columnName(int whichColumn) const
Gets name (if column does not exist then NULL)
Definition: CoinModel.hpp:554
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:165
const char * columnUpperAsString(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:614
double * pointer(int i, int j) const
Returns pointer to element for row i column j.
void setQuadraticElement(int i, int j, double value)
Sets quadratic value for column i and j.
const std::string & getRowBlock() const
Return the row block name.
Definition: CoinModel.hpp:70
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...
double * objectiveArray() const
Return objective array.
Definition: CoinModel.hpp:684
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:261
const char * isIntegerAsString(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:630
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.
#define COIN_DBL_MAX
This has #defines etc for the "C" interface to Coin.
void setColumnObjective(int whichColumn, double columnObjective)
Sets columnObjective (if column does not exist then all columns up to this are defined with default v...
CoinBaseModel()
Default Constructor.
double * rowUpperArray() const
Return rowUpper array.
Definition: CoinModel.hpp:675
virtual CoinBigIndex numberElements() const =0
Return number of elements.
const CoinModelHash * rowNames() const
Return row names array.
Definition: CoinModel.hpp:690
int logLevel() const
Get print level 0 - off, 1 - errors, 2 - more.
Definition: CoinModel.hpp:58
CoinModelLink lastInQuadraticColumn(int whichColumn) const
Returns last element in given quadratic column - index is -1 if none.
int * start_
If simple then start of each row/column.
Definition: CoinModel.hpp:964
const CoinPackedMatrix * packedMatrix() const
Return a pointer to CoinPackedMatrix (or NULL)
Definition: CoinModel.hpp:420
int packCols()
Packs down all columns i.e.
Definition: CoinModel.hpp:344
double columnLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:538
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...
double getColumnLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
CoinModelLink lastInColumn(int whichColumn) const
Returns last element in given column - index is -1 if none.
bool stringsExist() const
Says if strings exist.
Definition: CoinModel.hpp:663
int numberRows_
Current number of rows.
Definition: CoinModel.hpp:87
void passInMatrix(const CoinPackedMatrix &matrix)
Pass in CoinPackedMatrix (and switch off element updates)
virtual CoinBaseModel * clone() const
Clone.
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...
std::string columnBlockName_
Columnblock name.
Definition: CoinModel.hpp:99
double * associatedArray() const
Returns associated array.
Definition: CoinModel.hpp:669
const char * columnObjectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:618
bool getColIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:582
int * memberSOS_
SOS members.
Definition: CoinModel.hpp:998
int column(const char *columnName) const
Column index from column name (-1 if no names or no match)
const char * getColumnName(int whichColumn) const
Gets name (if column does not exist then NULL)
int decodeBit(char *phrase, char *&nextPhrase, double &coefficient, bool ifFirst) const
returns jColumn (-2 if linear term, -1 if unknown) and coefficient
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
const int * cutMarker() const
Returns array of 0 or nonzero if can be a cut (or returns NULL)
Definition: CoinModel.hpp:696
const char * getProblemName() const
Return the problem name.
Definition: CoinModel.hpp:63
const char * getColumnIsIntegerAsString(int whichColumn) const
Gets if integer (if column does not exist then false)
double objectiveOffset() const
Returns the (constant) objective offset This is the RHS entry for the objective row.
Definition: CoinModel.hpp:45
void setPriorities(int size, const int *priorities)
Sets priority array.
double columnObjective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:546
int * typeSOS_
SOS type.
Definition: CoinModel.hpp:1000
double * sortElements_
Array for sorting elements.
Definition: CoinModel.hpp:982
void deleteCol(int whichColumn)
Deletes all entries in column and bounds.
Definition: CoinModel.hpp:330
CoinModelLinkedList quadraticRowList_
Linked list for quadratic rows.
Definition: CoinModel.hpp:986
const char * getRowUpperAsString(int whichRow) const
Gets rowUpper (if row does not exist then +COIN_DBL_MAX)
void setCutMarker(int size, const int *marker)
Sets cut marker array.
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:246
virtual ~CoinModel()
Destructor.
void gdb(int nonLinear, const char *fileName, const void *info)
Read a problem from AMPL nl file so not constructor so gdb will work.
double getDoubleFromString(CoinYacc &info, const char *string)
Gets a double from a string possibly containing named strings, returns unset if not found...
double getDoubleFromString(CoinYacc &info, const char *string, const char *x, double xValue)
faster version
double columnUpper(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:542
double * associated_
Associated values.
Definition: CoinModel.hpp:992
double objectiveOffset_
Objective offset to be passed on.
Definition: CoinModel.hpp:93
CoinModelHash2 hashQuadraticElements_
Hash for quadratic elements.
Definition: CoinModel.hpp:978
double optimizationDirection_
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:91
int type_
Type of build - -1 unset, 0 for row, 1 for column, 2 linked.
Definition: CoinModel.hpp:1018
int convertMatrix()
Convert elements to CoinPackedMatrix (and switch off element updates).
double getRowUpper(int whichRow) const
Gets rowUpper (if row does not exist then +COIN_DBL_MAX)
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:251
int computeAssociated(double *associated)
Fills in all associated - returning number of errors.
const std::string & getColumnBlock() const
Return the column block name.
Definition: CoinModel.hpp:76
bool isInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:562
double getRowLower(int whichRow) const
Gets rowLower (if row does not exist then -COIN_DBL_MAX)
void setColumnLower(int whichColumn, double columnLower)
Sets columnLower (if column does not exist then all columns up to this are defined with default value...
int packColumns()
Packs down all columns i.e.
void setColumnBlock(const std::string &name)
Set column block name.
Definition: CoinModel.hpp:79
double getColObjective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:574
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:699
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. The constraints on the rows are given by lower and upper ...
CoinModelTriple * quadraticElements_
Actual quadratic elements (always linked lists)
Definition: CoinModel.hpp:976
CoinModel * reorder(const char *mark) const
If possible return a model where if all variables marked nonzero are fixed the problem will be linear...
const CoinModelTriple * elements() const
Return elements as triples.
Definition: CoinModel.hpp:437
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:281
double * columnUpper_
Column Upper.
Definition: CoinModel.hpp:946
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 setColUpper(int numberColumns, const double *columnUpper)
Sets columnUpper array.
Definition: CoinModel.hpp:367
int * prioritySOS_
SOS priority.
Definition: CoinModel.hpp:1002
void setObjectiveOffset(double value)
Set objective offset.
Definition: CoinModel.hpp:48
void resize(int maximumRows, int maximumColumns, int maximumElements)
Resize.
virtual CoinBaseModel * clone() const =0
Clone.
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:286
int links_
Links present (could be tested by sizes of objects) 0 - none, 1 - row links, 2 - column links...
Definition: CoinModel.hpp:1025
CoinModelLinkedList rowList_
Linked list for rows.
Definition: CoinModel.hpp:972
double rowLower(int whichRow) const
Return number of elements.
Definition: CoinModel.hpp:511
CoinModelLink firstInRow(int whichRow) const
Returns first element in given row - index is -1 if none.
For int,int hashing.
double * columnUpperArray() const
Return columnUpper array.
Definition: CoinModel.hpp:681
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:320
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:315
void setMoreInfo(void *info)
Set pointer to more information.
Definition: CoinModel.hpp:709
int numberElements_
Current number of elements.
Definition: CoinModel.hpp:920
void freeStringMemory(CoinYacc &info)
Frees value memory.
int numberColumns_
Current number of columns.
Definition: CoinModel.hpp:89
void operator()(int i, int j, double value)
Sets value for row i and column j.
Definition: CoinModel.hpp:173
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...
for linked lists
const char * columnIsIntegerAsString(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:626
double getElement(int i, int j) const
Returns value for row i and column j.
int maximumElements_
Maximum number of elements.
Definition: CoinModel.hpp:922
int maximumRows_
Maximum number of rows.
Definition: CoinModel.hpp:916
int createPackedMatrix(CoinPackedMatrix &matrix, const double *associated)
Creates a packed matrix - return number of errors.
int packRows()
Packs down all rows i.e.
const char * rowName(int whichRow) const
Gets name (if row does not exist then NULL)
Definition: CoinModel.hpp:519
CoinModelLink next(CoinModelLink &current) const
Returns next element in current row or column - index is -1 if none.
const char * rowLowerAsString(int whichRow) const
Return number of elements.
Definition: CoinModel.hpp:590
int numberRows() const
Return number of rows.
Definition: CoinModel.hpp:35
void deleteColumn(int whichColumn)
Deletes all entries in column and bounds and objective.
const char * getColumnUpperAsString(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
void deleteRow(int whichRow)
Deletes all entries in row and bounds.
CoinBigIndex numberElements() const
Return number of elements.
Definition: CoinModel.hpp:434
int position(int i, int j) const
Returns position in elements for row i column j.
int pack()
Packs down all rows and columns.
void replaceQuadraticRow(int rowNumber, const double *linear, const CoinPackedMatrix *quadraticPart)
Replaces a quadratic row.
int countPlusMinusOne(CoinBigIndex *startPositive, CoinBigIndex *startNegative, const double *associated)
Fills in startPositive and startNegative with counts for +-1 matrix.
void setProblemName(const char *name)
Set problem name.
int row(const char *rowName) const
Row index from row name (-1 if no names or no match)