source: trunk/include/ClpPackedMatrix.hpp @ 461

Last change on this file since 461 was 461, checked in by forrest, 16 years ago

Trying to make faster

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 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  */
102  virtual bool allElementsInRange(ClpModel * model,
103                                  double smallest, double largest);
104  /** Returns largest and smallest elements of both signs.
105      Largest refers to largest absolute value.
106  */
107  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
108                       double & smallestPositive, double & largestPositive);
109
110  /** Unpacks a column into an CoinIndexedvector
111   */
112  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
113                   int column) const ;
114  /** Unpacks a column into an CoinIndexedvector
115   ** in packed foramt
116      Note that model is NOT const.  Bounds and objective could
117      be modified if doing column generation (just for this variable) */
118  virtual void unpackPacked(ClpSimplex * model,
119                            CoinIndexedVector * rowArray,
120                            int column) const;
121  /** Adds multiple of a column into an CoinIndexedvector
122      You can use quickAdd to add to vector */
123  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
124                   int column, double multiplier) const ;
125  /** Adds multiple of a column into an array */
126  virtual void add(const ClpSimplex * model,double * array,
127                   int column, double multiplier) const;
128   /// Allow any parts of a created CoinPackedMatrix to be deleted
129   virtual void releasePackedMatrix() const { };
130  /** Given positive integer weights for each row fills in sum of weights
131      for each column (and slack).
132      Returns weights vector
133  */
134  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
135  /// Says whether it can do partial pricing
136  virtual bool canDoPartialPricing() const;
137  /// Partial pricing
138  virtual void partialPricing(ClpSimplex * model, double start, double end,
139                      int & bestSequence, int & numberWanted);
140  /// makes sure active columns correct
141  virtual int refresh(ClpSimplex * model);
142  // Really scale matrix
143  virtual void reallyScale(const double * rowScale, const double * columnScale);
144   //@}
145
146  /**@name Matrix times vector methods */
147  //@{
148    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
149        @pre <code>x</code> must be of size <code>numColumns()</code>
150        @pre <code>y</code> must be of size <code>numRows()</code> */
151  virtual void times(double scalar,
152                       const double * x, double * y) const;
153  /// And for scaling
154  virtual void times(double scalar,
155                     const double * x, double * y,
156                     const double * rowScale, 
157                     const double * columnScale) const;
158    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
159        @pre <code>x</code> must be of size <code>numRows()</code>
160        @pre <code>y</code> must be of size <code>numColumns()</code> */
161    virtual void transposeTimes(double scalar,
162                                const double * x, double * y) const;
163  /// And for scaling
164    virtual void transposeTimes(double scalar,
165                                const double * x, double * y,
166                                const double * rowScale, 
167                                const double * columnScale) const;
168    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
169        Can use y as temporary array (will be empty at end)
170        Note - If x packed mode - then z packed mode
171        Squashes small elements and knows about ClpSimplex */
172  virtual void transposeTimes(const ClpSimplex * model, double scalar,
173                              const CoinIndexedVector * x,
174                              CoinIndexedVector * y,
175                              CoinIndexedVector * z) const;
176    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
177        Note - If x packed mode - then z packed mode
178        This does by column and knows no gaps
179        Squashes small elements and knows about ClpSimplex */
180  void transposeTimesByColumn(const ClpSimplex * model, double scalar,
181                              const CoinIndexedVector * x,
182                              CoinIndexedVector * y,
183                              CoinIndexedVector * z) const;
184    /** Return <code>x * scalar * A in <code>z</code>.
185        Note - this version when x packed mode and so will be z
186        This does by column and knows no gaps and knows y empty
187        Squashes small elements and knows about ClpSimplex */
188  void transposeTimesByColumn(const ClpSimplex * model, double scalar,
189                              const CoinIndexedVector * x,
190                              CoinIndexedVector * z) const;
191    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
192        Can use y as temporary array (will be empty at end)
193        Note - If x packed mode - then z packed mode
194        Squashes small elements and knows about ClpSimplex.
195    This version uses row copy*/
196  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
197                              const CoinIndexedVector * x,
198                              CoinIndexedVector * y,
199                              CoinIndexedVector * z) const;
200    /** Return <code>x *A</code> in <code>z</code> but
201        just for indices in y.
202        Note - z always packed mode */
203  virtual void subsetTransposeTimes(const ClpSimplex * model,
204                                    const CoinIndexedVector * x,
205                                    const CoinIndexedVector * y,
206                                    CoinIndexedVector * z) const;
207  /// Sets up an effective RHS
208  void useEffectiveRhs(ClpSimplex * model);
209//@}
210
211  /**@name Other */
212   //@{
213  /// Returns CoinPackedMatrix (non const)
214  inline CoinPackedMatrix * matrix() const { return matrix_;};
215  /** Just sets matrix_ to NULL so it can be used elsewhere.
216      used in GUB
217  */
218  inline void setMatrixNull()
219  { matrix_=NULL;};
220   //@}
221
222
223  /**@name Constructors, destructor */
224   //@{
225   /** Default constructor. */
226   ClpPackedMatrix();
227   /** Destructor */
228   virtual ~ClpPackedMatrix();
229   //@}
230
231   /**@name Copy method */
232   //@{
233   /** The copy constructor. */
234   ClpPackedMatrix(const ClpPackedMatrix&);
235   /** The copy constructor from an CoinPackedMatrix. */
236   ClpPackedMatrix(const CoinPackedMatrix&);
237  /** Subset constructor (without gaps).  Duplicates are allowed
238      and order is as given */
239  ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
240                    int numberRows, const int * whichRows,
241                    int numberColumns, const int * whichColumns);
242  ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
243                    int numberRows, const int * whichRows,
244                    int numberColumns, const int * whichColumns);
245
246  /** This takes over ownership (for space reasons) */
247   ClpPackedMatrix(CoinPackedMatrix * matrix);
248
249   ClpPackedMatrix& operator=(const ClpPackedMatrix&);
250  /// Clone
251  virtual ClpMatrixBase * clone() const ;
252  /** Subset clone (without gaps).  Duplicates are allowed
253      and order is as given */
254  virtual ClpMatrixBase * subsetClone (
255                    int numberRows, const int * whichRows,
256                    int numberColumns, const int * whichColumns) const ;
257   //@}
258   
259   
260protected:
261   /**@name Data members
262      The data members are protected to allow access for derived classes. */
263   //@{
264  /// Data
265  CoinPackedMatrix * matrix_;
266  /// number of active columns (normally same as number of columns)
267  int numberActiveColumns_;
268  /// Zero element flag - set true if any zero elements
269  bool zeroElements_;
270  /// Gaps flag - set true if column start and length don't say contiguous
271  bool hasGaps_;
272   //@}
273};
274
275#endif
Note: See TracBrowser for help on using the repository browser.