ClpPackedMatrix.hpp
Go to the documentation of this file.
1 /* $Id: ClpPackedMatrix.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 ClpPackedMatrix_H
5 #define ClpPackedMatrix_H
6 
7 #include "CoinPragma.hpp"
8 
9 #include "ClpMatrixBase.hpp"
10 
17 class ClpPackedMatrix2;
18 class ClpPackedMatrix3;
20 
21 public:
24  virtual CoinPackedMatrix * getPackedMatrix() const {
26  return matrix_;
27  }
29  virtual bool isColOrdered() const {
30  return matrix_->isColOrdered();
31  }
33  virtual CoinBigIndex getNumElements() const {
34  return matrix_->getNumElements();
35  }
37  virtual int getNumCols() const {
38  return matrix_->getNumCols();
39  }
41  virtual int getNumRows() const {
42  return matrix_->getNumRows();
43  }
44 
49  virtual const double * getElements() const {
50  return matrix_->getElements();
51  }
53  inline double * getMutableElements() const {
54  return matrix_->getMutableElements();
55  }
61  virtual const int * getIndices() const {
62  return matrix_->getIndices();
63  }
64 
65  virtual const CoinBigIndex * getVectorStarts() const {
66  return matrix_->getVectorStarts();
67  }
69  virtual const int * getVectorLengths() const {
70  return matrix_->getVectorLengths();
71  }
73  virtual int getVectorLength(int index) const {
74  return matrix_->getVectorSize(index);
75  }
76 
78  virtual void deleteCols(const int numDel, const int * indDel);
80  virtual void deleteRows(const int numDel, const int * indDel);
81 #ifndef CLP_NO_VECTOR
82  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
85  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
86 #endif
87 
91  virtual int appendMatrix(int number, int type,
92  const CoinBigIndex * starts, const int * index,
93  const double * element, int numberOther = -1);
98  virtual void replaceVector(const int index,
99  const int numReplace, const double * newElements) {
100  matrix_->replaceVector(index, numReplace, newElements);
101  }
105  virtual void modifyCoefficient(int row, int column, double newElement,
106  bool keepZero = false) {
107  matrix_->modifyCoefficient(row, column, newElement, keepZero);
108  }
110  virtual ClpMatrixBase * reverseOrderedCopy() const;
112  virtual CoinBigIndex countBasis(const int * whichColumn,
113  int & numberColumnBasic);
115  virtual void fillBasis(ClpSimplex * model,
116  const int * whichColumn,
117  int & numberColumnBasic,
118  int * row, int * start,
119  int * rowCount, int * columnCount,
120  CoinFactorizationDouble * element);
123  virtual int scale(ClpModel * model, const ClpSimplex * baseModel = NULL) const ;
126  virtual void scaleRowCopy(ClpModel * model) const ;
128  void createScaledMatrix(ClpSimplex * model) const;
132  virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
143  virtual bool allElementsInRange(ClpModel * model,
144  double smallest, double largest,
145  int check = 15);
149  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
150  double & smallestPositive, double & largestPositive);
151 
154  virtual void unpack(const ClpSimplex * model, CoinIndexedVector * rowArray,
155  int column) const ;
160  virtual void unpackPacked(ClpSimplex * model,
161  CoinIndexedVector * rowArray,
162  int column) const;
165  virtual void add(const ClpSimplex * model, CoinIndexedVector * rowArray,
166  int column, double multiplier) const ;
168  virtual void add(const ClpSimplex * model, double * array,
169  int column, double multiplier) const;
171  virtual void releasePackedMatrix() const { }
176  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model, int * inputWeights) const;
178  virtual bool canDoPartialPricing() const;
180  virtual void partialPricing(ClpSimplex * model, double start, double end,
181  int & bestSequence, int & numberWanted);
183  virtual int refresh(ClpSimplex * model);
184  // Really scale matrix
185  virtual void reallyScale(const double * rowScale, const double * columnScale);
191  virtual void setDimensions(int numrows, int numcols);
193 
199  virtual void times(double scalar,
200  const double * x, double * y) const;
202  virtual void times(double scalar,
203  const double * x, double * y,
204  const double * rowScale,
205  const double * columnScale) const;
209  virtual void transposeTimes(double scalar,
210  const double * x, double * y) const;
212  virtual void transposeTimes(double scalar,
213  const double * x, double * y,
214  const double * rowScale,
215  const double * columnScale,
216  double * spare = NULL) const;
221  void transposeTimesSubset( int number,
222  const int * which,
223  const double * pi, double * y,
224  const double * rowScale,
225  const double * columnScale,
226  double * spare = NULL) const;
231  virtual void transposeTimes(const ClpSimplex * model, double scalar,
232  const CoinIndexedVector * x,
233  CoinIndexedVector * y,
234  CoinIndexedVector * z) const;
239  void transposeTimesByColumn(const ClpSimplex * model, double scalar,
240  const CoinIndexedVector * x,
241  CoinIndexedVector * y,
242  CoinIndexedVector * z) const;
248  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
249  const CoinIndexedVector * x,
250  CoinIndexedVector * y,
251  CoinIndexedVector * z) const;
255  virtual void subsetTransposeTimes(const ClpSimplex * model,
256  const CoinIndexedVector * x,
257  const CoinIndexedVector * y,
258  CoinIndexedVector * z) const;
261  virtual bool canCombine(const ClpSimplex * model,
262  const CoinIndexedVector * pi) const;
264  virtual void transposeTimes2(const ClpSimplex * model,
265  const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
266  const CoinIndexedVector * pi2,
267  CoinIndexedVector * spare,
268  double referenceIn, double devex,
269  // Array for exact devex to say what is in reference framework
270  unsigned int * reference,
271  double * weights, double scaleFactor);
273  virtual void subsetTimes2(const ClpSimplex * model,
274  CoinIndexedVector * dj1,
275  const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
276  double referenceIn, double devex,
277  // Array for exact devex to say what is in reference framework
278  unsigned int * reference,
279  double * weights, double scaleFactor);
281  void useEffectiveRhs(ClpSimplex * model);
282 #if COIN_LONG_WORK
283  // For long double versions
284  virtual void times(CoinWorkDouble scalar,
285  const CoinWorkDouble * x, CoinWorkDouble * y) const ;
286  virtual void transposeTimes(CoinWorkDouble scalar,
287  const CoinWorkDouble * x, CoinWorkDouble * y) const ;
288 #endif
289 
290 
293  inline CoinPackedMatrix * matrix() const {
295  return matrix_;
296  }
300  inline void setMatrixNull() {
301  matrix_ = NULL;
302  }
304  inline void makeSpecialColumnCopy() {
305  flags_ |= 16;
306  }
310  inline bool zeros() const {
311  return ((flags_ & 1) != 0);
312  }
314  inline bool wantsSpecialColumnCopy() const {
315  return ((flags_ & 16) != 0);
316  }
318  inline int flags() const {
319  return flags_;
320  }
322  inline void checkGaps() {
323  flags_ = (matrix_->hasGaps()) ? (flags_ | 2) : (flags_ & (~2));
324  }
326 
327 
331  ClpPackedMatrix();
333  virtual ~ClpPackedMatrix();
335 
341  ClpPackedMatrix(const CoinPackedMatrix&);
344  ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
345  int numberRows, const int * whichRows,
346  int numberColumns, const int * whichColumns);
347  ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
348  int numberRows, const int * whichRows,
349  int numberColumns, const int * whichColumns);
350 
352  ClpPackedMatrix(CoinPackedMatrix * matrix);
353 
356  virtual ClpMatrixBase * clone() const ;
358  virtual void copy(const ClpPackedMatrix * from);
361  virtual ClpMatrixBase * subsetClone (
362  int numberRows, const int * whichRows,
363  int numberColumns, const int * whichColumns) const ;
365  void specialRowCopy(ClpSimplex * model, const ClpMatrixBase * rowCopy);
367  void specialColumnCopy(ClpSimplex * model);
369  virtual void correctSequence(const ClpSimplex * model, int & sequenceIn, int & sequenceOut) ;
371 private:
373  int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
374  int * COIN_RESTRICT index,
375  double * COIN_RESTRICT array,
376  const double tolerance) const;
378  int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
379  const double * COIN_RESTRICT columnScale,
380  int * COIN_RESTRICT index,
381  double * COIN_RESTRICT array,
382  const double tolerance) const;
384  int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
385  int * COIN_RESTRICT index,
386  double * COIN_RESTRICT array,
387  const unsigned char * status,
388  const double tolerance) const;
391  int gutsOfTransposeTimesUnscaled(const double * COIN_RESTRICT pi,
392  int * COIN_RESTRICT index,
393  double * COIN_RESTRICT array,
394  const unsigned char * status,
395  int * COIN_RESTRICT spareIndex,
396  double * COIN_RESTRICT spareArray,
397  const double * COIN_RESTRICT reducedCost,
398  double & upperTheta,
399  double & bestPossible,
400  double acceptablePivot,
401  double dualTolerance,
402  int & numberRemaining,
403  const double zeroTolerance) const;
405  int gutsOfTransposeTimesScaled(const double * COIN_RESTRICT pi,
406  const double * COIN_RESTRICT columnScale,
407  int * COIN_RESTRICT index,
408  double * COIN_RESTRICT array,
409  const unsigned char * status,
410  const double tolerance) const;
412  int gutsOfTransposeTimesByRowGEK(const CoinIndexedVector * COIN_RESTRICT piVector,
413  int * COIN_RESTRICT index,
414  double * COIN_RESTRICT output,
415  int numberColumns,
416  const double tolerance,
417  const double scalar) const;
419  int gutsOfTransposeTimesByRowGE3(const CoinIndexedVector * COIN_RESTRICT piVector,
420  int * COIN_RESTRICT index,
421  double * COIN_RESTRICT output,
422  int * COIN_RESTRICT lookup,
423  char * COIN_RESTRICT marked,
424  const double tolerance,
425  const double scalar) const;
427  void gutsOfTransposeTimesByRowEQ2(const CoinIndexedVector * piVector, CoinIndexedVector * output,
428  CoinIndexedVector * spareVector, const double tolerance, const double scalar) const;
430  void gutsOfTransposeTimesByRowEQ1(const CoinIndexedVector * piVector, CoinIndexedVector * output,
431  const double tolerance, const double scalar) const;
433  void clearCopies();
434 
435 
436 protected:
438  void checkFlags(int type) const;
442  CoinPackedMatrix * matrix_;
453  int flags_;
459 };
460 #ifdef THREAD
461 #include <pthread.h>
462 typedef struct {
463  double acceptablePivot;
464  const ClpSimplex * model;
465  double * spare;
466  int * spareIndex;
467  double * arrayTemp;
468  int * indexTemp;
469  int * numberInPtr;
470  double * bestPossiblePtr;
471  double * upperThetaPtr;
472  int * posFreePtr;
473  double * freePivotPtr;
474  int * numberOutPtr;
475  const unsigned short * count;
476  const double * pi;
477  const CoinBigIndex * rowStart;
478  const double * element;
479  const unsigned short * column;
480  int offset;
481  int numberInRowArray;
482  int numberLook;
483 } dualColumn0Struct;
484 #endif
486 
487 public:
493  void transposeTimes(const ClpSimplex * model,
494  const CoinPackedMatrix * rowCopy,
495  const CoinIndexedVector * x,
496  CoinIndexedVector * spareArray,
497  CoinIndexedVector * z) const;
499  inline bool usefulInfo() const {
500  return rowStart_ != NULL;
501  }
503 
504 
510  ClpPackedMatrix2(ClpSimplex * model, const CoinPackedMatrix * rowCopy);
512  virtual ~ClpPackedMatrix2();
514 
521 
522 
523 protected:
527  int numberBlocks_;
532  int * offset_;
534  mutable unsigned short * count_;
536  mutable CoinBigIndex * rowStart_;
538  unsigned short * column_;
540  double * work_;
541 #ifdef THREAD
542  pthread_t * threadId_;
543  dualColumn0Struct * info_;
544 #endif
545 
546 };
547 typedef struct {
548  CoinBigIndex startElements_; // point to data
549  int startIndices_; // point to column_
551  int numberPrice_; // at beginning
552  int numberElements_; // number elements per column
553 } blockStruct;
555 
556 public:
562  void transposeTimes(const ClpSimplex * model,
563  const double * pi,
564  CoinIndexedVector * output) const;
566  void transposeTimes2(const ClpSimplex * model,
567  const double * pi, CoinIndexedVector * dj1,
568  const double * piWeight,
569  double referenceIn, double devex,
570  // Array for exact devex to say what is in reference framework
571  unsigned int * reference,
572  double * weights, double scaleFactor);
574 
575 
581  ClpPackedMatrix3(ClpSimplex * model, const CoinPackedMatrix * columnCopy);
583  virtual ~ClpPackedMatrix3();
585 
592 
595  void sortBlocks(const ClpSimplex * model);
597  void swapOne(const ClpSimplex * model, const ClpPackedMatrix * matrix,
598  int iColumn);
600 
601 
602 protected:
606  int numberBlocks_;
611  int * column_;
613  CoinBigIndex * start_;
615  int * row_;
617  double * element_;
621 };
622 
623 #endif