ClpMatrixBase.hpp
Go to the documentation of this file.
1 /* $Id: ClpMatrixBase.hpp 1525 2010-02-26 17:27:59Z mjs $ */
2 // Copyright (C) 2002, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 #ifndef ClpMatrixBase_H
5 #define ClpMatrixBase_H
6 
7 #include "CoinPragma.hpp"
8 #include "CoinFinite.hpp"
9 
10 #include "CoinPackedMatrix.hpp"
11 class CoinIndexedVector;
12 class ClpSimplex;
13 class ClpModel;
14 
29 
30 public:
33  virtual CoinPackedMatrix * getPackedMatrix() const = 0;
36  virtual bool isColOrdered() const = 0;
38  virtual CoinBigIndex getNumElements() const = 0;
40  virtual int getNumCols() const = 0;
42  virtual int getNumRows() const = 0;
43 
48  virtual const double * getElements() const = 0;
54  virtual const int * getIndices() const = 0;
55 
56  virtual const CoinBigIndex * getVectorStarts() const = 0;
58  virtual const int * getVectorLengths() const = 0 ;
60  virtual int getVectorLength(int index) const ;
62  virtual void deleteCols(const int numDel, const int * indDel) = 0;
64  virtual void deleteRows(const int numDel, const int * indDel) = 0;
65 #ifndef CLP_NO_VECTOR
66  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
69  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
70 #endif
71 
74  virtual void modifyCoefficient(int row, int column, double newElement,
75  bool keepZero = false);
80  virtual int appendMatrix(int number, int type,
81  const CoinBigIndex * starts, const int * index,
82  const double * element, int numberOther = -1);
83 
86  virtual ClpMatrixBase * reverseOrderedCopy() const {
87  return NULL;
88  }
89 
91  virtual CoinBigIndex countBasis(const int * whichColumn,
92  int & numberColumnBasic) = 0;
94  virtual void fillBasis(ClpSimplex * model,
95  const int * whichColumn,
96  int & numberColumnBasic,
97  int * row, int * start,
98  int * rowCount, int * columnCount,
99  CoinFactorizationDouble * element) = 0;
103  virtual int scale(ClpModel * , const ClpSimplex * = NULL) const {
104  return 1;
105  }
108  virtual void scaleRowCopy(ClpModel * ) const { }
110  virtual bool canGetRowCopy() const {
111  return true;
112  }
116  inline virtual ClpMatrixBase * scaledColumnCopy(ClpModel * ) const {
117  return this->clone();
118  }
119 
130  virtual bool allElementsInRange(ClpModel * ,
131  double , double ,
132  int = 15) {
133  return true;
134  }
140  virtual void setDimensions(int numrows, int numcols);
144  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
145  double & smallestPositive, double & largestPositive);
146 
149  virtual void unpack(const ClpSimplex * model, CoinIndexedVector * rowArray,
150  int column) const = 0;
155  virtual void unpackPacked(ClpSimplex * model,
156  CoinIndexedVector * rowArray,
157  int column) const = 0;
162  virtual int refresh(ClpSimplex * ) {
163  return 0;
164  }
165 
166  // Really scale matrix
167  virtual void reallyScale(const double * rowScale, const double * columnScale);
173  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model, int * inputWeights) const;
176  virtual void add(const ClpSimplex * model, CoinIndexedVector * rowArray,
177  int column, double multiplier) const = 0;
179  virtual void add(const ClpSimplex * model, double * array,
180  int column, double multiplier) const = 0;
182  virtual void releasePackedMatrix() const = 0;
184  virtual bool canDoPartialPricing() const;
186  virtual int hiddenRows() const;
188  virtual void partialPricing(ClpSimplex * model, double start, double end,
189  int & bestSequence, int & numberWanted);
199  virtual int extendUpdated(ClpSimplex * model, CoinIndexedVector * update, int mode);
206  virtual void primalExpanded(ClpSimplex * model, int mode);
216  virtual void dualExpanded(ClpSimplex * model, CoinIndexedVector * array,
217  double * other, int mode);
237  virtual int generalExpanded(ClpSimplex * model, int mode, int & number);
241  virtual int updatePivot(ClpSimplex * model, double oldInValue, double oldOutValue);
245  virtual void createVariable(ClpSimplex * model, int & bestSequence);
248  virtual int checkFeasible(ClpSimplex * model, double & sum) const ;
250  double reducedCost(ClpSimplex * model, int sequence) const;
252  virtual void correctSequence(const ClpSimplex * model, int & sequenceIn, int & sequenceOut) ;
254 
255  //---------------------------------------------------------------------------
263  virtual void times(double scalar,
264  const double * x, double * y) const = 0;
268  virtual void times(double scalar,
269  const double * x, double * y,
270  const double * rowScale,
271  const double * columnScale) const;
275  virtual void transposeTimes(double scalar,
276  const double * x, double * y) const = 0;
280  virtual void transposeTimes(double scalar,
281  const double * x, double * y,
282  const double * rowScale,
283  const double * columnScale,
284  double * spare = NULL) const;
285 #if COIN_LONG_WORK
286  // For long double versions (aborts if not supported)
287  virtual void times(CoinWorkDouble scalar,
288  const CoinWorkDouble * x, CoinWorkDouble * y) const ;
289  virtual void transposeTimes(CoinWorkDouble scalar,
290  const CoinWorkDouble * x, CoinWorkDouble * y) const ;
291 #endif
292 
296  virtual void transposeTimes(const ClpSimplex * model, double scalar,
297  const CoinIndexedVector * x,
298  CoinIndexedVector * y,
299  CoinIndexedVector * z) const = 0;
304  virtual void subsetTransposeTimes(const ClpSimplex * model,
305  const CoinIndexedVector * x,
306  const CoinIndexedVector * y,
307  CoinIndexedVector * z) const = 0;
310  virtual bool canCombine(const ClpSimplex * ,
311  const CoinIndexedVector * ) const {
312  return false;
313  }
315  virtual void transposeTimes2(const ClpSimplex * model,
316  const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
317  const CoinIndexedVector * pi2,
318  CoinIndexedVector * spare,
319  double referenceIn, double devex,
320  // Array for exact devex to say what is in reference framework
321  unsigned int * reference,
322  double * weights, double scaleFactor);
324  virtual void subsetTimes2(const ClpSimplex * model,
325  CoinIndexedVector * dj1,
326  const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
327  double referenceIn, double devex,
328  // Array for exact devex to say what is in reference framework
329  unsigned int * reference,
330  double * weights, double scaleFactor);
335  virtual void listTransposeTimes(const ClpSimplex * model,
336  double * x,
337  int * y,
338  int number,
339  double * z) const;
341 
342  virtual ClpMatrixBase * clone() const = 0;
349  virtual ClpMatrixBase * subsetClone (
350  int numberRows, const int * whichRows,
351  int numberColumns, const int * whichColumns) const;
353  virtual void backToBasics() {}
360  inline int type() const {
361  return type_;
362  }
364  void setType(int newtype) {
365  type_ = newtype;
366  }
368  void useEffectiveRhs(ClpSimplex * model);
372  virtual double * rhsOffset(ClpSimplex * model, bool forceRefresh = false,
373  bool check = false);
375  inline int lastRefresh() const {
376  return lastRefresh_;
377  }
379  inline int refreshFrequency() const {
380  return refreshFrequency_;
381  }
382  inline void setRefreshFrequency(int value) {
383  refreshFrequency_ = value;
384  }
386  inline bool skipDualCheck() const {
387  return skipDualCheck_;
388  }
389  inline void setSkipDualCheck(bool yes) {
390  skipDualCheck_ = yes;
391  }
394  inline int minimumObjectsScan() const {
395  return minimumObjectsScan_;
396  }
397  inline void setMinimumObjectsScan(int value) {
398  minimumObjectsScan_ = value;
399  }
401  inline int minimumGoodReducedCosts() const {
403  }
404  inline void setMinimumGoodReducedCosts(int value) {
405  minimumGoodReducedCosts_ = value;
406  }
408  inline double startFraction() const {
409  return startFraction_;
410  }
411  inline void setStartFraction(double value) {
412  startFraction_ = value;
413  }
415  inline double endFraction() const {
416  return endFraction_;
417  }
418  inline void setEndFraction(double value) {
419  endFraction_ = value;
420  }
422  inline double savedBestDj() const {
423  return savedBestDj_;
424  }
425  inline void setSavedBestDj(double value) {
426  savedBestDj_ = value;
427  }
429  inline int originalWanted() const {
430  return originalWanted_;
431  }
432  inline void setOriginalWanted(int value) {
433  originalWanted_ = value;
434  }
436  inline int currentWanted() const {
437  return currentWanted_;
438  }
439  inline void setCurrentWanted(int value) {
440  currentWanted_ = value;
441  }
443  inline int savedBestSequence() const {
444  return savedBestSequence_;
445  }
446  inline void setSavedBestSequence(int value) {
447  savedBestSequence_ = value;
448  }
450 
451 
452 protected:
453 
459  ClpMatrixBase();
461 public:
462  virtual ~ClpMatrixBase();
463 protected:
464  // Copy
466  // Assignment
469 
470 
471 protected:
478  double * rhsOffset_;
482  double endFraction_;
484  double savedBestDj_;
492  int type_;
508 };
509 // bias for free variables
510 #define FREE_BIAS 1.0e1
511 // Acceptance criteria for free variables
512 #define FREE_ACCEPT 1.0e2
513 
514 #endif