Dip  0.92.4
OsiData.hpp
Go to the documentation of this file.
1 // Name: OsiData.hpp
2 // Author: Francois Margot
3 // Tepper School of Business
4 // Carnegie Mellon University, Pittsburgh, PA 15213
5 // email: fmargot@andrew.cmu.edu
6 // Date: 12/2/06
7 //-----------------------------------------------------------------------------
8 // Copyright (C) 2006, Francois Margot and others. All Rights Reserved.
9 
10 #ifndef OsiData_H
11 #define OsiData_H
12 
20 #include "CoinPackedMatrix.hpp"
21 
22 class OsiData {
23 
24 public:
25 
28 
30  virtual void setInfinity(const double givenInfinity){
31  infinity = givenInfinity;
32  }
33 
35  inline double getInfinity() const {return infinity;};
36 
38  virtual void setNrow(const int givenNrow){
39  nrow = givenNrow;
40  }
41 
43  inline int getNrow() const {return nrow;};
44 
46  virtual void setNcol(const int givenNcol){
47  ncol = givenNcol;
48  }
49 
51  inline int getNcol() const {return ncol;};
52 
55  virtual void setMatrixByCol(const CoinPackedMatrix *givenMatrixByCol){
56  matrixByCol = givenMatrixByCol;
57  }
58 
60  inline const CoinPackedMatrix *getMatrixByCol() const {return matrixByCol;};
61 
64  virtual void setMatrixByRow(const CoinPackedMatrix *givenMatrixByRow){
65  matrixByRow = givenMatrixByRow;
66  }
67 
69  inline const CoinPackedMatrix *getMatrixByRow() const {return matrixByRow;};
70 
72  virtual void setObj(const double *givenObj){
73  obj = givenObj;
74  }
75 
77  inline const double *getObj() const {return obj;};
78 
81  virtual void setColLower(const double *givenColLower){
82  colLower = givenColLower;
83  }
84 
86  inline const double *getColLower() const {return colLower;};
87 
90  virtual void setColUpper(const double *givenColUpper){
91  colUpper = givenColUpper;
92  }
93 
95  inline const double *getColUpper() const {return colUpper;};
96 
99  virtual void setRowLower(const double *givenRowLower){
100  rowLower = givenRowLower;
101  }
102 
104  inline const double *getRowLower() const {return rowLower;};
105 
108  virtual void setRowUpper(const double *givenRowUpper){
109  rowUpper = givenRowUpper;
110  }
111 
113  inline const double *getRowUpper() const {return rowUpper;};
114 
117  //virtual void setRowRhs(const double *givenRowRhs);
119  inline const double *getRowRhs() const {return rowRhs;};
121  inline const double *getRowRange() const {return rowRange;};
123  inline const char *getRowSense() const {return rowSense;};
124 
127  //virtual void setRowActivity(const double *givenRowActivity);
129  inline const double *getRowActivity() const {return rowActivity;};
130 
133  virtual void setColType(const char *givenColType){
134  colType = givenColType;
135  }
136 
138  inline const char *getColType() const {return colType;};
139 
141  virtual void setPrimalSol(const double * givenPrimalSol){
142  primalSol = givenPrimalSol;
143  }
144 
146  inline const double *getPrimalSol() const {return primalSol;};
147 
152 
153  rowRhs = new double[nrow];
154  rowRange = new double[nrow];
155  rowSense = new char[nrow];
156  rowActivity = new double[nrow];
157 
158  int r;
159  for(r = 0; r < nrow; r++){
161  rowSense[r], rowRhs[r], rowRange[r]);
162  }
164  }
166 
169  inline void convertBoundToSense(const double lower,
170  const double upper,
171  char & sense,
172  double & right,
173  double & range) const
174  {
175  double inf = getInfinity();
176  range = 0.0;
177  if (lower > -inf) {
178  if (upper < inf) {
179  right = upper;
180  if (upper==lower) {
181  sense = 'E';
182  } else {
183  sense = 'R';
184  range = upper - lower;
185  }
186  } else {
187  sense = 'G';
188  right = lower;
189  }
190  } else {
191  if (upper < inf) {
192  sense = 'L';
193  right = upper;
194  } else {
195  sense = 'N';
196  right = 0.0;
197  }
198  }
199  }
200 
203  OsiData(const double givenInfinity = DBL_MAX,
205  const int &givenNrow = 0,
206  const int &givenNcol = 0,
207  const CoinPackedMatrix * givenMatrixByCol = NULL,
208  const CoinPackedMatrix * givenMatrixByRow = NULL,
209  const double * givenObj = NULL,
210  const double * givenColLower = NULL,
211  const double * givenColUpper = NULL,
212  const double * givenRowLower = NULL,
213  const double * givenRowUpper = NULL,
214  const char * givenColType = NULL,
215  const double * givenPrimalSol = NULL) :
216  infinity(givenInfinity),
217  nrow(givenNrow),
218  ncol(givenNcol),
219  matrixByCol(givenMatrixByCol),
220  matrixByRow(givenMatrixByRow),
221  obj(givenObj),
222  colLower(givenColLower),
223  colUpper(givenColUpper),
224  rowLower(givenRowLower),
225  rowUpper(givenRowUpper),
226  colType(givenColType),
227  primalSol(givenPrimalSol) {}
228 
229 
231  virtual ~OsiData(){
232  if(rowRhs)
233  delete [] rowRhs;
234  if(rowRange)
235  delete [] rowRange;
236  if(rowSense)
237  delete [] rowSense;
238  if(rowActivity)
239  delete [] rowActivity;
240  }
242 
243 protected:
244 
245  // Private member data
246 
250 
251  // Definition of infinity
252  double infinity;
253 
254  // Number of constraints
255  int nrow;
256 
257  // Number of variables.
258  int ncol;
259 
260  // Pointer on matrix of coefficients (ordered by columns).
262 
263  // Pointer on matrix of coefficients (ordered by rows).
265 
266  // Pointer on vector of objective coefficients.
267  const double *obj;
268 
269  // Pointer on vector of lower bounds on variables.
270  const double *colLower;
271 
272  // Pointer on vector of upper bounds for variables.
273  const double *colUpper;
274 
275  // Pointer on vector of lower bounds for constraints.
276  const double *rowLower;
277 
278  // Pointer on vector of upper bounds for constraints.
279  const double *rowUpper;
280 
289  const char * colType;
290 
291  // Pointer on vector for current primal solution.
292  const double * primalSol;
293 
294 protected:
295 
296  // Vector of right hand sides for constraints.
297  double * rowRhs;
298 
299  // Vector of ranges for constraints.
300  double * rowRange;
301 
302  // Vector of row senses for constraints.
303  char * rowSense;
304 
305  // Vector of activity of constraints (i.e. coefficient matrix
306  // times primalSol).
307  double * rowActivity;
308 
309 
311 
312 };
313 
314 
315 
316 #endif
int getNcol() const
Get ncol.
Definition: OsiData.hpp:51
const char * getRowSense() const
Get rowSense.
Definition: OsiData.hpp:123
virtual void setRowLower(const double *givenRowLower)
Set rowLower to point on a vector holding the lower bounds on the constraints.
Definition: OsiData.hpp:99
const char * getColType() const
Get colType.
Definition: OsiData.hpp:138
virtual void setNrow(const int givenNrow)
Set nrow to the number of rows.
Definition: OsiData.hpp:38
const double * getObj() const
Get obj.
Definition: OsiData.hpp:77
const char * colType
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:289
virtual void setObj(const double *givenObj)
Set obj to point on a vector holding the objective coefficient values.
Definition: OsiData.hpp:72
const double * colUpper
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:273
void times(const double *x, double *y) const
Return A * x in y.
const CoinPackedMatrix * getMatrixByRow() const
Get matrixByRow.
Definition: OsiData.hpp:69
virtual void setColLower(const double *givenColLower)
Set colLower to point on a vector holding the lower bounds on the variables.
Definition: OsiData.hpp:81
CoinPackedMatrix const * matrixByRow
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:264
double infinity
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:252
const double * getRowRhs() const
Set rowRhs to point on a vector holding the right hand side of the constraints (for a ranged constrai...
Definition: OsiData.hpp:119
virtual void setInfinity(const double givenInfinity)
Set infinity.
Definition: OsiData.hpp:30
virtual void setPrimalSol(const double *givenPrimalSol)
Set primal solution.
Definition: OsiData.hpp:141
OsiData(const double givenInfinity=DBL_MAX, const int &givenNrow=0, const int &givenNcol=0, const CoinPackedMatrix *givenMatrixByCol=NULL, const CoinPackedMatrix *givenMatrixByRow=NULL, const double *givenObj=NULL, const double *givenColLower=NULL, const double *givenColUpper=NULL, const double *givenRowLower=NULL, const double *givenRowUpper=NULL, const char *givenColType=NULL, const double *givenPrimalSol=NULL)
Default constructor.
Definition: OsiData.hpp:204
void initializeOtherData()
initialize the non-const data
Definition: OsiData.hpp:149
virtual ~OsiData()
Destructor.
Definition: OsiData.hpp:231
void convertBoundToSense(const double lower, const double upper, char &sense, double &right, double &range) const
A quick inlined function to convert from the lb/ub style of constraint definition to the sense/rhs/ra...
Definition: OsiData.hpp:169
Sparse Matrix Base Class.
double * rowRhs
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:297
const double * rowUpper
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:279
int nrow
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:255
virtual void setColUpper(const double *givenColUpper)
Set colUpper to point on a vector holding the upper bounds on the variables.
Definition: OsiData.hpp:90
const double * getColUpper() const
Get colUpper.
Definition: OsiData.hpp:95
int ncol
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:258
char * rowSense
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:303
const double * getColLower() const
Get colLower.
Definition: OsiData.hpp:86
const double * getRowLower() const
Get rowLower.
Definition: OsiData.hpp:104
const double * rowLower
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:276
const double * colLower
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:270
const double * primalSol
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:292
virtual void setMatrixByCol(const CoinPackedMatrix *givenMatrixByCol)
Set matrixByCol to point on the coefficient matrix ordered by columns.
Definition: OsiData.hpp:55
const double * getPrimalSol() const
Get primal solution.
Definition: OsiData.hpp:146
virtual void setMatrixByRow(const CoinPackedMatrix *givenMatrixByRow)
Set matrixByRow to point on the coefficient matrix ordered by rows.
Definition: OsiData.hpp:64
Class collecting pointers on data for OsiEmpty.
Definition: OsiData.hpp:22
int getNrow() const
Get nrow.
Definition: OsiData.hpp:43
virtual void setColType(const char *givenColType)
Set colType to point on a vector holding the type of the variables (&#39;B&#39;, &#39;I&#39;, or &#39;C&#39; for Binary...
Definition: OsiData.hpp:133
virtual void setNcol(const int givenNcol)
Set ncol to the number of variables.
Definition: OsiData.hpp:46
const double * obj
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:267
const CoinPackedMatrix * getMatrixByCol() const
Get matrixByCol.
Definition: OsiData.hpp:60
double getInfinity() const
Get infinity.
Definition: OsiData.hpp:35
const double * getRowRange() const
Get rowRange.
Definition: OsiData.hpp:121
double * rowRange
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:300
#define CoinAssert(expression)
Definition: CoinError.hpp:183
CoinPackedMatrix const * matrixByCol
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:261
const double * getRowUpper() const
Get rowUpper.
Definition: OsiData.hpp:113
virtual void setRowUpper(const double *givenRowUpper)
Set rowUpper to point on a vector holding the upper bounds on the constraints.
Definition: OsiData.hpp:108
const double * getRowActivity() const
Set rowActivity to point on a vector holding the activity of the constraints (i.e.
Definition: OsiData.hpp:129
double * rowActivity
Pointer on vector of characters for columns types.
Definition: OsiData.hpp:307