source: trunk/include/ClpMatrixBase.hpp @ 118

Last change on this file since 118 was 118, checked in by forrest, 17 years ago

Adding Network matrix and PlusMinusOne?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 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
79  /** Checks if all elements are in valid range.  Can just
80      return true if you are not paranoid.  For Clp I will
81      probably expect no zeros.  Code can modify matrix to get rid of
82      small elements.
83  */
84  virtual bool allElementsInRange(ClpSimplex * model,
85                                  double smallest, double largest)
86  { return true;};
87
88  /** Unpacks a column into an CoinIndexedvector
89      Note that model is NOT const.  Bounds and objective could
90      be modified if doing column generation (just for this variable) */
91  virtual void unpack(ClpSimplex * model,CoinIndexedVector * rowArray,
92                   int column) const =0;
93  /** Purely for column generation and similar ideas.  Allows
94      matrix and any bounds or costs to be updated (sensibly).
95      Returns non-zero if any changes.
96  */
97  int refresh(ClpSimplex * model)
98    { return 0;};
99
100  /** Adds multiple of a column into an CoinIndexedvector
101      You can use quickAdd to add to vector */
102  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
103                   int column, double multiplier) const =0;
104   /// Allow any parts of a created CoinPackedMatrix to be deleted
105   virtual void releasePackedMatrix() const {};
106   //@}
107
108  //---------------------------------------------------------------------------
109  /**@name Matrix times vector methods
110     They can be faster if scalar is +- 1
111     Also for simplex I am not using basic/non-basic split */
112  //@{
113    /** Return <code>y + A * x * scalar</code> in <code>y</code>.
114        @pre <code>x</code> must be of size <code>numColumns()</code>
115        @pre <code>y</code> must be of size <code>numRows()</code> */
116  virtual void times(double scalar,
117                       const double * x, double * y) const=0;
118  /// And for scaling - default aborts for when scaling not supported
119  virtual void times(double scalar,
120                     const double * x, double * y,
121                     const double * rowScale, 
122                     const double * columnScale) const;
123    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
124        @pre <code>x</code> must be of size <code>numRows()</code>
125        @pre <code>y</code> must be of size <code>numColumns()</code> */
126    virtual void transposeTimes(double scalar,
127                                const double * x, double * y) const = 0;
128  /// And for scaling - default aborts for when scaling not supported
129    virtual void transposeTimes(double scalar,
130                                const double * x, double * y,
131                                const double * rowScale, 
132                                const double * columnScale) const;
133    /** Return <code>x * scalar *A + y</code> in <code>z</code>.
134        Can use y as temporary array (will be empty at end)
135        Squashes small elements and knows about ClpSimplex */
136  virtual void transposeTimes(const ClpSimplex * model, double scalar,
137                              const CoinIndexedVector * x,
138                              CoinIndexedVector * y,
139                              CoinIndexedVector * z) const = 0;
140    /** Return <code>x *A</code> in <code>z</code> but
141        just for indices in y.
142        This is only needed for primal steepest edge.
143        Squashes small elements and knows about ClpSimplex */
144  virtual void subsetTransposeTimes(const ClpSimplex * model,
145                              const CoinIndexedVector * x,
146                              const CoinIndexedVector * y,
147                              CoinIndexedVector * z) const = 0;
148  //@}
149  //@{
150  ///@name Other
151  /// Clone
152  virtual ClpMatrixBase * clone() const = 0;
153 
154  /// Returns type
155  inline int type() const
156  { return type_;};
157  /// Sets type
158  void setType(int type) {type_=type;};
159   //@}
160 
161 
162protected:
163
164   /**@name Constructors, destructor<br>
165      <strong>NOTE</strong>: All constructors are protected. There's no need
166      to expose them, after all, this is an abstract class. */
167   //@{
168   /** Default constructor. */
169   ClpMatrixBase();
170   /** Destructor (has to be public) */
171public:
172   virtual ~ClpMatrixBase();
173protected:
174  // Copy
175   ClpMatrixBase(const ClpMatrixBase&);
176  // Assignment
177   ClpMatrixBase& operator=(const ClpMatrixBase&);
178   //@}
179   
180   
181protected:
182   /**@name Data members
183      The data members are protected to allow access for derived classes. */
184   //@{
185   /// type (may be useful)
186   int type_;
187   //@}
188};
189
190#endif
Note: See TracBrowser for help on using the repository browser.