Clp  1.15.10
ClpMatrixBase.hpp
Go to the documentation of this file.
1 /* $Id: ClpMatrixBase.hpp 1722 2011-04-17 09:58:37Z stefan $ */
2 // Copyright (C) 2002, 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 ClpMatrixBase_H
7 #define ClpMatrixBase_H
8 
9 #include "CoinPragma.hpp"
10 #include "CoinTypes.hpp"
11 
12 #include "CoinPackedMatrix.hpp"
13 class CoinIndexedVector;
14 class ClpSimplex;
15 class ClpModel;
16 
31 
32 public:
35  virtual CoinPackedMatrix * getPackedMatrix() const = 0;
38  virtual bool isColOrdered() const = 0;
40  virtual CoinBigIndex getNumElements() const = 0;
42  virtual int getNumCols() const = 0;
44  virtual int getNumRows() const = 0;
45 
50  virtual const double * getElements() const = 0;
56  virtual const int * getIndices() const = 0;
57 
58  virtual const CoinBigIndex * getVectorStarts() const = 0;
60  virtual const int * getVectorLengths() const = 0 ;
62  virtual int getVectorLength(int index) const ;
64  virtual void deleteCols(const int numDel, const int * indDel) = 0;
66  virtual void deleteRows(const int numDel, const int * indDel) = 0;
67 #ifndef CLP_NO_VECTOR
68  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
71  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
72 #endif
73 
76  virtual void modifyCoefficient(int row, int column, double newElement,
77  bool keepZero = false);
82  virtual int appendMatrix(int number, int type,
83  const CoinBigIndex * starts, const int * index,
84  const double * element, int numberOther = -1);
85 
88  virtual ClpMatrixBase * reverseOrderedCopy() const {
89  return NULL;
90  }
91 
93  virtual CoinBigIndex countBasis(const int * whichColumn,
94  int & numberColumnBasic) = 0;
96  virtual void fillBasis(ClpSimplex * model,
97  const int * whichColumn,
98  int & numberColumnBasic,
99  int * row, int * start,
100  int * rowCount, int * columnCount,
101  CoinFactorizationDouble * element) = 0;
105  virtual int scale(ClpModel * , const ClpSimplex * = NULL) const {
106  return 1;
107  }
110  virtual void scaleRowCopy(ClpModel * ) const { }
112  virtual bool canGetRowCopy() const {
113  return true;
114  }
118  inline virtual ClpMatrixBase * scaledColumnCopy(ClpModel * ) const {
119  return this->clone();
120  }
121 
132  virtual bool allElementsInRange(ClpModel * ,
133  double , double ,
134  int = 15) {
135  return true;
136  }
142  virtual void setDimensions(int numrows, int numcols);
146  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
147  double & smallestPositive, double & largestPositive);
148 
151  virtual void unpack(const ClpSimplex * model, CoinIndexedVector * rowArray,
152  int column) const = 0;
157  virtual void unpackPacked(ClpSimplex * model,
158  CoinIndexedVector * rowArray,
159  int column) const = 0;
164  virtual int refresh(ClpSimplex * ) {
165  return 0;
166  }
167 
168  // Really scale matrix
169  virtual void reallyScale(const double * rowScale, const double * columnScale);
175  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model, int * inputWeights) const;
178  virtual void add(const ClpSimplex * model, CoinIndexedVector * rowArray,
179  int column, double multiplier) const = 0;
181  virtual void add(const ClpSimplex * model, double * array,
182  int column, double multiplier) const = 0;
184  virtual void releasePackedMatrix() const = 0;
186  virtual bool canDoPartialPricing() const;
188  virtual int hiddenRows() const;
190  virtual void partialPricing(ClpSimplex * model, double start, double end,
191  int & bestSequence, int & numberWanted);
201  virtual int extendUpdated(ClpSimplex * model, CoinIndexedVector * update, int mode);
208  virtual void primalExpanded(ClpSimplex * model, int mode);
218  virtual void dualExpanded(ClpSimplex * model, CoinIndexedVector * array,
219  double * other, int mode);
239  virtual int generalExpanded(ClpSimplex * model, int mode, int & number);
243  virtual int updatePivot(ClpSimplex * model, double oldInValue, double oldOutValue);
247  virtual void createVariable(ClpSimplex * model, int & bestSequence);
250  virtual int checkFeasible(ClpSimplex * model, double & sum) const ;
252  double reducedCost(ClpSimplex * model, int sequence) const;
254  virtual void correctSequence(const ClpSimplex * model, int & sequenceIn, int & sequenceOut) ;
256 
257  //---------------------------------------------------------------------------
265  virtual void times(double scalar,
266  const double * x, double * y) const = 0;
270  virtual void times(double scalar,
271  const double * x, double * y,
272  const double * rowScale,
273  const double * columnScale) const;
277  virtual void transposeTimes(double scalar,
278  const double * x, double * y) const = 0;
282  virtual void transposeTimes(double scalar,
283  const double * x, double * y,
284  const double * rowScale,
285  const double * columnScale,
286  double * spare = NULL) const;
287 #if COIN_LONG_WORK
288  // For long double versions (aborts if not supported)
289  virtual void times(CoinWorkDouble scalar,
290  const CoinWorkDouble * x, CoinWorkDouble * y) const ;
291  virtual void transposeTimes(CoinWorkDouble scalar,
292  const CoinWorkDouble * x, CoinWorkDouble * y) const ;
293 #endif
294 
298  virtual void transposeTimes(const ClpSimplex * model, double scalar,
299  const CoinIndexedVector * x,
300  CoinIndexedVector * y,
301  CoinIndexedVector * z) const = 0;
306  virtual void subsetTransposeTimes(const ClpSimplex * model,
307  const CoinIndexedVector * x,
308  const CoinIndexedVector * y,
309  CoinIndexedVector * z) const = 0;
312  virtual bool canCombine(const ClpSimplex * ,
313  const CoinIndexedVector * ) const {
314  return false;
315  }
317  virtual void transposeTimes2(const ClpSimplex * model,
318  const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
319  const CoinIndexedVector * pi2,
320  CoinIndexedVector * spare,
321  double referenceIn, double devex,
322  // Array for exact devex to say what is in reference framework
323  unsigned int * reference,
324  double * weights, double scaleFactor);
326  virtual void subsetTimes2(const ClpSimplex * model,
327  CoinIndexedVector * dj1,
328  const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
329  double referenceIn, double devex,
330  // Array for exact devex to say what is in reference framework
331  unsigned int * reference,
332  double * weights, double scaleFactor);
337  virtual void listTransposeTimes(const ClpSimplex * model,
338  double * x,
339  int * y,
340  int number,
341  double * z) const;
343 
344  virtual ClpMatrixBase * clone() const = 0;
351  virtual ClpMatrixBase * subsetClone (
352  int numberRows, const int * whichRows,
353  int numberColumns, const int * whichColumns) const;
355  virtual void backToBasics() {}
362  inline int type() const {
363  return type_;
364  }
366  void setType(int newtype) {
367  type_ = newtype;
368  }
370  void useEffectiveRhs(ClpSimplex * model);
374  virtual double * rhsOffset(ClpSimplex * model, bool forceRefresh = false,
375  bool check = false);
377  inline int lastRefresh() const {
378  return lastRefresh_;
379  }
381  inline int refreshFrequency() const {
382  return refreshFrequency_;
383  }
384  inline void setRefreshFrequency(int value) {
385  refreshFrequency_ = value;
386  }
388  inline bool skipDualCheck() const {
389  return skipDualCheck_;
390  }
391  inline void setSkipDualCheck(bool yes) {
392  skipDualCheck_ = yes;
393  }
396  inline int minimumObjectsScan() const {
397  return minimumObjectsScan_;
398  }
399  inline void setMinimumObjectsScan(int value) {
400  minimumObjectsScan_ = value;
401  }
403  inline int minimumGoodReducedCosts() const {
405  }
406  inline void setMinimumGoodReducedCosts(int value) {
407  minimumGoodReducedCosts_ = value;
408  }
410  inline double startFraction() const {
411  return startFraction_;
412  }
413  inline void setStartFraction(double value) {
414  startFraction_ = value;
415  }
417  inline double endFraction() const {
418  return endFraction_;
419  }
420  inline void setEndFraction(double value) {
421  endFraction_ = value;
422  }
424  inline double savedBestDj() const {
425  return savedBestDj_;
426  }
427  inline void setSavedBestDj(double value) {
428  savedBestDj_ = value;
429  }
431  inline int originalWanted() const {
432  return originalWanted_;
433  }
434  inline void setOriginalWanted(int value) {
435  originalWanted_ = value;
436  }
438  inline int currentWanted() const {
439  return currentWanted_;
440  }
441  inline void setCurrentWanted(int value) {
442  currentWanted_ = value;
443  }
445  inline int savedBestSequence() const {
446  return savedBestSequence_;
447  }
448  inline void setSavedBestSequence(int value) {
449  savedBestSequence_ = value;
450  }
452 
453 
454 protected:
455 
461  ClpMatrixBase();
463 public:
464  virtual ~ClpMatrixBase();
465 protected:
466  // Copy
468  // Assignment
471 
472 
473 protected:
480  double * rhsOffset_;
484  double endFraction_;
486  double savedBestDj_;
494  int type_;
510 };
511 // bias for free variables
512 #define FREE_BIAS 1.0e1
513 // Acceptance criteria for free variables
514 #define FREE_ACCEPT 1.0e2
515 
516 #endif
virtual const double * getElements() const =0
A vector containing the elements in the packed matrix.
virtual void appendRows(int number, const CoinPackedVectorBase *const *rows)
Append Rows.
void setCurrentWanted(int value)
virtual bool canCombine(const ClpSimplex *, const CoinIndexedVector *) const
Returns true if can combine transposeTimes and subsetTransposeTimes and if it would be faster...
int type() const
Returns type.
virtual const CoinBigIndex * getVectorStarts() const =0
int refreshFrequency() const
If rhsOffset used this is refresh frequency (0==off)
virtual void rangeOfElements(double &smallestNegative, double &largestNegative, double &smallestPositive, double &largestPositive)
Returns largest and smallest elements of both signs.
double startFraction() const
Current start of search space in matrix (as fraction)
virtual int getNumRows() const =0
Number of rows.
virtual bool isColOrdered() const =0
Whether the packed matrix is column major ordered or not.
Abstract base class for Clp Matrices.
virtual bool canDoPartialPricing() const
Says whether it can do partial pricing.
virtual void deleteRows(const int numDel, const int *indDel)=0
Delete the rows whose indices are listed in indDel.
virtual void dualExpanded(ClpSimplex *model, CoinIndexedVector *array, double *other, int mode)
utility dual function for dealing with dynamic constraints mode=0 - Set up before "updateTranspose" a...
virtual void appendCols(int number, const CoinPackedVectorBase *const *columns)
Append Columns.
virtual int getNumCols() const =0
Number of columns.
virtual CoinBigIndex countBasis(const int *whichColumn, int &numberColumnBasic)=0
Returns number of elements in column part of basis.
void setRefreshFrequency(int value)
double savedBestDj() const
Current best reduced cost.
double * rhsOffset_
Effective RHS offset if it is being used.
int lastRefresh() const
If rhsOffset used this is iteration last refreshed.
virtual int generalExpanded(ClpSimplex *model, int mode, int &number)
general utility function for dealing with dynamic constraints mode=0 - Create list of non-key basics ...
double reducedCost(ClpSimplex *model, int sequence) const
Returns reduced cost of a variable.
void setSavedBestSequence(int value)
virtual bool canGetRowCopy() const
Returns true if can create row copy.
int savedBestSequence_
Saved best sequence in pricing.
virtual void fillBasis(ClpSimplex *model, const int *whichColumn, int &numberColumnBasic, int *row, int *start, int *rowCount, int *columnCount, CoinFactorizationDouble *element)=0
Fills in column part of basis.
int minimumGoodReducedCosts() const
Partial pricing tuning parameter - minimum number of negative reduced costs to get.
virtual void transposeTimes2(const ClpSimplex *model, const CoinIndexedVector *pi1, CoinIndexedVector *dj1, const CoinIndexedVector *pi2, CoinIndexedVector *spare, double referenceIn, double devex, unsigned int *reference, double *weights, double scaleFactor)
Updates two arrays for steepest and does devex weights (need not be coded)
int currentWanted_
Current number of negative reduced costs which we still need.
int savedBestSequence() const
Current best sequence.
virtual ~ClpMatrixBase()
Destructor (has to be public)
virtual void add(const ClpSimplex *model, CoinIndexedVector *rowArray, int column, double multiplier) const =0
Adds multiple of a column into an CoinIndexedvector You can use quickAdd to add to vector...
virtual CoinPackedMatrix * getPackedMatrix() const =0
Return a complete CoinPackedMatrix.
virtual void unpack(const ClpSimplex *model, CoinIndexedVector *rowArray, int column) const =0
Unpacks a column into an CoinIndexedvector.
virtual void subsetTimes2(const ClpSimplex *model, CoinIndexedVector *dj1, const CoinIndexedVector *pi2, CoinIndexedVector *dj2, double referenceIn, double devex, unsigned int *reference, double *weights, double scaleFactor)
Updates second array for steepest and does devex weights (need not be coded)
int trueSequenceOut_
True sequence out (i.e. from larger problem)
int originalWanted() const
Initial number of negative reduced costs wanted.
int currentWanted() const
Current number of negative reduced costs which we still need.
void setMinimumObjectsScan(int value)
void setOriginalWanted(int value)
virtual bool allElementsInRange(ClpModel *, double, double, int=15)
Checks if all elements are in valid range.
virtual int hiddenRows() const
Returns number of hidden rows e.g. gub.
virtual void unpackPacked(ClpSimplex *model, CoinIndexedVector *rowArray, int column) const =0
Unpacks a column into an CoinIndexedvector in packed format Note that model is NOT const...
void setType(int newtype)
Sets type.
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:55
virtual void correctSequence(const ClpSimplex *model, int &sequenceIn, int &sequenceOut)
Correct sequence in and out to give true value (if both -1 maybe do whole matrix) ...
double endFraction() const
Current end of search space in matrix (as fraction)
void setStartFraction(double value)
void useEffectiveRhs(ClpSimplex *model)
Sets up an effective RHS.
virtual void subsetTransposeTimes(const ClpSimplex *model, const CoinIndexedVector *x, const CoinIndexedVector *y, CoinIndexedVector *z) const =0
Return x *A in z but just for indices in y.
virtual int refresh(ClpSimplex *)
Purely for column generation and similar ideas.
virtual void setDimensions(int numrows, int numcols)
Set the dimensions of the matrix.
ClpMatrixBase()
Default constructor.
int refreshFrequency_
If rhsOffset used this is refresh frequency (0==off)
virtual void reallyScale(const double *rowScale, const double *columnScale)
virtual void listTransposeTimes(const ClpSimplex *model, double *x, int *y, int number, double *z) const
Return x *A in z but just for number indices in y.
virtual int scale(ClpModel *, const ClpSimplex *=NULL) const
Creates scales for column copy (rowCopy in model may be modified) default does not allow scaling retu...
virtual void scaleRowCopy(ClpModel *) const
Scales rowCopy if column copy scaled Only called if scales already exist.
int lastRefresh_
If rhsOffset used this is iteration last refreshed.
virtual int appendMatrix(int number, int type, const CoinBigIndex *starts, const int *index, const double *element, int numberOther=-1)
Append a set of rows/columns to the end of the matrix.
virtual void times(double scalar, const double *x, double *y) const =0
Return y + A * x * scalar in y.
virtual CoinBigIndex getNumElements() const =0
Number of entries in the packed matrix.
bool skipDualCheck_
whether to skip dual checks most of time
virtual double * rhsOffset(ClpSimplex *model, bool forceRefresh=false, bool check=false)
Returns effective RHS offset if it is being used.
virtual ClpMatrixBase * reverseOrderedCopy() const
Returns a new matrix in reverse order without gaps Is allowed to return NULL if doesn't want to have ...
virtual CoinBigIndex * dubiousWeights(const ClpSimplex *model, int *inputWeights) const
Given positive integer weights for each row fills in sum of weights for each column (and slack)...
ClpMatrixBase & operator=(const ClpMatrixBase &)
virtual ClpMatrixBase * clone() const =0
void setSavedBestDj(double value)
virtual void transposeTimes(double scalar, const double *x, double *y) const =0
Return y + x * scalar * A in y.
int minimumObjectsScan_
Partial pricing tuning parameter - minimum number of "objects" to scan.
virtual const int * getIndices() const =0
A vector containing the minor indices of the elements in the packed matrix.
virtual void backToBasics()
Gets rid of any mutable by products.
virtual int getVectorLength(int index) const
The length of a single major-dimension vector.
int originalWanted_
Initial number of negative reduced costs wanted.
bool skipDualCheck() const
whether to skip dual checks most of time
virtual ClpMatrixBase * subsetClone(int numberRows, const int *whichRows, int numberColumns, const int *whichColumns) const
Subset clone (without gaps).
int trueSequenceIn_
True sequence in (i.e. from larger problem)
virtual const int * getVectorLengths() const =0
The lengths of the major-dimension vectors.
virtual int checkFeasible(ClpSimplex *model, double &sum) const
Just for debug if odd type matrix.
int type_
type (may be useful)
double startFraction_
Current start of search space in matrix (as fraction)
virtual void releasePackedMatrix() const =0
Allow any parts of a created CoinPackedMatrix to be deleted.
virtual void primalExpanded(ClpSimplex *model, int mode)
utility primal function for dealing with dynamic constraints mode=0 - Set up before "update" and "tim...
virtual int updatePivot(ClpSimplex *model, double oldInValue, double oldOutValue)
update information for a pivot (and effective rhs)
int minimumObjectsScan() const
Partial pricing tuning parameter - minimum number of "objects" to scan.
void setSkipDualCheck(bool yes)
virtual void partialPricing(ClpSimplex *model, double start, double end, int &bestSequence, int &numberWanted)
Partial pricing.
virtual int extendUpdated(ClpSimplex *model, CoinIndexedVector *update, int mode)
expands an updated column to allow for extra rows which the main solver does not know about and retur...
virtual ClpMatrixBase * scaledColumnCopy(ClpModel *) const
Realy really scales column copy Only called if scales already exist.
virtual void createVariable(ClpSimplex *model, int &bestSequence)
Creates a variable.
virtual void modifyCoefficient(int row, int column, double newElement, bool keepZero=false)
Modify one element of packed matrix.
virtual void deleteCols(const int numDel, const int *indDel)=0
Delete the columns whose indices are listed in indDel.
int minimumGoodReducedCosts_
Partial pricing tuning parameter - minimum number of negative reduced costs to get.
void setEndFraction(double value)
double endFraction_
Current end of search space in matrix (as fraction)
double savedBestDj_
Best reduced cost so far.
void setMinimumGoodReducedCosts(int value)