CoinSnapshot.hpp
Go to the documentation of this file.
1 /* $Id: CoinSnapshot.hpp 1191 2009-07-25 08:38:12Z forrest $ */
2 // Copyright (C) 2006, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 #ifndef CoinSnapshot_H
5 #define CoinSnapshot_H
6 
7 class CoinPackedMatrix;
8 #include "CoinFinite.hpp"
9 
10 //#############################################################################
11 
23 class CoinSnapshot {
24 
25 public:
26 
27  //---------------------------------------------------------------------------
33  inline int getNumCols() const
35  { return numCols_;}
36 
38  inline int getNumRows() const
39  { return numRows_;}
40 
42  inline int getNumElements() const
43  { return numElements_;}
44 
46  inline int getNumIntegers() const
47  { return numIntegers_;}
48 
50  inline const double * getColLower() const
51  { return colLower_;}
52 
54  inline const double * getColUpper() const
55  { return colUpper_;}
56 
58  inline const double * getRowLower() const
59  { return rowLower_;}
60 
62  inline const double * getRowUpper() const
63  { return rowUpper_;}
64 
72  inline const double * getRightHandSide() const
73  { return rightHandSide_;}
74 
76  inline const double * getObjCoefficients() const
77  { return objCoefficients_;}
78 
80  inline double getObjSense() const
81  { return objSense_;}
82 
84  inline bool isContinuous(int colIndex) const
85  { return colType_[colIndex]=='C';}
86 
88  inline bool isBinary(int colIndex) const
89  { return colType_[colIndex]=='B';}
90 
92  inline bool isInteger(int colIndex) const
93  { return colType_[colIndex]=='B'||colType_[colIndex]=='I';}
94 
96  inline bool isIntegerNonBinary(int colIndex) const
97  { return colType_[colIndex]=='I';}
98 
100  inline bool isFreeBinary(int colIndex) const
101  { return colType_[colIndex]=='B'&&colUpper_[colIndex]>colLower_[colIndex];}
102 
104  inline const char * getColType() const
105  { return colType_;}
106 
108  inline const CoinPackedMatrix * getMatrixByRow() const
109  { return matrixByRow_;}
110 
112  inline const CoinPackedMatrix * getMatrixByCol() const
113  { return matrixByCol_;}
114 
117  { return originalMatrixByRow_;}
118 
121  { return originalMatrixByCol_;}
123 
126  inline const double * getColSolution() const
128  { return colSolution_;}
129 
131  inline const double * getRowPrice() const
132  { return rowPrice_;}
133 
135  inline const double * getReducedCost() const
136  { return reducedCost_;}
137 
139  inline const double * getRowActivity() const
140  { return rowActivity_;}
141 
143  inline const double * getDoNotSeparateThis() const
144  { return doNotSeparateThis_;}
146 
149  inline double getInfinity() const
151  { return infinity_;}
152 
155  inline double getObjValue() const
156  { return objValue_;}
157 
159  inline double getObjOffset() const
160  { return objOffset_;}
161 
163  inline double getDualTolerance() const
164  { return dualTolerance_;}
165 
167  inline double getPrimalTolerance() const
168  { return primalTolerance_;}
169 
171  inline double getIntegerTolerance() const
172  { return integerTolerance_;}
173 
175  inline double getIntegerUpperBound() const
176  { return integerUpperBound_;}
177 
179  inline double getIntegerLowerBound() const
180  { return integerLowerBound_;}
182 
183  //---------------------------------------------------------------------------
184 
199  void loadProblem(const CoinPackedMatrix& matrix,
200  const double* collb, const double* colub,
201  const double* obj,
202  const double* rowlb, const double* rowub,
203  bool makeRowCopy=false);
204 
206 
207  //---------------------------------------------------------------------------
208 
211  inline void setNumCols(int value)
213  { numCols_ = value;}
214 
216  inline void setNumRows(int value)
217  { numRows_ = value;}
218 
220  inline void setNumElements(int value)
221  { numElements_ = value;}
222 
224  inline void setNumIntegers(int value)
225  { numIntegers_ = value;}
226 
228  void setColLower(const double * array, bool copyIn=true);
229 
231  void setColUpper(const double * array, bool copyIn=true);
232 
234  void setRowLower(const double * array, bool copyIn=true);
235 
237  void setRowUpper(const double * array, bool copyIn=true);
238 
246  void setRightHandSide(const double * array, bool copyIn=true);
247 
256  void createRightHandSide();
257 
259  void setObjCoefficients(const double * array, bool copyIn=true);
260 
262  inline void setObjSense(double value)
263  { objSense_ = value;}
264 
266  void setColType(const char *array, bool copyIn=true);
267 
269  void setMatrixByRow(const CoinPackedMatrix * matrix, bool copyIn=true);
270 
272  void createMatrixByRow();
273 
275  void setMatrixByCol(const CoinPackedMatrix * matrix, bool copyIn=true);
276 
278  void setOriginalMatrixByRow(const CoinPackedMatrix * matrix, bool copyIn=true);
279 
281  void setOriginalMatrixByCol(const CoinPackedMatrix * matrix, bool copyIn=true);
282 
284  void setColSolution(const double * array, bool copyIn=true);
285 
287  void setRowPrice(const double * array, bool copyIn=true);
288 
290  void setReducedCost(const double * array, bool copyIn=true);
291 
293  void setRowActivity(const double * array, bool copyIn=true);
294 
296  void setDoNotSeparateThis(const double * array, bool copyIn=true);
297 
299  inline void setInfinity(double value)
300  { infinity_ = value;}
301 
303  inline void setObjValue(double value)
304  { objValue_ = value;}
305 
307  inline void setObjOffset(double value)
308  { objOffset_ = value;}
309 
311  inline void setDualTolerance(double value)
312  { dualTolerance_ = value;}
313 
315  inline void setPrimalTolerance(double value)
316  { primalTolerance_ = value;}
317 
319  inline void setIntegerTolerance(double value)
320  { integerTolerance_ = value;}
321 
323  inline void setIntegerUpperBound(double value)
324  { integerUpperBound_ = value;}
325 
327  inline void setIntegerLowerBound(double value)
328  { integerLowerBound_ = value;}
330 
331  //---------------------------------------------------------------------------
332 
334 
335  CoinSnapshot();
337 
339  CoinSnapshot(const CoinSnapshot &);
340 
342  CoinSnapshot & operator=(const CoinSnapshot& rhs);
343 
345  virtual ~CoinSnapshot ();
346 
348 
349 private:
351 
352 
358  void gutsOfDestructor(int type);
360  void gutsOfCopy(const CoinSnapshot & rhs);
362 
364 
366  double objSense_;
367 
369  double infinity_;
370 
372  double objValue_;
373 
375  double objOffset_;
376 
379 
382 
385 
388 
391 
393  const double * colLower_;
394 
396  const double * colUpper_;
397 
399  const double * rowLower_;
400 
402  const double * rowUpper_;
403 
405  const double * rightHandSide_;
406 
408  const double * objCoefficients_;
409 
411  const char * colType_;
412 
415 
418 
421 
424 
426  const double * colSolution_;
427 
429  const double * rowPrice_;
430 
432  const double * reducedCost_;
433 
435  const double * rowActivity_;
436 
438  const double * doNotSeparateThis_;
439 
441  int numCols_;
442 
444  int numRows_;
445 
448 
451 
453  typedef struct {
454  unsigned int colLower:1;
455  unsigned int colUpper:1;
456  unsigned int rowLower:1;
457  unsigned int rowUpper:1;
458  unsigned int rightHandSide:1;
459  unsigned int objCoefficients:1;
460  unsigned int colType:1;
461  unsigned int matrixByRow:1;
462  unsigned int matrixByCol:1;
463  unsigned int originalMatrixByRow:1;
464  unsigned int originalMatrixByCol:1;
465  unsigned int colSolution:1;
466  unsigned int rowPrice:1;
467  unsigned int reducedCost:1;
468  unsigned int rowActivity:1;
469  unsigned int doNotSeparateThis:1;
470  } coinOwned;
473 };
474 #endif
double getIntegerLowerBound() const
Get integer lower bound i.e. best possible solution * getObjSense.
const double * rightHandSide_
pointer to array[getNumRows()] of rhs side values
double integerTolerance_
integer tolerance
int getNumRows() const
Get number of rows.
void setObjSense(double value)
Set objective function sense (1 for min (default), -1 for max)
double primalTolerance_
primal tolerance
const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual variable values.
int getNumCols() const
Get number of columns.
double objValue_
objective function value (including any rhs offset)
const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
const double * rowActivity_
pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vector)...
const double * doNotSeparateThis_
pointer to array[getNumCols()] of primal variable values which should not be separated (for debug) ...
double integerUpperBound_
integer upper bound i.e. best solution * getObjSense
const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
void setIntegerLowerBound(double value)
Set integer lower bound i.e. best possible solution * getObjSense.
const CoinPackedMatrix * getOriginalMatrixByCol() const
Get pointer to column-wise copy of "original" matrix.
To say whether arrays etc are owned by CoinSnapshot.
void setObjCoefficients(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of objective function coefficients.
void setIntegerUpperBound(double value)
Set integer upper bound i.e. best solution * getObjSense.
void setMatrixByCol(const CoinPackedMatrix *matrix, bool copyIn=true)
Set pointer to column-wise copy of current matrix.
int numRows_
number of rows
const double * getRightHandSide() const
Get pointer to array[getNumRows()] of row right-hand sides This gives same results as OsiSolverInterf...
const double * colUpper_
pointer to array[getNumCols()] of column upper bounds
double getObjOffset() const
Get objective offset i.e. sum c sub j * x subj -objValue = objOffset.
void setOriginalMatrixByCol(const CoinPackedMatrix *matrix, bool copyIn=true)
Set pointer to column-wise copy of "original" matrix.
const CoinPackedMatrix * matrixByRow_
pointer to row-wise copy of current matrix
const CoinPackedMatrix * getOriginalMatrixByRow() const
Get pointer to row-wise copy of "original" matrix.
void setDoNotSeparateThis(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of primal variable values which should not be separated (for debug...
Sparse Matrix Base Class.
void setOriginalMatrixByRow(const CoinPackedMatrix *matrix, bool copyIn=true)
Set pointer to row-wise copy of "original" matrix.
void setColUpper(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of column upper bounds.
const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.
double getPrimalTolerance() const
Get primal tolerance.
void setNumElements(int value)
Set number of nonzero elements.
bool isInteger(int colIndex) const
Return true if column is integer.
bool isIntegerNonBinary(int colIndex) const
Return true if variable is general integer.
void gutsOfDestructor(int type)
Does main work of destructor - type (or'ed) 1 - NULLify pointers 2 - delete pointers 4 - initialize s...
double dualTolerance_
dual tolerance
CoinSnapshot & operator=(const CoinSnapshot &rhs)
Assignment operator.
const CoinPackedMatrix * matrixByCol_
pointer to column-wise copy of current matrix
void loadProblem(const CoinPackedMatrix &matrix, const double *collb, const double *colub, const double *obj, const double *rowlb, const double *rowub, bool makeRowCopy=false)
Load in an problem by copying the arguments (the constraints on the rows are given by lower and upper...
coinOwned owned_
objective function sense (1 for min (default), -1 for max)
double objOffset_
objective offset i.e. sum c sub j * x subj -objValue = objOffset
void setColSolution(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of primal variable values.
void setIntegerTolerance(double value)
Set integer tolerance.
void setObjValue(double value)
Set objective function value (including any rhs offset)
const double * getDoNotSeparateThis() const
Get pointer to array[getNumCols()] of primal variable values which should not be separated (for debug...
const char * getColType() const
Get colType array ('B', 'I', or 'C' for Binary, Integer and Continuous)
double integerLowerBound_
integer lower bound i.e. best possible solution * getObjSense
const double * rowLower_
pointer to array[getNumRows()] of row lower bounds
int numIntegers_
number of integer variables
void setDualTolerance(double value)
Set dual tolerance.
int numElements_
number of nonzero elements
const double * colLower_
pointer to array[getNumCols()] of column lower bounds
const double * objCoefficients_
pointer to array[getNumCols()] of objective function coefficients
const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of current matrix.
const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of current matrix.
int getNumElements() const
Get number of nonzero elements.
void setRowLower(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of row lower bounds.
void setRowUpper(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of row upper bounds.
void setObjOffset(double value)
Set objective offset i.e. sum c sub j * x subj -objValue = objOffset.
bool isContinuous(int colIndex) const
Return true if variable is continuous.
void setRightHandSide(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of row right-hand sides This gives same results as OsiSolverInterf...
void setMatrixByRow(const CoinPackedMatrix *matrix, bool copyIn=true)
Set pointer to row-wise copy of current matrix.
const char * colType_
colType array ('B', 'I', or 'C' for Binary, Integer and Continuous)
const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
double getDualTolerance() const
Get dual tolerance.
double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
int numCols_
number of columns
double getIntegerUpperBound() const
Get integer upper bound i.e. best solution * getObjSense.
const double * reducedCost_
a pointer to array[getNumCols()] of reduced costs
void setReducedCost(const double *array, bool copyIn=true)
Set a pointer to array[getNumCols()] of reduced costs.
double getObjValue() const
Get objective function value - includinbg any offset i.e.
NON Abstract Base Class for interfacing with cut generators or branching code or .
void createRightHandSide()
Create array[getNumRows()] of row right-hand sides using existing information This gives same results...
void setRowActivity(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
void setNumIntegers(int value)
Set number of integer variables.
const double * rowUpper_
pointer to array[getNumRows()] of row upper bounds
const double * colSolution_
pointer to array[getNumCols()] of primal variable values
void setInfinity(double value)
Set solver's value for infinity.
void gutsOfCopy(const CoinSnapshot &rhs)
Does main work of copy.
double objSense_
objective function sense (1 for min (default), -1 for max)
const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
const double * rowPrice_
pointer to array[getNumRows()] of dual variable values
void setPrimalTolerance(double value)
Set primal tolerance.
double getIntegerTolerance() const
Get integer tolerance.
CoinSnapshot()
Default Constructor.
void setColType(const char *array, bool copyIn=true)
Set colType array ('B', 'I', or 'C' for Binary, Integer and Continuous)
virtual ~CoinSnapshot()
Destructor.
int getNumIntegers() const
Get number of integer variables.
const double * getColSolution() const
Get pointer to array[getNumCols()] of primal variable values.
void setNumCols(int value)
Set number of columns.
const CoinPackedMatrix * originalMatrixByRow_
pointer to row-wise copy of "original" matrix
const CoinPackedMatrix * originalMatrixByCol_
pointer to column-wise copy of "original" matrix
void createMatrixByRow()
Create row-wise copy from MatrixByCol.
const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
bool isBinary(int colIndex) const
Return true if variable is binary.
void setRowPrice(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of dual variable values.
double infinity_
solver's value for infinity
void setColLower(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of column lower bounds.
void setNumRows(int value)
Set number of rows.
bool isFreeBinary(int colIndex) const
Return true if variable is binary and not fixed at either bound.
double getInfinity() const
Get solver's value for infinity.