Cbc  2.10.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CoinSnapshot.hpp
Go to the documentation of this file.
1 /* $Id: CoinSnapshot.hpp 2083 2019-01-06 19:38:09Z unxusr $ */
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  //---------------------------------------------------------------------------
34  inline int getNumCols() const
36  {
37  return numCols_;
38  }
39 
41  inline int getNumRows() const
42  {
43  return numRows_;
44  }
45 
47  inline int getNumElements() const
48  {
49  return numElements_;
50  }
51 
53  inline int getNumIntegers() const
54  {
55  return numIntegers_;
56  }
57 
59  inline const double *getColLower() const
60  {
61  return colLower_;
62  }
63 
65  inline const double *getColUpper() const
66  {
67  return colUpper_;
68  }
69 
71  inline const double *getRowLower() const
72  {
73  return rowLower_;
74  }
75 
77  inline const double *getRowUpper() const
78  {
79  return rowUpper_;
80  }
81 
89  inline const double *getRightHandSide() const
90  {
91  return rightHandSide_;
92  }
93 
95  inline const double *getObjCoefficients() const
96  {
97  return objCoefficients_;
98  }
99 
101  inline double getObjSense() const
102  {
103  return objSense_;
104  }
105 
107  inline bool isContinuous(int colIndex) const
108  {
109  return colType_[colIndex] == 'C';
110  }
111 
113  inline bool isBinary(int colIndex) const
114  {
115  return colType_[colIndex] == 'B';
116  }
117 
119  inline bool isInteger(int colIndex) const
120  {
121  return colType_[colIndex] == 'B' || colType_[colIndex] == 'I';
122  }
123 
125  inline bool isIntegerNonBinary(int colIndex) const
126  {
127  return colType_[colIndex] == 'I';
128  }
129 
131  inline bool isFreeBinary(int colIndex) const
132  {
133  return colType_[colIndex] == 'B' && colUpper_[colIndex] > colLower_[colIndex];
134  }
135 
137  inline const char *getColType() const
138  {
139  return colType_;
140  }
141 
143  inline const CoinPackedMatrix *getMatrixByRow() const
144  {
145  return matrixByRow_;
146  }
147 
149  inline const CoinPackedMatrix *getMatrixByCol() const
150  {
151  return matrixByCol_;
152  }
153 
156  {
157  return originalMatrixByRow_;
158  }
159 
162  {
163  return originalMatrixByCol_;
164  }
166 
169  inline const double *getColSolution() const
171  {
172  return colSolution_;
173  }
174 
176  inline const double *getRowPrice() const
177  {
178  return rowPrice_;
179  }
180 
182  inline const double *getReducedCost() const
183  {
184  return reducedCost_;
185  }
186 
188  inline const double *getRowActivity() const
189  {
190  return rowActivity_;
191  }
192 
194  inline const double *getDoNotSeparateThis() const
195  {
196  return doNotSeparateThis_;
197  }
199 
202  inline double getInfinity() const
204  {
205  return infinity_;
206  }
207 
210  inline double getObjValue() const
211  {
212  return objValue_;
213  }
214 
216  inline double getObjOffset() const
217  {
218  return objOffset_;
219  }
220 
222  inline double getDualTolerance() const
223  {
224  return dualTolerance_;
225  }
226 
228  inline double getPrimalTolerance() const
229  {
230  return primalTolerance_;
231  }
232 
234  inline double getIntegerTolerance() const
235  {
236  return integerTolerance_;
237  }
238 
240  inline double getIntegerUpperBound() const
241  {
242  return integerUpperBound_;
243  }
244 
246  inline double getIntegerLowerBound() const
247  {
248  return integerLowerBound_;
249  }
251 
252  //---------------------------------------------------------------------------
253 
268  void loadProblem(const CoinPackedMatrix &matrix,
269  const double *collb, const double *colub,
270  const double *obj,
271  const double *rowlb, const double *rowub,
272  bool makeRowCopy = false);
273 
275 
276  //---------------------------------------------------------------------------
277 
280  inline void setNumCols(int value)
282  {
283  numCols_ = value;
284  }
285 
287  inline void setNumRows(int value)
288  {
289  numRows_ = value;
290  }
291 
293  inline void setNumElements(int value)
294  {
295  numElements_ = value;
296  }
297 
299  inline void setNumIntegers(int value)
300  {
301  numIntegers_ = value;
302  }
303 
305  void setColLower(const double *array, bool copyIn = true);
306 
308  void setColUpper(const double *array, bool copyIn = true);
309 
311  void setRowLower(const double *array, bool copyIn = true);
312 
314  void setRowUpper(const double *array, bool copyIn = true);
315 
323  void setRightHandSide(const double *array, bool copyIn = true);
324 
333  void createRightHandSide();
334 
336  void setObjCoefficients(const double *array, bool copyIn = true);
337 
339  inline void setObjSense(double value)
340  {
341  objSense_ = value;
342  }
343 
345  void setColType(const char *array, bool copyIn = true);
346 
348  void setMatrixByRow(const CoinPackedMatrix *matrix, bool copyIn = true);
349 
351  void createMatrixByRow();
352 
354  void setMatrixByCol(const CoinPackedMatrix *matrix, bool copyIn = true);
355 
357  void setOriginalMatrixByRow(const CoinPackedMatrix *matrix, bool copyIn = true);
358 
360  void setOriginalMatrixByCol(const CoinPackedMatrix *matrix, bool copyIn = true);
361 
363  void setColSolution(const double *array, bool copyIn = true);
364 
366  void setRowPrice(const double *array, bool copyIn = true);
367 
369  void setReducedCost(const double *array, bool copyIn = true);
370 
372  void setRowActivity(const double *array, bool copyIn = true);
373 
375  void setDoNotSeparateThis(const double *array, bool copyIn = true);
376 
378  inline void setInfinity(double value)
379  {
380  infinity_ = value;
381  }
382 
384  inline void setObjValue(double value)
385  {
386  objValue_ = value;
387  }
388 
390  inline void setObjOffset(double value)
391  {
392  objOffset_ = value;
393  }
394 
396  inline void setDualTolerance(double value)
397  {
398  dualTolerance_ = value;
399  }
400 
402  inline void setPrimalTolerance(double value)
403  {
404  primalTolerance_ = value;
405  }
406 
408  inline void setIntegerTolerance(double value)
409  {
410  integerTolerance_ = value;
411  }
412 
414  inline void setIntegerUpperBound(double value)
415  {
416  integerUpperBound_ = value;
417  }
418 
420  inline void setIntegerLowerBound(double value)
421  {
422  integerLowerBound_ = value;
423  }
425 
426  //---------------------------------------------------------------------------
427 
429 
430  CoinSnapshot();
432 
434  CoinSnapshot(const CoinSnapshot &);
435 
437  CoinSnapshot &operator=(const CoinSnapshot &rhs);
438 
440  virtual ~CoinSnapshot();
441 
443 
444 private:
446 
447 
453  void gutsOfDestructor(int type);
455  void gutsOfCopy(const CoinSnapshot &rhs);
457 
459 
461  double objSense_;
462 
464  double infinity_;
465 
467  double objValue_;
468 
470  double objOffset_;
471 
474 
477 
480 
483 
486 
488  const double *colLower_;
489 
491  const double *colUpper_;
492 
494  const double *rowLower_;
495 
497  const double *rowUpper_;
498 
500  const double *rightHandSide_;
501 
503  const double *objCoefficients_;
504 
506  const char *colType_;
507 
510 
513 
516 
519 
521  const double *colSolution_;
522 
524  const double *rowPrice_;
525 
527  const double *reducedCost_;
528 
530  const double *rowActivity_;
531 
533  const double *doNotSeparateThis_;
534 
536  int numCols_;
537 
539  int numRows_;
540 
543 
546 
548  typedef struct {
549  unsigned int colLower : 1;
550  unsigned int colUpper : 1;
551  unsigned int rowLower : 1;
552  unsigned int rowUpper : 1;
553  unsigned int rightHandSide : 1;
554  unsigned int objCoefficients : 1;
555  unsigned int colType : 1;
556  unsigned int matrixByRow : 1;
557  unsigned int matrixByCol : 1;
558  unsigned int originalMatrixByRow : 1;
559  unsigned int originalMatrixByCol : 1;
560  unsigned int colSolution : 1;
561  unsigned int rowPrice : 1;
562  unsigned int reducedCost : 1;
563  unsigned int rowActivity : 1;
564  unsigned int doNotSeparateThis : 1;
565  } coinOwned;
568 };
569 #endif
570 
571 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
572 */
CoinSnapshot & operator=(const CoinSnapshot &rhs)
Assignment operator.
const char * getColType() const
Get colType array ('B', 'I', or 'C' for Binary, Integer and Continuous)
const double * rowLower_
pointer to array[getNumRows()] of row lower bounds
void setColSolution(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of primal variable values.
int getNumElements() const
Get number of nonzero elements.
void setNumIntegers(int value)
Set number of integer variables.
const double * getObjCoefficients() const
Get pointer to array[getNumCols()] of objective function coefficients.
double getPrimalTolerance() const
Get primal tolerance.
double getObjValue() const
Get objective function value - includinbg any offset i.e.
void setRowLower(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of row lower bounds.
void createRightHandSide()
Create array[getNumRows()] of row right-hand sides using existing information This gives same results...
double getDualTolerance() const
Get dual tolerance.
void gutsOfCopy(const CoinSnapshot &rhs)
Does main work of copy.
void setDualTolerance(double value)
Set dual tolerance.
const CoinPackedMatrix * matrixByRow_
pointer to row-wise copy of current matrix
NON Abstract Base Class for interfacing with cut generators or branching code or .
const double * getDoNotSeparateThis() const
Get pointer to array[getNumCols()] of primal variable values which should not be separated (for debug...
double getObjOffset() const
Get objective offset i.e. sum c sub j * x subj -objValue = objOffset.
void setColLower(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of column lower bounds.
int getNumCols() const
Get number of columns.
bool isContinuous(int colIndex) const
Return true if variable is continuous.
double getIntegerLowerBound() const
Get integer lower bound i.e. best possible solution * getObjSense.
void setNumRows(int value)
Set number of rows.
const double * getColSolution() const
Get pointer to array[getNumCols()] of primal variable values.
const CoinPackedMatrix * matrixByCol_
pointer to column-wise copy of current matrix
const double * colSolution_
pointer to array[getNumCols()] of primal variable values
void createMatrixByRow()
Create row-wise copy from MatrixByCol.
double getInfinity() const
Get solver's value for infinity.
const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
double objOffset_
objective offset i.e. sum c sub j * x subj -objValue = objOffset
const CoinPackedMatrix * originalMatrixByRow_
pointer to row-wise copy of "original" matrix
int getNumIntegers() const
Get number of integer variables.
void setObjOffset(double value)
Set objective offset i.e. sum c sub j * x subj -objValue = objOffset.
const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
CoinSnapshot()
Default Constructor.
void setObjSense(double value)
Set objective function sense (1 for min (default), -1 for max)
const double * rowUpper_
pointer to array[getNumRows()] of row upper bounds
bool isFreeBinary(int colIndex) const
Return true if variable is binary and not fixed at either bound.
double integerUpperBound_
integer upper bound i.e. best solution * getObjSense
void gutsOfDestructor(int type)
Does main work of destructor - type (or'ed) 1 - NULLify pointers 2 - delete pointers 4 - initialize s...
const char * colType_
colType array ('B', 'I', or 'C' for Binary, Integer and Continuous)
void setDoNotSeparateThis(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of primal variable values which should not be separated (for debug...
double primalTolerance_
primal tolerance
void setRowActivity(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
double objSense_
objective function sense (1 for min (default), -1 for max)
int numIntegers_
number of integer variables
double objValue_
objective function value (including any rhs offset)
const CoinPackedMatrix * getMatrixByRow() const
Get pointer to row-wise copy of current matrix.
double getObjSense() const
Get objective function sense (1 for min (default), -1 for max)
bool isBinary(int colIndex) const
Return true if variable is binary.
void setOriginalMatrixByCol(const CoinPackedMatrix *matrix, bool copyIn=true)
Set pointer to column-wise copy of "original" matrix.
const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
void setIntegerTolerance(double value)
Set integer tolerance.
void setNumCols(int value)
Set number of columns.
void setIntegerUpperBound(double value)
Set integer upper bound i.e. best solution * getObjSense.
void setColUpper(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of column upper bounds.
const CoinPackedMatrix * getOriginalMatrixByCol() const
Get pointer to column-wise copy of "original" matrix.
int numCols_
number of columns
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...
void setIntegerLowerBound(double value)
Set integer lower bound i.e. best possible solution * getObjSense.
const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
const double * rightHandSide_
pointer to array[getNumRows()] of rhs side values
void setRightHandSide(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of row right-hand sides This gives same results as OsiSolverInterf...
Sparse Matrix Base Class.
To say whether arrays etc are owned by CoinSnapshot.
int getNumRows() const
Get number of rows.
const CoinPackedMatrix * originalMatrixByCol_
pointer to column-wise copy of "original" matrix
const double * doNotSeparateThis_
pointer to array[getNumCols()] of primal variable values which should not be separated (for debug) ...
void setReducedCost(const double *array, bool copyIn=true)
Set a pointer to array[getNumCols()] of reduced costs.
const double * colUpper_
pointer to array[getNumCols()] of column upper bounds
double infinity_
solver's value for infinity
void setInfinity(double value)
Set solver's value for infinity.
const double * rowPrice_
pointer to array[getNumRows()] of dual variable values
double getIntegerTolerance() const
Get integer tolerance.
double getIntegerUpperBound() const
Get integer upper bound i.e. best solution * getObjSense.
void setMatrixByRow(const CoinPackedMatrix *matrix, bool copyIn=true)
Set pointer to row-wise copy of current matrix.
const double * objCoefficients_
pointer to array[getNumCols()] of objective function coefficients
void setColType(const char *array, bool copyIn=true)
Set 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...
const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual variable values.
int numElements_
number of nonzero elements
const CoinPackedMatrix * getOriginalMatrixByRow() const
Get pointer to row-wise copy of "original" matrix.
void setMatrixByCol(const CoinPackedMatrix *matrix, bool copyIn=true)
Set pointer to column-wise copy of current matrix.
virtual ~CoinSnapshot()
Destructor.
const CoinPackedMatrix * getMatrixByCol() const
Get pointer to column-wise copy of current matrix.
bool isInteger(int colIndex) const
Return true if column is integer.
const double * reducedCost_
a pointer to array[getNumCols()] of reduced costs
void setObjValue(double value)
Set objective function value (including any rhs offset)
double integerTolerance_
integer tolerance
void setOriginalMatrixByRow(const CoinPackedMatrix *matrix, bool copyIn=true)
Set pointer to row-wise copy of "original" matrix.
bool isIntegerNonBinary(int colIndex) const
Return true if variable is general integer.
const double * rowActivity_
pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vector)...
void setRowUpper(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of row upper bounds.
double dualTolerance_
dual tolerance
void setNumElements(int value)
Set number of nonzero elements.
const double * colLower_
pointer to array[getNumCols()] of column lower bounds
void setObjCoefficients(const double *array, bool copyIn=true)
Set pointer to array[getNumCols()] of objective function coefficients.
void setPrimalTolerance(double value)
Set primal tolerance.
coinOwned owned_
void setRowPrice(const double *array, bool copyIn=true)
Set pointer to array[getNumRows()] of dual variable values.
int numRows_
number of rows
double integerLowerBound_
integer lower bound i.e. best possible solution * getObjSense
const double * getRightHandSide() const
Get pointer to array[getNumRows()] of row right-hand sides This gives same results as OsiSolverInterf...
const double * getReducedCost() const
Get a pointer to array[getNumCols()] of reduced costs.