CoinModel.hpp
Go to the documentation of this file.
1 /* $Id: CoinModel.hpp 1691 2014-03-19 12:43:56Z forrest $ */
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:
16 
17 
20  CoinBaseModel ();
22 
24  CoinBaseModel ( const CoinBaseModel &rhs);
25 
27  CoinBaseModel & operator=( const CoinBaseModel& rhs);
28 
30  virtual CoinBaseModel * clone() const=0;
31 
33  virtual ~CoinBaseModel () ;
35 
38  inline int numberRows() const
40  { return numberRows_;}
42  inline int numberColumns() const
43  { return numberColumns_;}
45  virtual CoinBigIndex numberElements() const = 0;
49  inline double objectiveOffset() const
50  { return objectiveOffset_;}
52  inline void setObjectiveOffset(double value)
53  { objectiveOffset_=value;}
55  inline double optimizationDirection() const {
57  }
59  inline void setOptimizationDirection(double value)
60  { optimizationDirection_=value;}
62  inline int logLevel() const
63  { return logLevel_;}
65  void setLogLevel(int value);
67  inline const char * getProblemName() const
68  { return problemName_.c_str();}
70  void setProblemName(const char *name) ;
72  void setProblemName(const std::string &name) ;
74  inline const std::string & getRowBlock() const
75  { return rowBlockName_;}
77  inline void setRowBlock(const std::string &name)
78  { rowBlockName_ = name;}
80  inline const std::string & getColumnBlock() const
81  { return columnBlockName_;}
83  inline void setColumnBlock(const std::string &name)
84  { columnBlockName_ = name;}
86  void setMessageHandler(CoinMessageHandler * handler);
88 
89 protected:
92  int numberRows_;
101  std::string problemName_;
103  std::string rowBlockName_;
105  std::string columnBlockName_;
110 
121 
123 };
124 
161 class CoinModel : public CoinBaseModel {
162 
163 public:
167  void addRow(int numberInRow, const int * columns,
168  const double * elements, double rowLower=-COIN_DBL_MAX,
169  double rowUpper=COIN_DBL_MAX, const char * name=NULL);
171  void addColumn(int numberInColumn, const int * rows,
172  const double * elements,
173  double columnLower=0.0,
174  double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
175  const char * name=NULL, bool isInteger=false);
177  inline void addCol(int numberInColumn, const int * rows,
178  const double * elements,
179  double columnLower=0.0,
180  double columnUpper=COIN_DBL_MAX, double objectiveValue=0.0,
181  const char * name=NULL, bool isInteger=false)
182  { addColumn(numberInColumn, rows, elements, columnLower, columnUpper, objectiveValue,
183  name,isInteger);}
185  inline void operator() (int i,int j,double value)
186  { setElement(i,j,value);}
188  void setElement(int i,int j,double value) ;
194  int getRow(int whichRow, int * column, double * element);
200  int getColumn(int whichColumn, int * column, double * element);
202  void setQuadraticElement(int i,int j,double value) ;
204  inline void operator() (int i,int j,const char * value)
205  { setElement(i,j,value);}
207  void setElement(int i,int j,const char * value) ;
209  int associateElement(const char * stringValue, double value);
213  void setRowLower(int whichRow,double rowLower);
217  void setRowUpper(int whichRow,double rowUpper);
221  void setRowBounds(int whichRow,double rowLower,double rowUpper);
225  void setRowName(int whichRow,const char * rowName);
229  void setColumnLower(int whichColumn,double columnLower);
233  void setColumnUpper(int whichColumn,double columnUpper);
237  void setColumnBounds(int whichColumn,double columnLower,double columnUpper);
241  void setColumnObjective(int whichColumn,double columnObjective);
245  void setColumnName(int whichColumn,const char * columnName);
249  void setColumnIsInteger(int whichColumn,bool columnIsInteger);
253  inline void setObjective(int whichColumn,double columnObjective)
254  { setColumnObjective( whichColumn, columnObjective);}
258  inline void setIsInteger(int whichColumn,bool columnIsInteger)
259  { setColumnIsInteger( whichColumn, columnIsInteger);}
263  inline void setInteger(int whichColumn)
264  { setColumnIsInteger( whichColumn, true);}
268  inline void setContinuous(int whichColumn)
269  { setColumnIsInteger( whichColumn, false);}
273  inline void setColLower(int whichColumn,double columnLower)
274  { setColumnLower( whichColumn, columnLower);}
278  inline void setColUpper(int whichColumn,double columnUpper)
279  { setColumnUpper( whichColumn, columnUpper);}
283  inline void setColBounds(int whichColumn,double columnLower,double columnUpper)
284  { setColumnBounds( whichColumn, columnLower, columnUpper);}
288  inline void setColObjective(int whichColumn,double columnObjective)
289  { setColumnObjective( whichColumn, columnObjective);}
293  inline void setColName(int whichColumn,const char * columnName)
294  { setColumnName( whichColumn, columnName);}
298  inline void setColIsInteger(int whichColumn,bool columnIsInteger)
299  { setColumnIsInteger( whichColumn, columnIsInteger);}
303  void setRowLower(int whichRow,const char * rowLower);
307  void setRowUpper(int whichRow,const char * rowUpper);
311  void setColumnLower(int whichColumn,const char * columnLower);
315  void setColumnUpper(int whichColumn,const char * columnUpper);
319  void setColumnObjective(int whichColumn,const char * columnObjective);
323  void setColumnIsInteger(int whichColumn,const char * columnIsInteger);
327  inline void setObjective(int whichColumn,const char * columnObjective)
328  { setColumnObjective( whichColumn, columnObjective);}
332  inline void setIsInteger(int whichColumn,const char * columnIsInteger)
333  { setColumnIsInteger( whichColumn, columnIsInteger);}
336  void deleteRow(int whichRow);
339  void deleteColumn(int whichColumn);
342  inline void deleteCol(int whichColumn)
343  { deleteColumn(whichColumn);}
345  int deleteElement(int row, int column);
347  void deleteThisElement(int row, int column,int position);
350  int packRows();
353  int packColumns();
356  inline int packCols()
357  { return packColumns();}
362  int pack();
363 
366  void setObjective(int numberColumns,const double * objective) ;
369  void setColumnLower(int numberColumns,const double * columnLower);
372  inline void setColLower(int numberColumns,const double * columnLower)
373  { setColumnLower( numberColumns, columnLower);}
376  void setColumnUpper(int numberColumns,const double * columnUpper);
379  inline void setColUpper(int numberColumns,const double * columnUpper)
380  { setColumnUpper( numberColumns, columnUpper);}
383  void setRowLower(int numberRows,const double * rowLower);
386  void setRowUpper(int numberRows,const double * rowUpper);
387 
413  int writeMps(const char *filename, int compression = 0,
414  int formatType = 0, int numberAcross = 2, bool keepStrings=false) ;
415 
420  int differentModel(CoinModel & other, bool ignoreNames);
422 
423 
426  void passInMatrix(const CoinPackedMatrix & matrix);
430  int convertMatrix();
432  inline const CoinPackedMatrix * packedMatrix() const
433  { return packedMatrix_;}
435  inline const int * originalRows() const
436  { return rowType_;}
438  inline const int * originalColumns() const
439  { return columnType_;}
441 
442 
445  inline CoinBigIndex numberElements() const
447  { return numberElements_;}
449  inline const CoinModelTriple * elements() const
450  { return elements_;}
452  inline double operator() (int i,int j) const
453  { return getElement(i,j);}
455  double getElement(int i,int j) const;
457  inline double operator() (const char * rowName,const char * columnName) const
458  { return getElement(rowName,columnName);}
460  double getElement(const char * rowName,const char * columnName) const;
462  double getQuadraticElement(int i,int j) const;
467  const char * getElementAsString(int i,int j) const;
471  double * pointer (int i,int j) const;
475  int position (int i,int j) const;
476 
477 
481  CoinModelLink firstInRow(int whichRow) const ;
485  CoinModelLink lastInRow(int whichRow) const ;
489  CoinModelLink firstInColumn(int whichColumn) const ;
493  CoinModelLink lastInColumn(int whichColumn) const ;
498  CoinModelLink next(CoinModelLink & current) const ;
504  CoinModelLink previous(CoinModelLink & current) const ;
509  CoinModelLink firstInQuadraticColumn(int whichColumn) const ;
513  CoinModelLink lastInQuadraticColumn(int whichColumn) const ;
516  double getRowLower(int whichRow) const ;
519  double getRowUpper(int whichRow) const ;
522  const char * getRowName(int whichRow) const ;
523  inline double rowLower(int whichRow) const
524  { return getRowLower(whichRow);}
527  inline double rowUpper(int whichRow) const
528  { return getRowUpper(whichRow) ;}
531  inline const char * rowName(int whichRow) const
532  { return getRowName(whichRow);}
535  double getColumnLower(int whichColumn) const ;
538  double getColumnUpper(int whichColumn) const ;
541  double getColumnObjective(int whichColumn) const ;
544  const char * getColumnName(int whichColumn) const ;
547  bool getColumnIsInteger(int whichColumn) const ;
550  inline double columnLower(int whichColumn) const
551  { return getColumnLower(whichColumn);}
554  inline double columnUpper(int whichColumn) const
555  { return getColumnUpper(whichColumn) ;}
558  inline double columnObjective(int whichColumn) const
559  { return getColumnObjective(whichColumn);}
562  inline double objective(int whichColumn) const
563  { return getColumnObjective(whichColumn);}
566  inline const char * columnName(int whichColumn) const
567  { return getColumnName(whichColumn);}
570  inline bool columnIsInteger(int whichColumn) const
571  { return getColumnIsInteger(whichColumn);}
574  inline bool isInteger(int whichColumn) const
575  { return getColumnIsInteger(whichColumn);}
578  inline double getColLower(int whichColumn) const
579  { return getColumnLower(whichColumn);}
582  inline double getColUpper(int whichColumn) const
583  { return getColumnUpper(whichColumn) ;}
586  inline double getColObjective(int whichColumn) const
587  { return getColumnObjective(whichColumn);}
590  inline const char * getColName(int whichColumn) const
591  { return getColumnName(whichColumn);}
594  inline bool getColIsInteger(int whichColumn) const
595  { return getColumnIsInteger(whichColumn);}
598  const char * getRowLowerAsString(int whichRow) const ;
601  const char * getRowUpperAsString(int whichRow) const ;
602  inline const char * rowLowerAsString(int whichRow) const
603  { return getRowLowerAsString(whichRow);}
606  inline const char * rowUpperAsString(int whichRow) const
607  { return getRowUpperAsString(whichRow) ;}
610  const char * getColumnLowerAsString(int whichColumn) const ;
613  const char * getColumnUpperAsString(int whichColumn) const ;
616  const char * getColumnObjectiveAsString(int whichColumn) const ;
619  const char * getColumnIsIntegerAsString(int whichColumn) const ;
622  inline const char * columnLowerAsString(int whichColumn) const
623  { return getColumnLowerAsString(whichColumn);}
626  inline const char * columnUpperAsString(int whichColumn) const
627  { return getColumnUpperAsString(whichColumn) ;}
630  inline const char * columnObjectiveAsString(int whichColumn) const
631  { return getColumnObjectiveAsString(whichColumn);}
634  inline const char * objectiveAsString(int whichColumn) const
635  { return getColumnObjectiveAsString(whichColumn);}
638  inline const char * columnIsIntegerAsString(int whichColumn) const
639  { return getColumnIsIntegerAsString(whichColumn);}
642  inline const char * isIntegerAsString(int whichColumn) const
643  { return getColumnIsIntegerAsString(whichColumn);}
645  int row(const char * rowName) const;
647  int column(const char * columnName) const;
649  inline int type() const
650  { return type_;}
652  inline double unsetValue() const
653  { return -1.23456787654321e-97;}
655  int createPackedMatrix(CoinPackedMatrix & matrix,
656  const double * associated);
662  int countPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
663  const double * associated);
666  void createPlusMinusOne(CoinBigIndex * startPositive, CoinBigIndex * startNegative,
667  int * indices,
668  const double * associated);
670  int createArrays(double * & rowLower, double * & rowUpper,
671  double * & columnLower, double * & columnUpper,
672  double * & objective, int * & integerType,
673  double * & associated);
675  inline bool stringsExist() const
676  { return string_.numberItems()!=0;}
678  inline const CoinModelHash * stringArray() const
679  { return &string_;}
681  inline double * associatedArray() const
682  { return associated_;}
684  inline double * rowLowerArray() const
685  { return rowLower_;}
687  inline double * rowUpperArray() const
688  { return rowUpper_;}
690  inline double * columnLowerArray() const
691  { return columnLower_;}
693  inline double * columnUpperArray() const
694  { return columnUpper_;}
696  inline double * objectiveArray() const
697  { return objective_;}
699  inline int * integerTypeArray() const
700  { return integerType_;}
702  inline const CoinModelHash * rowNames() const
703  { return &rowName_;}
705  inline const CoinModelHash * columnNames() const
706  { return &columnName_;}
708  inline void zapRowNames()
709  { rowName_=CoinModelHash();}
711  inline void zapColumnNames()
714  inline const int * cutMarker() const
715  { return cut_;}
717  inline double optimizationDirection() const {
718  return optimizationDirection_;
719  }
721  inline void setOptimizationDirection(double value)
722  { optimizationDirection_=value;}
724  inline void * moreInfo() const
725  { return moreInfo_;}
727  inline void setMoreInfo(void * info)
728  { moreInfo_ = info;}
737  int whatIsSet() const;
739 
757  void loadBlock (const CoinPackedMatrix& matrix,
758  const double* collb, const double* colub,
759  const double* obj,
760  const double* rowlb, const double* rowub) ;
777  void loadBlock (const CoinPackedMatrix& matrix,
778  const double* collb, const double* colub,
779  const double* obj,
780  const char* rowsen, const double* rowrhs,
781  const double* rowrng) ;
782 
795  void loadBlock (const int numcols, const int numrows,
796  const CoinBigIndex * start, const int* index,
797  const double* value,
798  const double* collb, const double* colub,
799  const double* obj,
800  const double* rowlb, const double* rowub) ;
801 
814  void loadBlock (const int numcols, const int numrows,
815  const CoinBigIndex * start, const int* index,
816  const double* value,
817  const double* collb, const double* colub,
818  const double* obj,
819  const char* rowsen, const double* rowrhs,
820  const double* rowrng) ;
821 
823 
827  CoinModel();
829  CoinModel(int firstRows, int firstColumns, int firstElements,bool noNames=false);
832  CoinModel(const char *fileName, int allowStrings=0);
836  CoinModel( int nonLinear, const char * fileName,const void * info);
839  const CoinPackedMatrix * matrix,
840  const double * rowLower, const double * rowUpper,
841  const double * columnLower, const double * columnUpper,
842  const double * objective);
844  virtual CoinBaseModel * clone() const;
845 
847  virtual ~CoinModel();
849 
853  CoinModel(const CoinModel&);
855  CoinModel& operator=(const CoinModel&);
857 
860  void validateLinks() const;
863 private:
865  void resize(int maximumRows, int maximumColumns, int maximumElements);
867  void fillRows(int which,bool forceCreation,bool fromAddRow=false);
869  void fillColumns(int which,bool forceCreation,bool fromAddColumn=false);
872  void fillList(int which, CoinModelLinkedList & list,int type) const ;
876  void createList(int type) const;
878  int addString(const char * string);
882  double getDoubleFromString(CoinYacc & info, const char * string);
884  void freeStringMemory(CoinYacc & info);
885 public:
887  int computeAssociated(double * associated);
893  CoinPackedMatrix * quadraticRow(int rowNumber,double * linear,
894  int & numberBad) const;
896  void replaceQuadraticRow(int rowNumber,const double * linear, const CoinPackedMatrix * quadraticPart);
901  CoinModel * reorder(const char * mark) const;
912  int expandKnapsack(int knapsackRow, int & numberOutput,double * buildObj, CoinBigIndex * buildStart,
913  int * buildRow, double * buildElement,int reConstruct=-1) const;
915  void setCutMarker(int size,const int * marker);
917  void setPriorities(int size,const int * priorities);
919  inline const int * priorities() const
920  { return priority_;}
922  void setOriginalIndices(const int * row, const int * column);
923 
924 private:
928  void gdb( int nonLinear, const char * fileName, const void * info);
930  int decodeBit(char * phrase, char * & nextPhrase, double & coefficient, bool ifFirst) const;
932  void badType() const;
935  int maximumRows_;
948  double * rowLower_;
950  double * rowUpper_;
960  int * rowType_;
962  double * objective_;
964  double * columnLower_;
966  double * columnUpper_;
982  int * columnType_;
984  int * start_;
1002  double * sortElements_;
1012  double * associated_;
1016  int * startSOS_;
1018  int * memberSOS_;
1020  int * typeSOS_;
1024  double * referenceSOS_;
1026  int * priority_;
1028  int * cut_;
1030  void * moreInfo_;
1038  mutable int type_;
1040  bool noNames_;
1047  mutable int links_;
1049 };
1051 double getFunctionValueFromString(const char * string, const char * x, double xValue);
1053 double getDoubleFromString(CoinYacc & info, const char * string, const char * x, double xValue);
1054 #endif
int maximumQuadraticElements_
Maximum number of quadratic elements.
Definition: CoinModel.hpp:946
int CoinBigIndex
double getColLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:578
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:634
int * rowType_
Row types.
Definition: CoinModel.hpp:960
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:161
double objective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:562
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:724
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:1000
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:253
void setMessageHandler(CoinMessageHandler *handler)
Pass in message handler.
int * startSOS_
SOS starts.
Definition: CoinModel.hpp:1016
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:919
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:649
void * moreInfo_
Pointer to more information.
Definition: CoinModel.hpp:1030
double getQuadraticElement(int i, int j) const
Returns quadratic value for columns i and j.
double unsetValue() const
returns unset value
Definition: CoinModel.hpp:652
int * priority_
priorities (given for all columns (-1 if not integer)
Definition: CoinModel.hpp:1026
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:952
int * integerType_
Integer information.
Definition: CoinModel.hpp:970
CoinModelLinkedList quadraticColumnList_
Linked list for quadratic columns.
Definition: CoinModel.hpp:1008
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:988
int * integerTypeArray() const
Return integerType array.
Definition: CoinModel.hpp:699
const int * originalRows() const
Return pointers to original rows (for decomposition)
Definition: CoinModel.hpp:435
std::string rowBlockName_
Rowblock name.
Definition: CoinModel.hpp:103
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:55
double * columnLowerArray() const
Return columnLower array.
Definition: CoinModel.hpp:690
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:288
const CoinModelHash * columnNames() const
Return column names array.
Definition: CoinModel.hpp:705
double * columnLower_
Column Lower.
Definition: CoinModel.hpp:964
int * columnType_
Column types.
Definition: CoinModel.hpp:982
std::string problemName_
Problem name.
Definition: CoinModel.hpp:101
int addString(const char *string)
Adds one string, returns index.
const int * originalColumns() const
Return pointers to original columns (for decomposition)
Definition: CoinModel.hpp:438
double * rowLower_
Row lower.
Definition: CoinModel.hpp:948
const CoinModelHash * stringArray() const
Return string array.
Definition: CoinModel.hpp:678
CoinModelLinkedList columnList_
Linked list for columns.
Definition: CoinModel.hpp:994
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:938
const char * columnLowerAsString(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:622
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:582
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:268
CoinModelHash string_
Strings.
Definition: CoinModel.hpp:972
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:527
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:59
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:1014
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:986
int numberQuadraticElements_
Current number of quadratic elements.
Definition: CoinModel.hpp:944
bool columnIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:570
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.
CoinMessageHandler * handler_
Message handler (Passed in)
Definition: CoinModel.hpp:107
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:962
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:590
double * rowUpper_
Row upper.
Definition: CoinModel.hpp:950
CoinMessages messages_
Messages.
Definition: CoinModel.hpp:109
double * referenceSOS_
SOS reference.
Definition: CoinModel.hpp:1024
void setElement(int i, int j, double value)
Sets value for row i and column j.
CoinModelHash columnName_
Column names.
Definition: CoinModel.hpp:968
const char * rowUpperAsString(int whichRow) const
Gets rowUpper (if row does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:606
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:283
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:721
int * cut_
Nonzero if row is cut - done in one go e.g. from ampl.
Definition: CoinModel.hpp:1028
int sizeAssociated_
Size of associated values.
Definition: CoinModel.hpp:1010
void setRowBlock(const std::string &name)
Set row block name.
Definition: CoinModel.hpp:77
CoinModelHash2 hashElements_
Hash for elements.
Definition: CoinModel.hpp:990
double * rowLowerArray() const
Return rowLower array.
Definition: CoinModel.hpp:684
int logLevel_
Print level.
Definition: CoinModel.hpp:119
void setColLower(int numberColumns, const double *columnLower)
Sets columnLower array.
Definition: CoinModel.hpp:372
int sortSize_
Size of sort arrays.
Definition: CoinModel.hpp:1004
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:278
const char * columnName(int whichColumn) const
Gets name (if column does not exist then NULL)
Definition: CoinModel.hpp:566
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:177
const char * columnUpperAsString(int whichColumn) const
Gets columnUpper (if column does not exist then COIN_DBL_MAX)
Definition: CoinModel.hpp:626
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:74
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...
bool noNames_
True if no names EVER being used (for users who know what they are doing)
Definition: CoinModel.hpp:1040
double * objectiveArray() const
Return objective array.
Definition: CoinModel.hpp:696
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:273
const char * isIntegerAsString(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:642
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:708
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:687
virtual CoinBigIndex numberElements() const =0
Return number of elements.
const CoinModelHash * rowNames() const
Return row names array.
Definition: CoinModel.hpp:702
int logLevel() const
Get print level 0 - off, 1 - errors, 2 - more.
Definition: CoinModel.hpp:62
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:984
This is a first attempt at a message handler.
const CoinPackedMatrix * packedMatrix() const
Return a pointer to CoinPackedMatrix (or NULL)
Definition: CoinModel.hpp:432
int packCols()
Packs down all columns i.e.
Definition: CoinModel.hpp:356
double columnLower(int whichColumn) const
Gets columnLower (if column does not exist then 0.0)
Definition: CoinModel.hpp:550
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:675
int numberRows_
Current number of rows.
Definition: CoinModel.hpp:93
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:105
double * associatedArray() const
Returns associated array.
Definition: CoinModel.hpp:681
const char * columnObjectiveAsString(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:630
bool getColIsInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:594
int * memberSOS_
SOS members.
Definition: CoinModel.hpp:1018
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:714
const char * getProblemName() const
Return the problem name.
Definition: CoinModel.hpp:67
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:49
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:558
int * typeSOS_
SOS type.
Definition: CoinModel.hpp:1020
double * sortElements_
Array for sorting elements.
Definition: CoinModel.hpp:1002
void deleteCol(int whichColumn)
Deletes all entries in column and bounds.
Definition: CoinModel.hpp:342
CoinModelLinkedList quadraticRowList_
Linked list for quadratic rows.
Definition: CoinModel.hpp:1006
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:258
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:554
double * associated_
Associated values.
Definition: CoinModel.hpp:1012
double objectiveOffset_
Objective offset to be passed on.
Definition: CoinModel.hpp:99
CoinModelHash2 hashQuadraticElements_
Hash for quadratic elements.
Definition: CoinModel.hpp:998
double optimizationDirection_
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:97
int type_
Type of build - -1 unset, 0 for row, 1 for column, 2 linked.
Definition: CoinModel.hpp:1038
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:263
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:80
bool isInteger(int whichColumn) const
Gets if integer (if column does not exist then false)
Definition: CoinModel.hpp:574
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:83
void zapColumnNames()
Reset column names.
Definition: CoinModel.hpp:711
double getColObjective(int whichColumn) const
Gets columnObjective (if column does not exist then 0.0)
Definition: CoinModel.hpp:586
double optimizationDirection() const
Direction of optimization (1 - minimize, -1 - maximize, 0 - ignore.
Definition: CoinModel.hpp:717
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:996
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:449
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:293
double * columnUpper_
Column Upper.
Definition: CoinModel.hpp:966
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:379
int * prioritySOS_
SOS priority.
Definition: CoinModel.hpp:1022
void setObjectiveOffset(double value)
Set objective offset.
Definition: CoinModel.hpp:52
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:298
int links_
Links present (could be tested by sizes of objects) 0 - none, 1 - row links, 2 - column links...
Definition: CoinModel.hpp:1047
CoinModelLinkedList rowList_
Linked list for rows.
Definition: CoinModel.hpp:992
double rowLower(int whichRow) const
Return number of elements.
Definition: CoinModel.hpp:523
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:693
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:332
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:327
void setMoreInfo(void *info)
Set pointer to more information.
Definition: CoinModel.hpp:727
int numberElements_
Current number of elements.
Definition: CoinModel.hpp:940
void freeStringMemory(CoinYacc &info)
Frees value memory.
int numberColumns_
Current number of columns.
Definition: CoinModel.hpp:95
void operator()(int i, int j, double value)
Sets value for row i and column j.
Definition: CoinModel.hpp:185
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:638
double getElement(int i, int j) const
Returns value for row i and column j.
int maximumElements_
Maximum number of elements.
Definition: CoinModel.hpp:942
int maximumRows_
Maximum number of rows.
Definition: CoinModel.hpp:936
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:531
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:602
int numberRows() const
Return number of rows.
Definition: CoinModel.hpp:39
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:446
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)