source: trunk/include/ClpPackedMatrix.hpp @ 50

Last change on this file since 50 was 50, checked in by ladanyi, 18 years ago

devel-1 merged into HEAD

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.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#if defined(_MSC_VER)
7// Turn off compiler warning about long names
8#  pragma warning(disable:4786)
9#endif
10
11#include "ClpMatrixBase.hpp"
12
13/** This implements OsiPackedMatrix as derived from ClpMatrixBase.
14
15    It adds a few methods that know about model as well as matrix
16
17    For details see OsiPackedMatrix */
18
19class ClpPackedMatrix : public ClpMatrixBase {
20 
21public:
22  /**@name Useful methods */
23   //@{
24   /// Return a complete CoinPackedMatrix
25  virtual CoinPackedMatrix * getPackedMatrix() const { return matrix_;};
26    /** Whether the packed matrix is column major ordered or not. */
27    virtual bool isColOrdered() const { return matrix_->isColOrdered(); }
28   /** Number of entries in the packed matrix. */
29  virtual  CoinBigIndex getNumElements() const 
30  { return matrix_->getNumElements(); }
31   /** Number of columns. */
32   virtual int getNumCols() const { return matrix_->getNumCols(); }
33   /** Number of rows. */
34  virtual int getNumRows() const { return matrix_->getNumRows(); };
35
36   /** A vector containing the elements in the packed matrix. Note that there
37        might be gaps in this list, entries that do not belong to any
38        major-dimension vector. To get the actual elements one should look at
39        this vector together with vectorStarts and vectorLengths. */
40   virtual const double * getElements() const 
41  { return matrix_->getElements();};
42   /** A vector containing the minor indices of the elements in the packed
43        matrix. Note that there might be gaps in this list, entries that do not
44        belong to any major-dimension vector. To get the actual elements one
45        should look at this vector together with vectorStarts and
46        vectorLengths. */
47   virtual const int * getIndices() const 
48  { return matrix_->getIndices();};
49
50   virtual const CoinBigIndex * getVectorStarts() const 
51  { return matrix_->getVectorStarts();};
52   /** The lengths of the major-dimension vectors. */
53   virtual const int * getVectorLengths() const 
54  { return matrix_->getVectorLengths();} ;
55
56    /** Delete the columns whose indices are listed in <code>indDel</code>. */
57    virtual void deleteCols(const int numDel, const int * indDel)
58  { matrix_->deleteCols(numDel,indDel);};
59    /** Delete the rows whose indices are listed in <code>indDel</code>. */
60    virtual void deleteRows(const int numDel, const int * indDel)
61  { matrix_->deleteRows(numDel,indDel);};
62  /** Replace the elements of a vector.  The indices remain the same.
63      This is only needed if scaling and a row copy is used.
64      At most the number specified will be replaced.
65      The index is between 0 and major dimension of matrix */
66  void replaceVector(const int index,
67                       const int numReplace, const double * newElements)
68      {matrix_->replaceVector(index,numReplace,newElements);};
69  /** Returns a new matrix in reverse order without gaps */
70  virtual ClpMatrixBase * reverseOrderedCopy() const;
71  /** Returns number of elements in basis
72      column is basic if entry >=0 */
73  virtual CoinBigIndex numberInBasis(const int * columnIsBasic) const ;
74  /// Fills in basis (Returns number of elements and updates numberBasic)
75  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
76                                const int * columnIsBasic, int & numberBasic,
77                                int * row, int * column,
78                                double * element) const ;
79  /** Creates scales for column copy (rowCopy in model may be modified)
80      returns non-zero if no scaling done */
81  virtual int scale(ClpSimplex * model) const ;
82  /// Creates row copy and scales if necessary
83  virtual ClpMatrixBase * scaledRowCopy(ClpSimplex * model) const;
84  /** Checks if all elements are in valid range.  Can just
85      return true if you are not paranoid.  For Clp I will
86      probably expect no zeros.  Code can modify matrix to get rid of
87      small elements.
88  */
89  virtual bool allElementsInRange(ClpSimplex * model,
90                                  double smallest, double largest);
91
92  /** Unpacks a column into an CoinIndexedvector
93      Note that model is NOT const.  Bounds and objective could
94      be modified if doing column generation */
95  virtual void unpack(ClpSimplex * model,CoinIndexedVector * rowArray,
96                   int column) const ;
97  /** Adds multiple of a column into an CoinIndexedvector
98      You can use quickAdd to add to vector */
99  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
100                   int column, double multiplier) const ;
101   /// Allow any parts of a created CoinPackedMatrix to be deleted
102   virtual void releasePackedMatrix() const { };
103   //@}
104
105  /**@name Matrix times vector methods */
106  //@{
107    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
108        @precond <code>x<code> must be of size <code>numColumns()</code>
109        @precond <code>y<code> must be of size <code>numRows()</code> */
110  virtual void times(double scalar,
111                       const double * x, double * y) const;
112  /// And for scaling
113  virtual void times(double scalar,
114                     const double * x, double * y,
115                     const double * rowScale, 
116                     const double * columnScale) const;
117    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
118        @precond <code>x<code> must be of size <code>numRows()</code>
119        @precond <code>y<code> must be of size <code>numColumns()</code> */
120    virtual void transposeTimes(double scalar,
121                                const double * x, double * y) const;
122  /// And for scaling
123    virtual void transposeTimes(double scalar,
124                                const double * x, double * y,
125                                const double * rowScale, 
126                                const double * columnScale) const;
127    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
128        Can use y as temporary array (will be empty at end)
129        Squashes small elements and knows about ClpSimplex */
130  virtual void transposeTimes(const ClpSimplex * model, double scalar,
131                              const CoinIndexedVector * x,
132                              CoinIndexedVector * y,
133                              CoinIndexedVector * z) const;
134    /** Return <code>x *A in <code>z</code> but
135        just for indices in y.
136        Squashes small elements and knows about ClpSimplex */
137  virtual void subsetTransposeTimes(const ClpSimplex * model,
138                              const CoinIndexedVector * x,
139                              const CoinIndexedVector * y,
140                              CoinIndexedVector * z) const;
141  //@}
142
143  /**@name Other */
144   //@{
145  /// Returns CoinPackedMatrix (non const)
146  inline CoinPackedMatrix * matrix() const { return matrix_;};
147   //@}
148
149
150  /**@name Constructors, destructor */
151   //@{
152   /** Default constructor. */
153   ClpPackedMatrix();
154   /** Destructor */
155   virtual ~ClpPackedMatrix();
156   //@}
157
158   /**@name Copy method */
159   //@{
160   /** The copy constructor. */
161   ClpPackedMatrix(const ClpPackedMatrix&);
162   /** The copy constructor from an CoinPackedMatrix. */
163   ClpPackedMatrix(const CoinPackedMatrix&);
164
165  /** This takes over ownership (for space reasons) */
166   ClpPackedMatrix(CoinPackedMatrix * matrix);
167
168   ClpPackedMatrix& operator=(const ClpPackedMatrix&);
169  /// Clone
170  virtual ClpMatrixBase * clone() const ;
171   //@}
172   
173   
174protected:
175   /**@name Data members
176      The data members are protected to allow access for derived classes. */
177   //@{
178  /// Data
179  CoinPackedMatrix * matrix_;
180   //@}
181};
182
183#endif
Note: See TracBrowser for help on using the repository browser.