coin-Bcp
CoinModel.hpp
Go to the documentation of this file.
1 /* $Id: CoinModel.hpp 2083 2019-01-06 19:38:09Z unxusr $ */
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 "CoinMessageHandler.hpp"
11 #include "CoinPackedMatrix.hpp"
12 #include "CoinFinite.hpp"
14 
15 public:
18  CoinBaseModel();
20 
22  CoinBaseModel(const CoinBaseModel &rhs);
23 
26 
28  virtual CoinBaseModel *clone() const = 0;
29 
31  virtual ~CoinBaseModel();
33 
36  inline int numberRows() const
38  {
39  return numberRows_;
40  }
42  inline int numberColumns() const
43  {
44  return numberColumns_;
45  }
47  virtual CoinBigIndex numberElements() const = 0;
51  inline double objectiveOffset() const
52  {
53  return objectiveOffset_;
54  }
56  inline void setObjectiveOffset(double value)
57  {
58  objectiveOffset_ = value;
59  }
61  inline double optimizationDirection() const
62  {
64  }
66  inline void setOptimizationDirection(double value)
67  {
68  optimizationDirection_ = value;
69  }
71  inline int logLevel() const
72  {
73  return logLevel_;
74  }
76  void setLogLevel(int value);
78  inline const char *getProblemName() const
79  {
80  return problemName_.c_str();
81  }
83  void setProblemName(const char *name);
85  void setProblemName(const std::string &name);
87  inline const std::string &getRowBlock() const
88  {
89  return rowBlockName_;
90  }
92  inline void setRowBlock(const std::string &name)
93  {
94  rowBlockName_ = name;
95  }
97  inline const std::string &getColumnBlock() const
98  {
99  return columnBlockName_;
100  }
102  inline void setColumnBlock(const std::string &name)
103  {
104  columnBlockName_ = name;
105  }
107  void setMessageHandler(CoinMessageHandler *handler);
109 
110 protected:
113  int numberRows_;
122  std::string problemName_;
124  std::string rowBlockName_;
126  std::string columnBlockName_;
131 
142 };
144 
181 class CoinModel : public CoinBaseModel {
182 
183 public:
187  void addRow(int numberInRow, const int *columns,
188  const double *elements, double rowLower = -COIN_DBL_MAX,
189  double rowUpper = COIN_DBL_MAX, const char *name = NULL);
191  void addColumn(int numberInColumn, const int *rows,
192  const double *elements,
193  double columnLower = 0.0,
194  double columnUpper = COIN_DBL_MAX, double objectiveValue = 0.0,
195  const char *name = NULL, bool isInteger = false);
197  inline void addCol(int numberInColumn, const int *rows,
198  const double *elements,
199  double columnLower = 0.0,
200  double columnUpper = COIN_DBL_MAX, double objectiveValue = 0.0,
201  const char *name = NULL, bool isInteger = false)
202  {
203  addColumn(numberInColumn, rows, elements, columnLower, columnUpper, objectiveValue,
204  name, isInteger);
205  }
207  inline void operator()(int i, int j, double value)
208  {
209  setElement(i, j, value);
210  }
212  void setElement(int i, int j, double value);
218  int getRow(int whichRow, int *column, double *element);
224  int getColumn(int whichColumn, int *column, double *element);
226  void setQuadraticElement(int i, int j, double value);
228  inline void operator()(int i, int j, const char *value)
229  {
230  setElement(i, j, value);
231  }
233  void setElement(int i, int j, const char *value);
235  int associateElement(const char *stringValue, double value);
239  void setRowLower(int whichRow, double rowLower);
243  void setRowUpper(int whichRow, double rowUpper);
247  void setRowBounds(int whichRow, double rowLower, double rowUpper);
251  void setRowName(int whichRow, const char *rowName);
255  void setColumnLower(int whichColumn, double columnLower);
259  void setColumnUpper(int whichColumn, double columnUpper);
263  void setColumnBounds(int whichColumn, double columnLower, double columnUpper);
267  void setColumnObjective(int whichColumn, double columnObjective);
271  void setColumnName(int whichColumn, const char *columnName);
275  void setColumnIsInteger(int whichColumn, bool columnIsInteger);
279  inline void setObjective(int whichColumn, double columnObjective)
280  {
281  setColumnObjective(whichColumn, columnObjective);
282  }
286  inline void setIsInteger(int whichColumn, bool columnIsInteger)
287  {
288  setColumnIsInteger(whichColumn, columnIsInteger);
289  }
293  inline void setInteger(int whichColumn)
294  {
295  setColumnIsInteger(whichColumn, true);
296  }
300  inline void setContinuous(int whichColumn)
301  {
302  setColumnIsInteger(whichColumn, false);
303  }
307  inline void setColLower(int whichColumn, double columnLower)
308  {
309  setColumnLower(whichColumn, columnLower);
310  }
314  inline void setColUpper(int whichColumn, double columnUpper)
315  {
316  setColumnUpper(whichColumn, columnUpper);
317  }
321  inline void setColBounds(int whichColumn, double columnLower, double columnUpper)
322  {
323  setColumnBounds(whichColumn, columnLower, columnUpper);
324  }
328  inline void setColObjective(int whichColumn, double columnObjective)
329  {
330  setColumnObjective(whichColumn, columnObjective);
331  }
335  inline void setColName(int whichColumn, const char *columnName)
336  {
337  setColumnName(whichColumn, columnName);
338  }
342  inline void setColIsInteger(int whichColumn, bool columnIsInteger)
343  {
344  setColumnIsInteger(whichColumn, columnIsInteger);
345  }
349  void setRowLower(int whichRow, const char *rowLower);
353  void setRowUpper(int whichRow, const char *rowUpper);
357  void setColumnLower(int whichColumn, const char *columnLower);
361  void setColumnUpper(int whichColumn, const char *columnUpper);
365  void setColumnObjective(int whichColumn, const char *columnObjective);
369  void setColumnIsInteger(int whichColumn, const char *columnIsInteger);
373  inline void setObjective(int whichColumn, const char *columnObjective)
374  {
375  setColumnObjective(whichColumn, columnObjective);
376  }
380  inline void setIsInteger(int whichColumn, const char *columnIsInteger)
381  {
382  setColumnIsInteger(whichColumn, columnIsInteger);
383  }
386  void deleteRow(int whichRow);
389  void deleteColumn(int whichColumn);
392  inline void deleteCol(int whichColumn)
393  {
394  deleteColumn(whichColumn);
395  }
402  int packRows();
405  int packColumns();
408  inline int packCols()
409  {
410  return packColumns();
411  }
416  int pack();
417 
420  void setObjective(int numberColumns, const double *objective);
423  void setColumnLower(int numberColumns, const double *columnLower);
426  inline void setColLower(int numberColumns, const double *columnLower)
427  {
428  setColumnLower(numberColumns, columnLower);
429  }
432  void setColumnUpper(int numberColumns, const double *columnUpper);
435  inline void setColUpper(int numberColumns, const double *columnUpper)
436  {
437  setColumnUpper(numberColumns, columnUpper);
438  }
441  void setRowLower(int numberRows, const double *rowLower);
444  void setRowUpper(int numberRows, const double *rowUpper);
445 
471  int writeMps(const char *filename, int compression = 0,
472  int formatType = 0, int numberAcross = 2, bool keepStrings = false);
473 
478  int differentModel(CoinModel &other, bool ignoreNames);
480 
483  void passInMatrix(const CoinPackedMatrix &matrix);
487  int convertMatrix();
489  inline const CoinPackedMatrix *packedMatrix() const
490  {
491  return packedMatrix_;
492  }
494  inline const int *originalRows() const
495  {
496  return rowType_;
497  }
499  inline const int *originalColumns() const
500  {
501  return columnType_;
502  }
504 
507  inline CoinBigIndex numberElements() const
509  {
510  return numberElements_;
511  }
513  inline const CoinModelTriple *elements() const
514  {
515  return elements_;
516  }
518  inline double operator()(int i, int j) const
519  {
520  return getElement(i, j);
521  }
523  double getElement(int i, int j) const;
525  inline double operator()(const char *rowName, const char *columnName) const
526  {
527  return getElement(rowName, columnName);
528  }
530  double getElement(const char *rowName, const char *columnName) const;
532  double getQuadraticElement(int i, int j) const;
537  const char *getElementAsString(int i, int j) const;
541  double *pointer(int i, int j) const;
545  CoinBigIndex position(int i, int j) const;
546 
550  CoinModelLink firstInRow(int whichRow) const;
554  CoinModelLink lastInRow(int whichRow) const;
558  CoinModelLink firstInColumn(int whichColumn) const;
562  CoinModelLink lastInColumn(int whichColumn) const;
567  CoinModelLink next(CoinModelLink &current) const;
573  CoinModelLink previous(CoinModelLink &current) const;
578  CoinModelLink firstInQuadraticColumn(int whichColumn) const;
582  CoinModelLink lastInQuadraticColumn(int whichColumn) const;
585  double getRowLower(int whichRow) const;
588  double getRowUpper(int whichRow) const;
591  const char *getRowName(int whichRow) const;
592  inline double rowLower(int whichRow) const
593  {
594  return getRowLower(whichRow);
595  }
598  inline double rowUpper(int whichRow) const
599  {
600  return getRowUpper(whichRow);
601  }
604  inline const char *rowName(int whichRow) const
605  {
606  return getRowName(whichRow);
607  }
610  double getColumnLower(int whichColumn) const;
613  double getColumnUpper(int whichColumn) const;
616  double getColumnObjective(int whichColumn) const;
619  const char *getColumnName(int whichColumn) const;
622  bool getColumnIsInteger(int whichColumn) const;
625  inline double columnLower(int whichColumn) const
626  {
627  return getColumnLower(whichColumn);
628  }
631  inline double columnUpper(int whichColumn) const
632  {
633  return getColumnUpper(whichColumn);
634  }
637  inline double columnObjective(int whichColumn) const
638  {
639  return getColumnObjective(whichColumn);
640  }
643  inline double objective(int whichColumn) const
644  {
645  return getColumnObjective(whichColumn);
646  }
649  inline const char *columnName(int whichColumn) const
650  {
651  return getColumnName(whichColumn);
652  }
655  inline bool columnIsInteger(int whichColumn) const
656  {
657  return getColumnIsInteger(whichColumn);
658  }
661  inline bool isInteger(int whichColumn) const
662  {
663  return getColumnIsInteger(whichColumn);
664  }
667  inline double getColLower(int whichColumn) const
668  {
669  return getColumnLower(whichColumn);
670  }
673  inline double getColUpper(int whichColumn) const
674  {
675  return getColumnUpper(whichColumn);
676  }
679  inline double getColObjective(int whichColumn) const
680  {
681  return getColumnObjective(whichColumn);
682  }
685  inline const char *getColName(int whichColumn) const
686  {
687  return getColumnName(whichColumn);
688  }
691  inline bool getColIsInteger(int whichColumn) const
692  {
693  return getColumnIsInteger(whichColumn);
694  }
697  const char *getRowLowerAsString(int whichRow) const;
700  const char *getRowUpperAsString(int whichRow) const;
701  inline const char *rowLowerAsString(int whichRow) const
702  {
703  return getRowLowerAsString(whichRow);
704  }
707  inline const char *rowUpperAsString(int whichRow) const
708  {
709  return getRowUpperAsString(whichRow);
710  }
713  const char *getColumnLowerAsString(int whichColumn) const;
716  const char *getColumnUpperAsString(int whichColumn) const;
719  const char *getColumnObjectiveAsString(int whichColumn) const;
722  const char *getColumnIsIntegerAsString(int whichColumn) const;
725  inline const char *columnLowerAsString(int whichColumn) const
726  {
727  return getColumnLowerAsString(whichColumn);
728  }
731  inline const char *columnUpperAsString(int whichColumn) const
732  {
733  return getColumnUpperAsString(whichColumn);
734  }
737  inline const char *columnObjectiveAsString(int whichColumn) const
738  {
739  return getColumnObjectiveAsString(whichColumn);
740  }
743  inline const char *objectiveAsString(int whichColumn) const
744  {
745  return getColumnObjectiveAsString(whichColumn);
746  }
749  inline const char *columnIsIntegerAsString(int whichColumn) const
750  {
751  return getColumnIsIntegerAsString(whichColumn);
752  }
755  inline const char *isIntegerAsString(int whichColumn) const
756  {
757  return getColumnIsIntegerAsString(whichColumn);
758  }
760  int row(const char *rowName) const;
762  int column(const char *columnName) const;
764  inline int type() const
765  {
766  return type_;
767  }
769  inline double unsetValue() const
770  {
771  return -1.23456787654321e-97;
772  }
775  const double *associated);
781  int countPlusMinusOne(CoinBigIndex *startPositive, CoinBigIndex *startNegative,
782  const double *associated);
785  void createPlusMinusOne(CoinBigIndex *startPositive, CoinBigIndex *startNegative,
786  int *indices,
787  const double *associated);
789  int createArrays(double *&rowLower, double *&rowUpper,
790  double *&columnLower, double *&columnUpper,
791  double *&objective, int *&integerType,
792  double *&associated);
794  inline bool stringsExist() const
795  {
796  return string_.numberItems() != 0;
797  }
799  inline const CoinModelHash *stringArray() const
800  {
801  return &string_;
802  }
804  inline double *associatedArray() const
805  {
806  return associated_;
807  }
809  inline double *rowLowerArray() const
810  {
811  return rowLower_;
812  }
814  inline double *rowUpperArray() const
815  {
816  return rowUpper_;
817  }
819  inline double *columnLowerArray() const
820  {
821  return columnLower_;
822  }
824  inline double *columnUpperArray() const
825  {
826  return columnUpper_;
827  }
829  inline double *objectiveArray() const
830  {
831  return objective_;
832  }
834  inline int *integerTypeArray() const
835  {
836  return integerType_;
837  }
839  inline const CoinModelHash *rowNames() const
840  {
841  return &rowName_;
842  }
844  inline const CoinModelHash *columnNames() const
845  {
846  return &columnName_;
847  }
849  inline void zapRowNames()
850  {
852  }
854  inline void zapColumnNames()
855  {
857  }
859  inline const int *cutMarker() const
860  {
861  return cut_;
862  }
864  inline double optimizationDirection() const
865  {
866  return optimizationDirection_;
867  }
869  inline void setOptimizationDirection(double value)
870  {
871  optimizationDirection_ = value;
872  }
874  inline void *moreInfo() const
875  {
876  return moreInfo_;
877  }
879  inline void setMoreInfo(void *info)
880  {
881  moreInfo_ = info;
882  }
891  int whatIsSet() const;
893 
911  void loadBlock(const CoinPackedMatrix &matrix,
912  const double *collb, const double *colub,
913  const double *obj,
914  const double *rowlb, const double *rowub);
931  void loadBlock(const CoinPackedMatrix &matrix,
932  const double *collb, const double *colub,
933  const double *obj,
934  const char *rowsen, const double *rowrhs,
935  const double *rowrng);
936 
949  void loadBlock(const int numcols, const int numrows,
950  const CoinBigIndex *start, const int *index,
951  const double *value,
952  const double *collb, const double *colub,
953  const double *obj,
954  const double *rowlb, const double *rowub);
955 
968  void loadBlock(const int numcols, const int numrows,
969  const CoinBigIndex *start, const int *index,
970  const double *value,
971  const double *collb, const double *colub,
972  const double *obj,
973  const char *rowsen, const double *rowrhs,
974  const double *rowrng);
975 
977 
981  CoinModel();
983  CoinModel(int firstRows, int firstColumns, CoinBigIndex firstElements, bool noNames = false);
986  CoinModel(const char *fileName, int allowStrings = 0);
990  CoinModel(int nonLinear, const char *fileName, const void *info);
993  const CoinPackedMatrix *matrix,
994  const double *rowLower, const double *rowUpper,
995  const double *columnLower, const double *columnUpper,
996  const double *objective);
998  virtual CoinBaseModel *clone() const;
999 
1001  virtual ~CoinModel();
1003 
1007  CoinModel(const CoinModel &);
1009  CoinModel &operator=(const CoinModel &);
1011 
1014  void validateLinks() const;
1017 private:
1019  void resize(int maximumRows, int maximumColumns, CoinBigIndex maximumElements);
1021  void fillRows(int which, bool forceCreation, bool fromAddRow = false);
1023  void fillColumns(int which, bool forceCreation, bool fromAddColumn = false);
1026  void fillList(int which, CoinModelLinkedList &list, int type) const;
1030  void createList(int type) const;
1032  int addString(const char *string);
1036  double getDoubleFromString(CoinYacc &info, const char *string);
1038  void freeStringMemory(CoinYacc &info);
1039 
1040 public:
1042  int computeAssociated(double *associated);
1048  CoinPackedMatrix *quadraticRow(int rowNumber, double *linear,
1049  int &numberBad) const;
1051  void replaceQuadraticRow(int rowNumber, const double *linear, const CoinPackedMatrix *quadraticPart);
1056  CoinModel *reorder(const char *mark) const;
1067  int expandKnapsack(int knapsackRow, int &numberOutput, double *buildObj, CoinBigIndex *buildStart,
1068  int *buildRow, double *buildElement, int reConstruct = -1) const;
1070  void setCutMarker(int size, const int *marker);
1072  void setPriorities(int size, const int *priorities);
1074  inline const int *priorities() const
1075  {
1076  return priority_;
1077  }
1079  void setOriginalIndices(const int *row, const int *column);
1080 
1081 private:
1085  void gdb(int nonLinear, const char *fileName, const void *info);
1087  int decodeBit(char *phrase, char *&nextPhrase, double &coefficient, bool ifFirst) const;
1089  void badType() const;
1092  int maximumRows_;
1105  double *rowLower_;
1107  double *rowUpper_;
1117  int *rowType_;
1119  double *objective_;
1121  double *columnLower_;
1123  double *columnUpper_;
1159  double *sortElements_;
1169  double *associated_;
1177  int *typeSOS_;
1181  double *referenceSOS_;
1185  int *cut_;
1187  void *moreInfo_;
1195  mutable int type_;
1197  bool noNames_;
1204  mutable int links_;
1206 };
1208 double getFunctionValueFromString(const char *string, const char *x, double xValue);
1210 double getDoubleFromString(CoinYacc &info, const char *string, const char *x, double xValue);
1211 #endif
1212 
1213 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
1214 */
int CoinBigIndex
double getColLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:667
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:743
int * rowType_
Row types.
Definition: CoinModel.hpp:1117
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:181
double objective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:643
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:874
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:1157
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:279
void setMessageHandler(CoinMessageHandler *handler)
Pass in message handler.
int * startSOS_
SOS starts.
Definition: CoinModel.hpp:1173
const char * getElementAsString(int i, int j) const
Returns value for row i and column j as string.
Base class for message handling.
const int * priorities() const
priorities (given for all columns (-1 if not integer)
Definition: CoinModel.hpp:1074
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:764
void * moreInfo_
Pointer to more information.
Definition: CoinModel.hpp:1187
double getQuadraticElement(int i, int j) const
Returns quadratic value for columns i and j.
double unsetValue() const
returns unset value
Definition: CoinModel.hpp:769
int * priority_
priorities (given for all columns (-1 if not integer)
Definition: CoinModel.hpp:1183
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:1109
int * integerType_
Integer information.
Definition: CoinModel.hpp:1127
CoinModelLinkedList quadraticColumnList_
Linked list for quadratic columns.
Definition: CoinModel.hpp:1165
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:1145
int * integerTypeArray() const
Return integerType array.
Definition: CoinModel.hpp:834
const int * originalRows() const
Return pointers to original rows (for decomposition)
Definition: CoinModel.hpp:494
std::string rowBlockName_
Rowblock name.
Definition: CoinModel.hpp:124
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:61
double * columnLowerArray() const
Return columnLower array.
Definition: CoinModel.hpp:819
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:328
const CoinModelHash * columnNames() const
Return column names array.
Definition: CoinModel.hpp:844
double * columnLower_
Column Lower.
Definition: CoinModel.hpp:1121
int * columnType_
Column types.
Definition: CoinModel.hpp:1139
std::string problemName_
Problem name.
Definition: CoinModel.hpp:122
int addString(const char *string)
Adds one string, returns index.
const int * originalColumns() const
Return pointers to original columns (for decomposition)
Definition: CoinModel.hpp:499
double * rowLower_
Row lower.
Definition: CoinModel.hpp:1105
const CoinModelHash * stringArray() const
Return string array.
Definition: CoinModel.hpp:799
CoinModelLinkedList columnList_
Linked list for columns.
Definition: CoinModel.hpp:1151
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:1095
const char * columnLowerAsString(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:725
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:673
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:300
CoinModelHash string_
Strings.
Definition: CoinModel.hpp:1129
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:598
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:66
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:1171
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.
void operator()(int i, int j, const char *value)
Sets value for row i and column j as string.
Definition: CoinModel.hpp:228
const char * getColumnObjectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
CoinModelTriple * elements_
Actual elements.
Definition: CoinModel.hpp:1143
bool columnIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:655
const char * getColumnLowerAsString(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
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.
CoinMessageHandler * handler_
Message handler (Passed in)
Definition: CoinModel.hpp:128
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:1119
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:685
double * rowUpper_
Row upper.
Definition: CoinModel.hpp:1107
CoinMessages messages_
Messages.
Definition: CoinModel.hpp:130
double * referenceSOS_
SOS reference.
Definition: CoinModel.hpp:1181
void setElement(int i, int j, double value)
Sets value for row i and column j.
CoinModelHash columnName_
Column names.
Definition: CoinModel.hpp:1125
const char * rowUpperAsString(int whichRow) const
Gets rowUpper (if row does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:707
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...
void deleteThisElement(int row, int column, CoinBigIndex position)
Takes element out of matrix when position known.
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:321
virtual ~CoinBaseModel()
Destructor.
int numberColumns() const
Return number of columns.
Definition: CoinModel.hpp:42
void setOptimizationDirection(double value)
Set direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:869
int * cut_
Nonzero if row is cut - done in one go e.g. from ampl.
Definition: CoinModel.hpp:1185
int sizeAssociated_
Size of associated values.
Definition: CoinModel.hpp:1167
void setRowBlock(const std::string &name)
Set row block name.
Definition: CoinModel.hpp:92
CoinModelHash2 hashElements_
Hash for elements.
Definition: CoinModel.hpp:1147
double * rowLowerArray() const
Return rowLower array.
Definition: CoinModel.hpp:809
int logLevel_
Print level.
Definition: CoinModel.hpp:140
void setColLower(int numberColumns, const double *columnLower)
Sets columnLower array.
Definition: CoinModel.hpp:426
int sortSize_
Size of sort arrays.
Definition: CoinModel.hpp:1161
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:314
const char * columnName(int whichColumn) const
Gets name (if column does not exist then NULL)
Definition: CoinModel.hpp:649
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:197
const char * columnUpperAsString(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:731
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:87
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...
CoinBigIndex maximumElements_
Maximum number of elements.
Definition: CoinModel.hpp:1099
bool noNames_
True if no names EVER being used (for users who know what they are doing)
Definition: CoinModel.hpp:1197
double * objectiveArray() const
Return objective array.
Definition: CoinModel.hpp:829
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:307
const char * isIntegerAsString(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:755
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:849
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:814
virtual CoinBigIndex numberElements() const =0
Return number of elements.
const CoinModelHash * rowNames() const
Return row names array.
Definition: CoinModel.hpp:839
int logLevel() const
Get print level 0 - off, 1 - errors, 2 - more.
Definition: CoinModel.hpp:71
CoinModelLink lastInQuadraticColumn(int whichColumn) const
Returns last element in given quadratic column - index is -1 if none.
This is a first attempt at a message handler.
const CoinPackedMatrix * packedMatrix() const
Return a pointer to CoinPackedMatrix (or NULL)
Definition: CoinModel.hpp:489
CoinBigIndex numberElements_
Current number of elements.
Definition: CoinModel.hpp:1097
int packCols()
Packs down all columns i.e.
Definition: CoinModel.hpp:408
double columnLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:625
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:794
int numberRows_
Current number of rows.
Definition: CoinModel.hpp:114
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:126
double * associatedArray() const
Returns associated array.
Definition: CoinModel.hpp:804
const char * columnObjectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:737
bool getColIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:691
int * memberSOS_
SOS members.
Definition: CoinModel.hpp:1175
void resize(int maximumRows, int maximumColumns, CoinBigIndex maximumElements)
Resize.
int column(const char *columnName) const
Column index from column name (-1 if no names or no match)
const double COIN_DBL_MAX
Definition: CoinFinite.hpp:18
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:859
const char * getProblemName() const
Return the problem name.
Definition: CoinModel.hpp:78
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:51
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:637
int * typeSOS_
SOS type.
Definition: CoinModel.hpp:1177
double * sortElements_
Array for sorting elements.
Definition: CoinModel.hpp:1159
CoinBigIndex * start_
If simple then start of each row/column.
Definition: CoinModel.hpp:1141
void deleteCol(int whichColumn)
Deletes all entries in column and bounds.
Definition: CoinModel.hpp:392
CoinModelLinkedList quadraticRowList_
Linked list for quadratic rows.
Definition: CoinModel.hpp:1163
const char * getRowUpperAsString(int whichRow) const
Gets rowUpper (if row does not exist then +COIN_DBL_MAX)
Class to hold and manipulate an array of massaged messages.
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:286
CoinBigIndex position(int i, int j) const
Returns position in elements for row i column j.
virtual ~CoinModel()
Destructor.
double operator()(const char *rowName, const char *columnName) const
Returns value for row rowName and column columnName.
Definition: CoinModel.hpp:525
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:631
double * associated_
Associated values.
Definition: CoinModel.hpp:1169
CoinBigIndex numberQuadraticElements_
Current number of quadratic elements.
Definition: CoinModel.hpp:1101
double objectiveOffset_
Objective offset to be passed on.
Definition: CoinModel.hpp:120
CoinModelHash2 hashQuadraticElements_
Hash for quadratic elements.
Definition: CoinModel.hpp:1155
double optimizationDirection_
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:118
int type_
Type of build - -1 unset, 0 for row, 1 for column, 2 linked.
Definition: CoinModel.hpp:1195
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:293
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:97
bool isInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:661
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:102
void zapColumnNames()
Reset column names.
Definition: CoinModel.hpp:854
double getColObjective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:679
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:864
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:1153
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:513
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:335
double * columnUpper_
Column Upper.
Definition: CoinModel.hpp:1123
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:435
int * prioritySOS_
SOS priority.
Definition: CoinModel.hpp:1179
void setObjectiveOffset(double value)
Set objective offset.
Definition: CoinModel.hpp:56
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:342
int links_
Links present (could be tested by sizes of objects) 0 - none, 1 - row links, 2 - column links...
Definition: CoinModel.hpp:1204
CoinModelLinkedList rowList_
Linked list for rows.
Definition: CoinModel.hpp:1149
double rowLower(int whichRow) const
Return number of elements.
Definition: CoinModel.hpp:592
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:824
CoinBigIndex deleteElement(int row, int column)
Takes element out of matrix - returning position (<0 if not there);.
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:380
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:373
void setMoreInfo(void *info)
Set pointer to more information.
Definition: CoinModel.hpp:879
void freeStringMemory(CoinYacc &info)
Frees value memory.
double operator()(int i, int j) const
Returns value for row i and column j.
Definition: CoinModel.hpp:518
int numberColumns_
Current number of columns.
Definition: CoinModel.hpp:116
void operator()(int i, int j, double value)
Sets value for row i and column j.
Definition: CoinModel.hpp:207
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:749
double getElement(int i, int j) const
Returns value for row i and column j.
int maximumRows_
Maximum number of rows.
Definition: CoinModel.hpp:1093
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:604
CoinBigIndex maximumQuadraticElements_
Maximum number of quadratic elements.
Definition: CoinModel.hpp:1103
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:701
int numberRows() const
Return number of rows.
Definition: CoinModel.hpp:37
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:508
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)