source: branches/pre/include/ClpPackedMatrix.hpp @ 210

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

Trying

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 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 OsiPackedMatrix as derived from ClpMatrixBase.
12
13    It adds a few methods that know about model as well as matrix
14
15    For details see OsiPackedMatrix */
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);};
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);};
60  /// Append Columns
61  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns)
62  { matrix_->appendCols(number,columns);};
63  /// Append Rows
64  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows)
65  { matrix_->appendRows(number,rows);};
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  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 basis
76      column is basic if entry >=0 */
77  virtual CoinBigIndex numberInBasis(const int * columnIsBasic) const ;
78  /// Fills in basis (Returns number of elements and updates numberBasic)
79  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
80                                const int * columnIsBasic, int & numberBasic,
81                                int * row, int * column,
82                                double * element) const ;
83  /** If element NULL returns number of elements in column part of basis,
84      If not NULL fills in as well */
85  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
86                                 const int * whichColumn, 
87                                 int numberRowBasic,
88                                 int numberColumnBasic,
89                                 int * row, int * column,
90                                 double * element) const ;
91  /** Creates scales for column copy (rowCopy in model may be modified)
92      returns non-zero if no scaling done */
93  virtual int scale(ClpSimplex * model) const ;
94  /** Checks if all elements are in valid range.  Can just
95      return true if you are not paranoid.  For Clp I will
96      probably expect no zeros.  Code can modify matrix to get rid of
97      small elements.
98  */
99  virtual bool allElementsInRange(ClpSimplex * model,
100                                  double smallest, double largest);
101
102  /** Unpacks a column into an CoinIndexedvector
103   */
104  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
105                   int column) const ;
106  /** Unpacks a column into an CoinIndexedvector
107   ** in packed foramt
108      Note that model is NOT const.  Bounds and objective could
109      be modified if doing column generation (just for this variable) */
110  virtual void unpackPacked(ClpSimplex * model,
111                            CoinIndexedVector * rowArray,
112                            int column) const;
113  /** Adds multiple of a column into an CoinIndexedvector
114      You can use quickAdd to add to vector */
115  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
116                   int column, double multiplier) const ;
117   /// Allow any parts of a created CoinPackedMatrix to be deleted
118   virtual void releasePackedMatrix() const { };
119  /** Given positive integer weights for each row fills in sum of weights
120      for each column (and slack).
121      Returns weights vector
122  */
123  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
124   //@}
125
126  /**@name Matrix times vector methods */
127  //@{
128    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
129        @pre <code>x</code> must be of size <code>numColumns()</code>
130        @pre <code>y</code> must be of size <code>numRows()</code> */
131  virtual void times(double scalar,
132                       const double * x, double * y) const;
133  /// And for scaling
134  virtual void times(double scalar,
135                     const double * x, double * y,
136                     const double * rowScale, 
137                     const double * columnScale) const;
138    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
139        @pre <code>x</code> must be of size <code>numRows()</code>
140        @pre <code>y</code> must be of size <code>numColumns()</code> */
141    virtual void transposeTimes(double scalar,
142                                const double * x, double * y) const;
143  /// And for scaling
144    virtual void transposeTimes(double scalar,
145                                const double * x, double * y,
146                                const double * rowScale, 
147                                const double * columnScale) const;
148    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
149        Can use y as temporary array (will be empty at end)
150        Note - If x packed mode - then z packed mode
151        Squashes small elements and knows about ClpSimplex */
152  virtual void transposeTimes(const ClpSimplex * model, double scalar,
153                              const CoinIndexedVector * x,
154                              CoinIndexedVector * y,
155                              CoinIndexedVector * z) const;
156    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
157        Can use y as temporary array (will be empty at end)
158        Note - If x packed mode - then z packed mode
159        Squashes small elements and knows about ClpSimplex.
160    This version uses row copy*/
161  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
162                              const CoinIndexedVector * x,
163                              CoinIndexedVector * y,
164                              CoinIndexedVector * z) const;
165    /** Return <code>x *A</code> in <code>z</code> but
166        just for indices in y.
167        Note - If x packed mode - then z packed mode
168        Squashes small elements and knows about ClpSimplex */
169  virtual void subsetTransposeTimes(const ClpSimplex * model,
170                                    const CoinIndexedVector * x,
171                                    const CoinIndexedVector * y,
172                                    CoinIndexedVector * z) const;
173  //@}
174
175  /**@name Other */
176   //@{
177  /// Returns CoinPackedMatrix (non const)
178  inline CoinPackedMatrix * matrix() const { return matrix_;};
179   //@}
180
181
182  /**@name Constructors, destructor */
183   //@{
184   /** Default constructor. */
185   ClpPackedMatrix();
186   /** Destructor */
187   virtual ~ClpPackedMatrix();
188   //@}
189
190   /**@name Copy method */
191   //@{
192   /** The copy constructor. */
193   ClpPackedMatrix(const ClpPackedMatrix&);
194   /** The copy constructor from an CoinPackedMatrix. */
195   ClpPackedMatrix(const CoinPackedMatrix&);
196  /** Subset constructor (without gaps).  Duplicates are allowed
197      and order is as given */
198  ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
199                    int numberRows, const int * whichRows,
200                    int numberColumns, const int * whichColumns);
201  ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
202                    int numberRows, const int * whichRows,
203                    int numberColumns, const int * whichColumns);
204
205  /** This takes over ownership (for space reasons) */
206   ClpPackedMatrix(CoinPackedMatrix * matrix);
207
208   ClpPackedMatrix& operator=(const ClpPackedMatrix&);
209  /// Clone
210  virtual ClpMatrixBase * clone() const ;
211  /** Subset clone (without gaps).  Duplicates are allowed
212      and order is as given */
213  virtual ClpMatrixBase * subsetClone (
214                    int numberRows, const int * whichRows,
215                    int numberColumns, const int * whichColumns) const ;
216   //@}
217   
218   
219protected:
220   /**@name Data members
221      The data members are protected to allow access for derived classes. */
222   //@{
223  /// Data
224  CoinPackedMatrix * matrix_;
225  /// Zero element flag - set true if any zero elements
226  bool zeroElements_;
227   //@}
228};
229
230#endif
Note: See TracBrowser for help on using the repository browser.