Clp  1.17.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClpMatrixBase.hpp
Go to the documentation of this file.
1 /* $Id: ClpMatrixBase.hpp 2385 2019-01-06 19:43:06Z unxusr $ */
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 // Compilers can produce better code if they know about __restrict
17 #ifndef COIN_RESTRICT
18 #ifdef COIN_USE_RESTRICT
19 #define COIN_RESTRICT __restrict
20 #else
21 #define COIN_RESTRICT
22 #endif
23 #endif
24 
39 
40 public:
43  virtual CoinPackedMatrix *getPackedMatrix() const = 0;
46  virtual bool isColOrdered() const = 0;
48  virtual CoinBigIndex getNumElements() const = 0;
50  virtual int getNumCols() const = 0;
52  virtual int getNumRows() const = 0;
53 
58  virtual const double *getElements() const = 0;
64  virtual const int *getIndices() const = 0;
65 
66  virtual const CoinBigIndex *getVectorStarts() const = 0;
68  virtual const int *getVectorLengths() const = 0;
70  virtual int getVectorLength(int index) const;
72  virtual void deleteCols(const int numDel, const int *indDel) = 0;
74  virtual void deleteRows(const int numDel, const int *indDel) = 0;
75 #ifndef CLP_NO_VECTOR
76  virtual void appendCols(int number, const CoinPackedVectorBase *const *columns);
79  virtual void appendRows(int number, const CoinPackedVectorBase *const *rows);
80 #endif
81 
84  virtual void modifyCoefficient(int row, int column, double newElement,
85  bool keepZero = false);
90  virtual int appendMatrix(int number, int type,
91  const CoinBigIndex *starts, const int *index,
92  const double *element, int numberOther = -1);
93 
97  {
98  return NULL;
99  }
100 
102  virtual int countBasis(const int *whichColumn,
103  int &numberColumnBasic)
104  = 0;
106  virtual void fillBasis(ClpSimplex *model,
107  const int *whichColumn,
108  int &numberColumnBasic,
109  int *row, int *start,
110  int *rowCount, int *columnCount,
111  CoinFactorizationDouble *element)
112  = 0;
116  virtual int scale(ClpModel *, ClpSimplex * = NULL) const
117  {
118  return 1;
119  }
122  virtual void scaleRowCopy(ClpModel *) const {}
124  virtual bool canGetRowCopy() const
125  {
126  return true;
127  }
131  inline virtual ClpMatrixBase *scaledColumnCopy(ClpModel *) const
132  {
133  return this->clone();
134  }
135 
146  virtual bool allElementsInRange(ClpModel *,
147  double, double,
148  int = 15)
149  {
150  return true;
151  }
157  virtual void setDimensions(int numrows, int numcols);
161  virtual void rangeOfElements(double &smallestNegative, double &largestNegative,
162  double &smallestPositive, double &largestPositive);
163 
166  virtual void unpack(const ClpSimplex *model, CoinIndexedVector *rowArray,
167  int column) const = 0;
172  virtual void unpackPacked(ClpSimplex *model,
173  CoinIndexedVector *rowArray,
174  int column) const = 0;
179  virtual int refresh(ClpSimplex *)
180  {
181  return 0;
182  }
183 
184  // Really scale matrix
185  virtual void reallyScale(const double *rowScale, const double *columnScale);
191  virtual CoinBigIndex *dubiousWeights(const ClpSimplex *model, int *inputWeights) const;
194  virtual void add(const ClpSimplex *model, CoinIndexedVector *rowArray,
195  int column, double multiplier) const = 0;
197  virtual void add(const ClpSimplex *model, double *array,
198  int column, double multiplier) const = 0;
200  virtual void releasePackedMatrix() const = 0;
202  virtual bool canDoPartialPricing() const;
204  virtual int hiddenRows() const;
206  virtual void partialPricing(ClpSimplex *model, double start, double end,
207  int &bestSequence, int &numberWanted);
217  virtual int extendUpdated(ClpSimplex *model, CoinIndexedVector *update, int mode);
224  virtual void primalExpanded(ClpSimplex *model, int mode);
234  virtual void dualExpanded(ClpSimplex *model, CoinIndexedVector *array,
235  double *other, int mode);
255  virtual int generalExpanded(ClpSimplex *model, int mode, int &number);
259  virtual int updatePivot(ClpSimplex *model, double oldInValue, double oldOutValue);
263  virtual void createVariable(ClpSimplex *model, int &bestSequence);
266  virtual int checkFeasible(ClpSimplex *model, double &sum) const;
268  double reducedCost(ClpSimplex *model, int sequence) const;
270  virtual void correctSequence(const ClpSimplex *model, int &sequenceIn, int &sequenceOut);
272 
273  //---------------------------------------------------------------------------
281  virtual void times(double scalar,
282  const double *COIN_RESTRICT x, double *COIN_RESTRICT y) const = 0;
286  virtual void times(double scalar,
287  const double *COIN_RESTRICT x, double *COIN_RESTRICT y,
288  const double *COIN_RESTRICT rowScale,
289  const double *COIN_RESTRICT columnScale) const;
293  virtual void transposeTimes(double scalar,
294  const double *COIN_RESTRICT x, double *COIN_RESTRICT y) const = 0;
298  virtual void transposeTimes(double scalar,
299  const double *COIN_RESTRICT x, double *COIN_RESTRICT y,
300  const double *COIN_RESTRICT rowScale,
301  const double *COIN_RESTRICT columnScale,
302  double *COIN_RESTRICT spare = NULL) const;
303 #if COIN_LONG_WORK
304  // For long double versions (aborts if not supported)
305  virtual void times(CoinWorkDouble scalar,
307  virtual void transposeTimes(CoinWorkDouble scalar,
309 #endif
310 
314  virtual void transposeTimes(const ClpSimplex *model, double scalar,
315  const CoinIndexedVector *x,
317  CoinIndexedVector *z) const = 0;
322  virtual void subsetTransposeTimes(const ClpSimplex *model,
323  const CoinIndexedVector *x,
324  const CoinIndexedVector *y,
325  CoinIndexedVector *z) const = 0;
328  virtual bool canCombine(const ClpSimplex *,
329  const CoinIndexedVector *) const
330  {
331  return false;
332  }
337  virtual int transposeTimes2(const ClpSimplex *model,
338  const CoinIndexedVector *pi1, CoinIndexedVector *dj1,
339  const CoinIndexedVector *pi2,
340  CoinIndexedVector *spare,
341  double *infeas, double *reducedCost,
342  double referenceIn, double devex,
343  // Array for exact devex to say what is in reference framework
344  unsigned int *reference,
345  double *weights, double scaleFactor);
347  virtual void subsetTimes2(const ClpSimplex *model,
348  CoinIndexedVector *dj1,
349  const CoinIndexedVector *pi2, CoinIndexedVector *dj2,
350  double referenceIn, double devex,
351  // Array for exact devex to say what is in reference framework
352  unsigned int *reference,
353  double *weights, double scaleFactor);
358  virtual void listTransposeTimes(const ClpSimplex *model,
359  double *x,
360  int *y,
361  int number,
362  double *z) const;
364 
365  virtual ClpMatrixBase *clone() const = 0;
372  virtual ClpMatrixBase *subsetClone(
373  int numberRows, const int *whichRows,
374  int numberColumns, const int *whichColumns) const;
376  virtual void backToBasics() {}
383  inline int type() const
384  {
385  return type_;
386  }
388  void setType(int newtype)
389  {
390  type_ = newtype;
391  }
393  void useEffectiveRhs(ClpSimplex *model);
397  virtual double *rhsOffset(ClpSimplex *model, bool forceRefresh = false,
398  bool check = false);
400  inline int lastRefresh() const
401  {
402  return lastRefresh_;
403  }
405  inline int refreshFrequency() const
406  {
407  return refreshFrequency_;
408  }
409  inline void setRefreshFrequency(int value)
410  {
411  refreshFrequency_ = value;
412  }
414  inline bool skipDualCheck() const
415  {
416  return skipDualCheck_;
417  }
418  inline void setSkipDualCheck(bool yes)
419  {
420  skipDualCheck_ = yes;
421  }
424  inline int minimumObjectsScan() const
425  {
426  return minimumObjectsScan_;
427  }
428  inline void setMinimumObjectsScan(int value)
429  {
430  minimumObjectsScan_ = value;
431  }
433  inline int minimumGoodReducedCosts() const
434  {
436  }
437  inline void setMinimumGoodReducedCosts(int value)
438  {
439  minimumGoodReducedCosts_ = value;
440  }
442  inline double startFraction() const
443  {
444  return startFraction_;
445  }
446  inline void setStartFraction(double value)
447  {
448  startFraction_ = value;
449  }
451  inline double endFraction() const
452  {
453  return endFraction_;
454  }
455  inline void setEndFraction(double value)
456  {
457  endFraction_ = value;
458  }
460  inline double savedBestDj() const
461  {
462  return savedBestDj_;
463  }
464  inline void setSavedBestDj(double value)
465  {
466  savedBestDj_ = value;
467  }
469  inline int originalWanted() const
470  {
471  return originalWanted_;
472  }
473  inline void setOriginalWanted(int value)
474  {
475  originalWanted_ = value;
476  }
478  inline int currentWanted() const
479  {
480  return currentWanted_;
481  }
482  inline void setCurrentWanted(int value)
483  {
484  currentWanted_ = value;
485  }
487  inline int savedBestSequence() const
488  {
489  return savedBestSequence_;
490  }
491  inline void setSavedBestSequence(int value)
492  {
493  savedBestSequence_ = value;
494  }
496 
497 protected:
503  ClpMatrixBase();
505 public:
506  virtual ~ClpMatrixBase();
507 
508 protected:
509  // Copy
510  ClpMatrixBase(const ClpMatrixBase &);
511  // Assignment
514 
515 protected:
522  double *rhsOffset_;
526  double endFraction_;
528  double savedBestDj_;
536  int type_;
552 };
553 // bias for free variables
554 #define FREE_BIAS 1.0e1
555 // Acceptance criteria for free variables
556 #define FREE_ACCEPT 1.0e2
557 
558 #endif
559 
560 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
561 */
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 countBasis(const int *whichColumn, int &numberColumnBasic)=0
Returns number of elements in column part of basis.
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.
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.
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)
#define COIN_RESTRICT
int trueSequenceOut_
True sequence out (i.e. from larger problem)
Abstract base class for various sparse vectors.
virtual void transposeTimes(double scalar, const double *COIN_RESTRICT x, double *COIN_RESTRICT y) const =0
Return y + x * scalar * A in y.
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)
double CoinFactorizationDouble
Definition: CoinTypes.hpp:57
void setOriginalWanted(int value)
virtual int scale(ClpModel *, ClpSimplex *=NULL) const
Creates scales for column copy (rowCopy in model may be modified) default does not allow scaling retu...
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:106
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) ...
Indexed Vector.
double endFraction() const
Current end of search space in matrix (as fraction)
virtual int transposeTimes2(const ClpSimplex *model, const CoinIndexedVector *pi1, CoinIndexedVector *dj1, const CoinIndexedVector *pi2, CoinIndexedVector *spare, double *infeas, double *reducedCost, double referenceIn, double devex, unsigned int *reference, double *weights, double scaleFactor)
Updates two arrays for steepest and does devex weights (need not be coded) Returns nonzero if updates...
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 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 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 ...
Sparse Matrix Base Class.
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 &)
int CoinBigIndex
virtual ClpMatrixBase * clone() const =0
void setSavedBestDj(double value)
virtual void times(double scalar, const double *COIN_RESTRICT x, double *COIN_RESTRICT y) const =0
Return y + A * x * scalar 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
double CoinWorkDouble
Definition: CoinTypes.hpp:53
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)