CoinSnapshot.hpp
Go to the documentation of this file.
1 /* $Id: CoinSnapshot.hpp 1416 2011-04-17 09:57:29Z stefan $ */
2 // Copyright (C) 2006, 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 CoinSnapshot_H
7 #define CoinSnapshot_H
8 
9 class CoinPackedMatrix;
10 #include "CoinTypes.hpp"
11 
12 //#############################################################################
13 
25 class CoinSnapshot {
26 
27 public:
28 
29  //---------------------------------------------------------------------------
35  inline int getNumCols() const
37  { return numCols_;}
38 
40  inline int getNumRows() const
41  { return numRows_;}
42 
44  inline int getNumElements() const
45  { return numElements_;}
46 
48  inline int getNumIntegers() const
49  { return numIntegers_;}
50 
52  inline const double * getColLower() const
53  { return colLower_;}
54 
56  inline const double * getColUpper() const
57  { return colUpper_;}
58 
60  inline const double * getRowLower() const
61  { return rowLower_;}
62 
64  inline const double * getRowUpper() const
65  { return rowUpper_;}
66 
74  inline const double * getRightHandSide() const
75  { return rightHandSide_;}
76 
78  inline const double * getObjCoefficients() const
79  { return objCoefficients_;}
80 
82  inline double getObjSense() const
83  { return objSense_;}
84 
86  inline bool isContinuous(int colIndex) const
87  { return colType_[colIndex]=='C';}
88 
90  inline bool isBinary(int colIndex) const
91  { return colType_[colIndex]=='B';}
92 
94  inline bool isInteger(int colIndex) const
95  { return colType_[colIndex]=='B'||colType_[colIndex]=='I';}
96 
98  inline bool isIntegerNonBinary(int colIndex) const
99  { return colType_[colIndex]=='I';}
100 
102  inline bool isFreeBinary(int colIndex) const
103  { return colType_[colIndex]=='B'&&colUpper_[colIndex]>colLower_[colIndex];}
104 
106  inline const char * getColType() const
107  { return colType_;}
108 
110  inline const CoinPackedMatrix * getMatrixByRow() const
111  { return matrixByRow_;}
112 
114  inline const CoinPackedMatrix * getMatrixByCol() const
115  { return matrixByCol_;}
116 
119  { return originalMatrixByRow_;}
120 
123  { return originalMatrixByCol_;}
125 
128  inline const double * getColSolution() const
130  { return colSolution_;}
131 
133  inline const double * getRowPrice() const
134  { return rowPrice_;}
135 
137  inline const double * getReducedCost() const
138  { return reducedCost_;}
139 
141  inline const double * getRowActivity() const
142  { return rowActivity_;}
143 
145  inline const double * getDoNotSeparateThis() const
146  { return doNotSeparateThis_;}
148 
151  inline double getInfinity() const
153  { return infinity_;}
154 
157  inline double getObjValue() const
158  { return objValue_;}
159 
161  inline double getObjOffset() const
162  { return objOffset_;}
163 
165  inline double getDualTolerance() const
166  { return dualTolerance_;}
167 
169  inline double getPrimalTolerance() const
170  { return primalTolerance_;}
171 
173  inline double getIntegerTolerance() const
174  { return integerTolerance_;}
175 
177  inline double getIntegerUpperBound() const
178  { return integerUpperBound_;}
179 
181  inline double getIntegerLowerBound() const
182  { return integerLowerBound_;}
184 
185  //---------------------------------------------------------------------------
186 
201  void loadProblem(const CoinPackedMatrix& matrix,
202  const double* collb, const double* colub,
203  const double* obj,
204  const double* rowlb, const double* rowub,
205  bool makeRowCopy=false);
206 
208 
209  //---------------------------------------------------------------------------
210 
213  inline void setNumCols(int value)
215  { numCols_ = value;}
216 
218  inline void setNumRows(int value)
219  { numRows_ = value;}
220 
222  inline void setNumElements(int value)
223  { numElements_ = value;}
224 
226  inline void setNumIntegers(int value)
227  { numIntegers_ = value;}
228 
230  void setColLower(const double * array, bool copyIn=true);
231 
233  void setColUpper(const double * array, bool copyIn=true);
234 
236  void setRowLower(const double * array, bool copyIn=true);
237 
239  void setRowUpper(const double * array, bool copyIn=true);
240 
248  void setRightHandSide(const double * array, bool copyIn=true);
249 
258  void createRightHandSide();
259 
261  void setObjCoefficients(const double * array, bool copyIn=true);
262 
264  inline void setObjSense(double value)
265  { objSense_ = value;}
266 
268  void setColType(const char *array, bool copyIn=true);
269 
271  void setMatrixByRow(const CoinPackedMatrix * matrix, bool copyIn=true);
272 
274  void createMatrixByRow();
275 
277  void setMatrixByCol(const CoinPackedMatrix * matrix, bool copyIn=true);
278 
280  void setOriginalMatrixByRow(const CoinPackedMatrix * matrix, bool copyIn=true);
281 
283  void setOriginalMatrixByCol(const CoinPackedMatrix * matrix, bool copyIn=true);
284 
286  void setColSolution(const double * array, bool copyIn=true);
287 
289  void setRowPrice(const double * array, bool copyIn=true);
290 
292  void setReducedCost(const double * array, bool copyIn=true);
293 
295  void setRowActivity(const double * array, bool copyIn=true);
296 
298  void setDoNotSeparateThis(const double * array, bool copyIn=true);
299 
301  inline void setInfinity(double value)
302  { infinity_ = value;}
303 
305  inline void setObjValue(double value)
306  { objValue_ = value;}
307 
309  inline void setObjOffset(double value)
310  { objOffset_ = value;}
311 
313  inline void setDualTolerance(double value)
314  { dualTolerance_ = value;}
315 
317  inline void setPrimalTolerance(double value)
318  { primalTolerance_ = value;}
319 
321  inline void setIntegerTolerance(double value)
322  { integerTolerance_ = value;}
323 
325  inline void setIntegerUpperBound(double value)
326  { integerUpperBound_ = value;}
327 
329  inline void setIntegerLowerBound(double value)
330  { integerLowerBound_ = value;}
332 
333  //---------------------------------------------------------------------------
334 
336 
337  CoinSnapshot();
339 
341  CoinSnapshot(const CoinSnapshot &);
342 
344  CoinSnapshot & operator=(const CoinSnapshot& rhs);
345 
347  virtual ~CoinSnapshot ();
348 
350 
351 private:
353 
354 
360  void gutsOfDestructor(int type);
362  void gutsOfCopy(const CoinSnapshot & rhs);
364 
366 
368  double objSense_;
369 
371  double infinity_;
372 
374  double objValue_;
375 
377  double objOffset_;
378 
381 
384 
387 
390 
393 
395  const double * colLower_;
396 
398  const double * colUpper_;
399 
401  const double * rowLower_;
402 
404  const double * rowUpper_;
405 
407  const double * rightHandSide_;
408 
410  const double * objCoefficients_;
411 
413  const char * colType_;
414 
417 
420 
423 
426 
428  const double * colSolution_;
429 
431  const double * rowPrice_;
432 
434  const double * reducedCost_;
435 
437  const double * rowActivity_;
438 
440  const double * doNotSeparateThis_;
441 
443  int numCols_;
444 
446  int numRows_;
447 
450 
453 
455  typedef struct {
456  unsigned int colLower:1;
457  unsigned int colUpper:1;
458  unsigned int rowLower:1;
459  unsigned int rowUpper:1;
460  unsigned int rightHandSide:1;
461  unsigned int objCoefficients:1;
462  unsigned int colType:1;
463  unsigned int matrixByRow:1;
464  unsigned int matrixByCol:1;
465  unsigned int originalMatrixByRow:1;
466  unsigned int originalMatrixByCol:1;
467  unsigned int colSolution:1;
468  unsigned int rowPrice:1;
469  unsigned int reducedCost:1;
470  unsigned int rowActivity:1;
471  unsigned int doNotSeparateThis:1;
472  } coinOwned;
475 };
476 #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.