source: trunk/include/ClpMatrixBase.hpp @ 78

Last change on this file since 78 was 78, checked in by ladanyi, 17 years ago

Massive documentation updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1// Copyright (C) 2002, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpMatrixBase_H
4#define ClpMatrixBase_H
5
6#include "CoinPragma.hpp"
7
8#include "CoinPackedMatrix.hpp"
9class CoinIndexedVector;
10class ClpSimplex;
11
12/** Abstract base class for Clp Matrices
13
14    Since this class is abstract, no object of this type can be created.
15
16    If a derived class provides all methods then all Clp algorithms
17    should work.  Some can be very inefficient e.g. getElements etc is
18    only used for tightening bounds for dual and the copies are
19    deleted.  Many methods can just be dummy i.e. abort(); if not
20    all features are being used.  So if column generation was being done
21    then it makes no sense to do steepest edge so there would be
22    no point providing subsetTransposeTimes.
23*/
24
25class ClpMatrixBase  {
26 
27public:
28   /**@name Virtual methods that the derived classes must provide */
29   //@{
30   /// Return a complete CoinPackedMatrix
31   virtual CoinPackedMatrix * getPackedMatrix() const = 0;
32    /** Whether the packed matrix is column major ordered or not. */
33  virtual bool isColOrdered() const = 0;
34   /** Number of entries in the packed matrix. */
35  virtual CoinBigIndex getNumElements() const = 0;
36   /** Number of columns. */
37  virtual int getNumCols() const = 0;
38   /** Number of rows. */
39  virtual int getNumRows() const = 0;
40
41   /** A vector containing the elements in the packed matrix. Note that there
42        might be gaps in this list, entries that do not belong to any
43        major-dimension vector. To get the actual elements one should look at
44        this vector together with vectorStarts and vectorLengths. */
45   virtual const double * getElements() const = 0;
46   /** A vector containing the minor indices of the elements in the packed
47        matrix. Note that there might be gaps in this list, entries that do not
48        belong to any major-dimension vector. To get the actual elements one
49        should look at this vector together with vectorStarts and
50        vectorLengths. */
51   virtual const int * getIndices() const = 0;
52
53   virtual const CoinBigIndex * getVectorStarts() const = 0;
54   /** The lengths of the major-dimension vectors. */
55   virtual const int * getVectorLengths() const = 0 ;
56    /** Delete the columns whose indices are listed in <code>indDel</code>. */
57    virtual void deleteCols(const int numDel, const int * indDel) = 0;
58    /** Delete the rows whose indices are listed in <code>indDel</code>. */
59    virtual void deleteRows(const int numDel, const int * indDel) = 0;
60
61  /** Returns a new matrix in reverse order without gaps
62      Is allowed to return NULL if doesn't want to have row copy */
63  virtual ClpMatrixBase * reverseOrderedCopy() const {return NULL;};
64
65  /** Returns number of elements in basis
66      column is basic if entry >=0 */
67  virtual CoinBigIndex numberInBasis(const int * columnIsBasic) const = 0;
68  /// Fills in basis (Returns number of elements and updates numberBasic)
69  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
70                                const int * columnIsBasic, int & numberBasic,
71                                int * row, int * column,
72                                double * element) const = 0;
73  /** Creates scales for column copy (rowCopy in model may be modified)
74      default does not allow scaling
75      returns non-zero if no scaling done */
76  virtual int scale(ClpSimplex * model) const 
77  { return 1;};
78  /// Creates row copy and scales if necessary
79  virtual ClpMatrixBase * scaledRowCopy(ClpSimplex * model) const
80  { return reverseOrderedCopy();};
81
82  /** Checks if all elements are in valid range.  Can just
83      return true if you are not paranoid.  For Clp I will
84      probably expect no zeros.  Code can modify matrix to get rid of
85      small elements.
86  */
87  virtual bool allElementsInRange(ClpSimplex * model,
88                                  double smallest, double largest)
89  { return true;};
90
91  /** Unpacks a column into an CoinIndexedvector
92      Note that model is NOT const.  Bounds and objective could
93      be modified if doing column generation (just for this variable) */
94  virtual void unpack(ClpSimplex * model,CoinIndexedVector * rowArray,
95                   int column) const =0;
96  /** Purely for column generation and similar ideas.  Allows
97      matrix and any bounds or costs to be updated (sensibly).
98      Returns non-zero if any changes.
99  */
100  int refresh(ClpSimplex * model)
101    { return 0;};
102
103  /** Adds multiple of a column into an CoinIndexedvector
104      You can use quickAdd to add to vector */
105  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
106                   int column, double multiplier) const =0;
107   /// Allow any parts of a created CoinPackedMatrix to be deleted
108   virtual void releasePackedMatrix() const {};
109   //@}
110
111  //---------------------------------------------------------------------------
112  /**@name Matrix times vector methods
113     They can be faster if scalar is +- 1
114     Also for simplex I am not using basic/non-basic split */
115  //@{
116    /** Return <code>y + A * x * scalar</code> in <code>y</code>.
117        @pre <code>x</code> must be of size <code>numColumns()</code>
118        @pre <code>y</code> must be of size <code>numRows()</code> */
119  virtual void times(double scalar,
120                       const double * x, double * y) const=0;
121  /// And for scaling - default aborts for when scaling not supported
122  virtual void times(double scalar,
123                     const double * x, double * y,
124                     const double * rowScale, 
125                     const double * columnScale) const;
126    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
127        @pre <code>x</code> must be of size <code>numRows()</code>
128        @pre <code>y</code> must be of size <code>numColumns()</code> */
129    virtual void transposeTimes(double scalar,
130                                const double * x, double * y) const = 0;
131  /// And for scaling - default aborts for when scaling not supported
132    virtual void transposeTimes(double scalar,
133                                const double * x, double * y,
134                                const double * rowScale, 
135                                const double * columnScale) const;
136    /** Return <code>x * scalar *A + y</code> in <code>z</code>.
137        Can use y as temporary array (will be empty at end)
138        Squashes small elements and knows about ClpSimplex */
139  virtual void transposeTimes(const ClpSimplex * model, double scalar,
140                              const CoinIndexedVector * x,
141                              CoinIndexedVector * y,
142                              CoinIndexedVector * z) const = 0;
143    /** Return <code>x *A</code> in <code>z</code> but
144        just for indices in y.
145        This is only needed for primal steepest edge.
146        Squashes small elements and knows about ClpSimplex */
147  virtual void subsetTransposeTimes(const ClpSimplex * model,
148                              const CoinIndexedVector * x,
149                              const CoinIndexedVector * y,
150                              CoinIndexedVector * z) const = 0;
151  //@}
152  //@{
153  ///@name Other
154  /// Clone
155  virtual ClpMatrixBase * clone() const = 0;
156 
157  /// Returns type
158  inline int type() const
159  { return type_;};
160  /// Sets type
161  void setType(int type) {type_=type;};
162   //@}
163 
164 
165protected:
166
167   /**@name Constructors, destructor<br>
168      <strong>NOTE</strong>: All constructors are protected. There's no need
169      to expose them, after all, this is an abstract class. */
170   //@{
171   /** Default constructor. */
172   ClpMatrixBase();
173   /** Destructor (has to be public) */
174public:
175   virtual ~ClpMatrixBase();
176protected:
177  // Copy
178   ClpMatrixBase(const ClpMatrixBase&);
179  // Assignment
180   ClpMatrixBase& operator=(const ClpMatrixBase&);
181   //@}
182   
183   
184protected:
185   /**@name Data members
186      The data members are protected to allow access for derived classes. */
187   //@{
188   /// type (may be useful)
189   int type_;
190   //@}
191};
192
193#endif
Note: See TracBrowser for help on using the repository browser.