source: trunk/include/ClpPackedMatrix.hpp @ 468

Last change on this file since 468 was 468, checked in by forrest, 15 years ago

to make sbb faster

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpPackedMatrix_H
4#define ClpPackedMatrix_H
5
6
7#include "CoinPragma.hpp"
8
9#include "ClpMatrixBase.hpp"
10
11/** This implements CoinPackedMatrix as derived from ClpMatrixBase.
12
13    It adds a few methods that know about model as well as matrix
14
15    For details see CoinPackedMatrix */
16
17class ClpPackedMatrix : public ClpMatrixBase {
18 
19public:
20  /**@name Useful methods */
21   //@{
22   /// Return a complete CoinPackedMatrix
23  virtual CoinPackedMatrix * getPackedMatrix() const { return matrix_;};
24    /** Whether the packed matrix is column major ordered or not. */
25    virtual bool isColOrdered() const { return matrix_->isColOrdered(); }
26   /** Number of entries in the packed matrix. */
27  virtual  CoinBigIndex getNumElements() const 
28  { return matrix_->getNumElements(); }
29   /** Number of columns. */
30   virtual int getNumCols() const { return matrix_->getNumCols(); }
31   /** Number of rows. */
32  virtual int getNumRows() const { return matrix_->getNumRows(); };
33
34   /** A vector containing the elements in the packed matrix. Note that there
35        might be gaps in this list, entries that do not belong to any
36        major-dimension vector. To get the actual elements one should look at
37        this vector together with vectorStarts and vectorLengths. */
38   virtual const double * getElements() const 
39  { return matrix_->getElements();};
40   /** A vector containing the minor indices of the elements in the packed
41        matrix. Note that there might be gaps in this list, entries that do not
42        belong to any major-dimension vector. To get the actual elements one
43        should look at this vector together with vectorStarts and
44        vectorLengths. */
45   virtual const int * getIndices() const 
46  { return matrix_->getIndices();};
47
48   virtual const CoinBigIndex * getVectorStarts() const 
49  { return matrix_->getVectorStarts();};
50   /** The lengths of the major-dimension vectors. */
51   virtual const int * getVectorLengths() const 
52  { return matrix_->getVectorLengths();} ;
53
54    /** Delete the columns whose indices are listed in <code>indDel</code>. */
55    virtual void deleteCols(const int numDel, const int * indDel)
56  { matrix_->deleteCols(numDel,indDel);numberActiveColumns_ = matrix_->getNumCols();};
57    /** Delete the rows whose indices are listed in <code>indDel</code>. */
58    virtual void deleteRows(const int numDel, const int * indDel)
59  { matrix_->deleteRows(numDel,indDel);numberActiveColumns_ = matrix_->getNumCols();};
60  /// Append Columns
61  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns)
62  { matrix_->appendCols(number,columns);numberActiveColumns_ = matrix_->getNumCols();};
63  /// Append Rows
64  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows)
65  { matrix_->appendRows(number,rows);numberActiveColumns_ = matrix_->getNumCols();};
66  /** Replace the elements of a vector.  The indices remain the same.
67      This is only needed if scaling and a row copy is used.
68      At most the number specified will be replaced.
69      The index is between 0 and major dimension of matrix */
70  virtual void replaceVector(const int index,
71                       const int numReplace, const double * newElements)
72      {matrix_->replaceVector(index,numReplace,newElements);};
73  /** Returns a new matrix in reverse order without gaps */
74  virtual ClpMatrixBase * reverseOrderedCopy() const;
75  /// Returns number of elements in column part of basis
76  virtual CoinBigIndex countBasis(ClpSimplex * model,
77                                 const int * whichColumn, 
78                                 int numberRowBasic,
79                                  int & numberColumnBasic);
80  /// Fills in column part of basis
81  virtual void fillBasis(ClpSimplex * model,
82                                 const int * whichColumn, 
83                                 int & numberColumnBasic,
84                                 int * row, int * start,
85                                 int * rowCount, int * columnCount,
86                                 double * element);
87  /** Creates scales for column copy (rowCopy in model may be modified)
88      returns non-zero if no scaling done */
89  virtual int scale(ClpModel * model) const ;
90  /** Scales rowCopy if column copy scaled
91      Only called if scales already exist */
92  virtual void scaleRowCopy(ClpModel * model) const ;
93  /** Realy really scales column copy
94      Only called if scales already exist.
95      Up to user ro delete */
96  virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
97  /** Checks if all elements are in valid range.  Can just
98      return true if you are not paranoid.  For Clp I will
99      probably expect no zeros.  Code can modify matrix to get rid of
100      small elements.
101      check bits (can be turned off to save time) :
102      1 - check if matrix has gaps
103      2 - check if zero elements
104      4 - check and compress duplicates
105      8 - report on large and small
106  */
107  virtual bool allElementsInRange(ClpModel * model,
108                                  double smallest, double largest,
109                                  int check=15);
110  /** Returns largest and smallest elements of both signs.
111      Largest refers to largest absolute value.
112  */
113  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
114                       double & smallestPositive, double & largestPositive);
115
116  /** Unpacks a column into an CoinIndexedvector
117   */
118  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
119                   int column) const ;
120  /** Unpacks a column into an CoinIndexedvector
121   ** in packed foramt
122      Note that model is NOT const.  Bounds and objective could
123      be modified if doing column generation (just for this variable) */
124  virtual void unpackPacked(ClpSimplex * model,
125                            CoinIndexedVector * rowArray,
126                            int column) const;
127  /** Adds multiple of a column into an CoinIndexedvector
128      You can use quickAdd to add to vector */
129  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
130                   int column, double multiplier) const ;
131  /** Adds multiple of a column into an array */
132  virtual void add(const ClpSimplex * model,double * array,
133                   int column, double multiplier) const;
134   /// Allow any parts of a created CoinPackedMatrix to be deleted
135   virtual void releasePackedMatrix() const { };
136  /** Given positive integer weights for each row fills in sum of weights
137      for each column (and slack).
138      Returns weights vector
139  */
140  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
141  /// Says whether it can do partial pricing
142  virtual bool canDoPartialPricing() const;
143  /// Partial pricing
144  virtual void partialPricing(ClpSimplex * model, double start, double end,
145                      int & bestSequence, int & numberWanted);
146  /// makes sure active columns correct
147  virtual int refresh(ClpSimplex * model);
148  // Really scale matrix
149  virtual void reallyScale(const double * rowScale, const double * columnScale);
150   //@}
151
152  /**@name Matrix times vector methods */
153  //@{
154    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
155        @pre <code>x</code> must be of size <code>numColumns()</code>
156        @pre <code>y</code> must be of size <code>numRows()</code> */
157  virtual void times(double scalar,
158                       const double * x, double * y) const;
159  /// And for scaling
160  virtual void times(double scalar,
161                     const double * x, double * y,
162                     const double * rowScale, 
163                     const double * columnScale) const;
164    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
165        @pre <code>x</code> must be of size <code>numRows()</code>
166        @pre <code>y</code> must be of size <code>numColumns()</code> */
167    virtual void transposeTimes(double scalar,
168                                const double * x, double * y) const;
169  /// And for scaling
170    virtual void transposeTimes(double scalar,
171                                const double * x, double * y,
172                                const double * rowScale, 
173                                const double * columnScale) const;
174    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
175        Can use y as temporary array (will be empty at end)
176        Note - If x packed mode - then z packed mode
177        Squashes small elements and knows about ClpSimplex */
178  virtual void transposeTimes(const ClpSimplex * model, double scalar,
179                              const CoinIndexedVector * x,
180                              CoinIndexedVector * y,
181                              CoinIndexedVector * z) const;
182    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
183        Note - If x packed mode - then z packed mode
184        This does by column and knows no gaps
185        Squashes small elements and knows about ClpSimplex */
186  void transposeTimesByColumn(const ClpSimplex * model, double scalar,
187                              const CoinIndexedVector * x,
188                              CoinIndexedVector * y,
189                              CoinIndexedVector * z) const;
190    /** Return <code>x * scalar * A in <code>z</code>.
191        Note - this version when x packed mode and so will be z
192        This does by column and knows no gaps and knows y empty
193        Squashes small elements and knows about ClpSimplex */
194  void transposeTimesByColumn(const ClpSimplex * model, double scalar,
195                              const CoinIndexedVector * x,
196                              CoinIndexedVector * z) const;
197    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
198        Can use y as temporary array (will be empty at end)
199        Note - If x packed mode - then z packed mode
200        Squashes small elements and knows about ClpSimplex.
201    This version uses row copy*/
202  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
203                              const CoinIndexedVector * x,
204                              CoinIndexedVector * y,
205                              CoinIndexedVector * z) const;
206    /** Return <code>x *A</code> in <code>z</code> but
207        just for indices in y.
208        Note - z always packed mode */
209  virtual void subsetTransposeTimes(const ClpSimplex * model,
210                                    const CoinIndexedVector * x,
211                                    const CoinIndexedVector * y,
212                                    CoinIndexedVector * z) const;
213  /// Sets up an effective RHS
214  void useEffectiveRhs(ClpSimplex * model);
215//@}
216
217  /**@name Other */
218   //@{
219  /// Returns CoinPackedMatrix (non const)
220  inline CoinPackedMatrix * matrix() const { return matrix_;};
221  /** Just sets matrix_ to NULL so it can be used elsewhere.
222      used in GUB
223  */
224  inline void setMatrixNull()
225  { matrix_=NULL;};
226   //@}
227
228
229  /**@name Constructors, destructor */
230   //@{
231   /** Default constructor. */
232   ClpPackedMatrix();
233   /** Destructor */
234   virtual ~ClpPackedMatrix();
235   //@}
236
237   /**@name Copy method */
238   //@{
239   /** The copy constructor. */
240   ClpPackedMatrix(const ClpPackedMatrix&);
241   /** The copy constructor from an CoinPackedMatrix. */
242   ClpPackedMatrix(const CoinPackedMatrix&);
243  /** Subset constructor (without gaps).  Duplicates are allowed
244      and order is as given */
245  ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
246                    int numberRows, const int * whichRows,
247                    int numberColumns, const int * whichColumns);
248  ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
249                    int numberRows, const int * whichRows,
250                    int numberColumns, const int * whichColumns);
251
252  /** This takes over ownership (for space reasons) */
253   ClpPackedMatrix(CoinPackedMatrix * matrix);
254
255   ClpPackedMatrix& operator=(const ClpPackedMatrix&);
256  /// Clone
257  virtual ClpMatrixBase * clone() const ;
258  /** Subset clone (without gaps).  Duplicates are allowed
259      and order is as given */
260  virtual ClpMatrixBase * subsetClone (
261                    int numberRows, const int * whichRows,
262                    int numberColumns, const int * whichColumns) const ;
263   //@}
264   
265   
266protected:
267   /**@name Data members
268      The data members are protected to allow access for derived classes. */
269   //@{
270  /// Data
271  CoinPackedMatrix * matrix_;
272  /// number of active columns (normally same as number of columns)
273  int numberActiveColumns_;
274  /// Zero element flag - set true if any zero elements
275  bool zeroElements_;
276  /// Gaps flag - set true if column start and length don't say contiguous
277  bool hasGaps_;
278   //@}
279};
280
281#endif
Note: See TracBrowser for help on using the repository browser.