source: branches/pre/include/ClpMatrixBase.hpp @ 213

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

ClpInterior? compiles

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 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;
11class ClpModel;
12
13/** Abstract base class for Clp Matrices
14
15    Since this class is abstract, no object of this type can be created.
16
17    If a derived class provides all methods then all Clp algorithms
18    should work.  Some can be very inefficient e.g. getElements etc is
19    only used for tightening bounds for dual and the copies are
20    deleted.  Many methods can just be dummy i.e. abort(); if not
21    all features are being used.  So if column generation was being done
22    then it makes no sense to do steepest edge so there would be
23    no point providing subsetTransposeTimes.
24*/
25
26class ClpMatrixBase  {
27 
28public:
29   /**@name Virtual methods that the derived classes must provide */
30   //@{
31   /// Return a complete CoinPackedMatrix
32   virtual CoinPackedMatrix * getPackedMatrix() const = 0;
33    /** Whether the packed matrix is column major ordered or not. */
34  virtual bool isColOrdered() const = 0;
35   /** Number of entries in the packed matrix. */
36  virtual CoinBigIndex getNumElements() const = 0;
37   /** Number of columns. */
38  virtual int getNumCols() const = 0;
39   /** Number of rows. */
40  virtual int getNumRows() const = 0;
41
42   /** A vector containing the elements in the packed matrix. Note that there
43        might be gaps in this list, entries that do not belong to any
44        major-dimension vector. To get the actual elements one should look at
45        this vector together with vectorStarts and vectorLengths. */
46   virtual const double * getElements() const = 0;
47   /** A vector containing the minor indices of the elements in the packed
48        matrix. Note that there might be gaps in this list, entries that do not
49        belong to any major-dimension vector. To get the actual elements one
50        should look at this vector together with vectorStarts and
51        vectorLengths. */
52   virtual const int * getIndices() const = 0;
53
54   virtual const CoinBigIndex * getVectorStarts() const = 0;
55   /** The lengths of the major-dimension vectors. */
56   virtual const int * getVectorLengths() const = 0 ;
57    /** Delete the columns whose indices are listed in <code>indDel</code>. */
58    virtual void deleteCols(const int numDel, const int * indDel) = 0;
59    /** Delete the rows whose indices are listed in <code>indDel</code>. */
60    virtual void deleteRows(const int numDel, const int * indDel) = 0;
61  /// Append Columns
62  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
63  /// Append Rows
64  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
65
66  /** Returns a new matrix in reverse order without gaps
67      Is allowed to return NULL if doesn't want to have row copy */
68  virtual ClpMatrixBase * reverseOrderedCopy() const {return NULL;};
69
70  // OLD - out soon
71  /** Returns number of elements in basis
72      column is basic if entry >=0 */
73  virtual CoinBigIndex numberInBasis(const int * columnIsBasic) const = 0;
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 = 0;
79  /** If element NULL returns number of elements in column part of basis,
80      If not NULL fills in as well */
81  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
82                                 const int * whichColumn, 
83                                 int numberRowBasic,
84                                 int numberColumnBasic,
85                                 int * row, int * column,
86                                 double * element) const = 0;
87  /** Creates scales for column copy (rowCopy in model may be modified)
88      default does not allow scaling
89      returns non-zero if no scaling done */
90  virtual int scale(ClpSimplex * model) const 
91  { return 1;};
92
93  /** Checks if all elements are in valid range.  Can just
94      return true if you are not paranoid.  For Clp I will
95      probably expect no zeros.  Code can modify matrix to get rid of
96      small elements.
97  */
98  virtual bool allElementsInRange(ClpModel * model,
99                                  double smallest, double largest)
100  { return true;};
101
102  /** Unpacks a column into an CoinIndexedvector
103   */
104  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
105                   int column) const =0;
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 =0;
113  /** Purely for column generation and similar ideas.  Allows
114      matrix and any bounds or costs to be updated (sensibly).
115      Returns non-zero if any changes.
116  */
117  int refresh(ClpSimplex * model)
118    { return 0;};
119  /** Given positive integer weights for each row fills in sum of weights
120      for each column (and slack).
121      Returns weights vector
122      Default returns vector of ones
123  */
124  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
125  /** Adds multiple of a column into an CoinIndexedvector
126      You can use quickAdd to add to vector */
127  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
128                   int column, double multiplier) const =0;
129   /// Allow any parts of a created CoinPackedMatrix to be deleted
130   virtual void releasePackedMatrix() const {};
131   //@}
132
133  //---------------------------------------------------------------------------
134  /**@name Matrix times vector methods
135     They can be faster if scalar is +- 1
136     Also for simplex I am not using basic/non-basic split */
137  //@{
138    /** Return <code>y + A * x * scalar</code> in <code>y</code>.
139        @pre <code>x</code> must be of size <code>numColumns()</code>
140        @pre <code>y</code> must be of size <code>numRows()</code> */
141  virtual void times(double scalar,
142                       const double * x, double * y) const=0;
143  /** And for scaling - default aborts for when scaling not supported
144      (unless pointers NULL when as normal)
145  */
146  virtual void times(double scalar,
147                     const double * x, double * y,
148                     const double * rowScale, 
149                     const double * columnScale) const;
150    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
151        @pre <code>x</code> must be of size <code>numRows()</code>
152        @pre <code>y</code> must be of size <code>numColumns()</code> */
153    virtual void transposeTimes(double scalar,
154                                const double * x, double * y) const = 0;
155  /** And for scaling - default aborts for when scaling not supported
156      (unless pointers NULL when as normal)
157  */
158  virtual void transposeTimes(double scalar,
159                                const double * x, double * y,
160                                const double * rowScale, 
161                                const double * columnScale) const;
162    /** Return <code>x * scalar *A + y</code> in <code>z</code>.
163        Can use y as temporary array (will be empty at end)
164        Note - If x packed mode - then z packed mode
165        Squashes small elements and knows about ClpSimplex */
166  virtual void transposeTimes(const ClpSimplex * model, double scalar,
167                              const CoinIndexedVector * x,
168                              CoinIndexedVector * y,
169                              CoinIndexedVector * z) const = 0;
170    /** Return <code>x *A</code> in <code>z</code> but
171        just for indices in y.
172        This is only needed for primal steepest edge.
173        Note - If x packed mode - then z packed mode
174        Squashes small elements and knows about ClpSimplex */
175  virtual void subsetTransposeTimes(const ClpSimplex * model,
176                              const CoinIndexedVector * x,
177                              const CoinIndexedVector * y,
178                              CoinIndexedVector * z) const = 0;
179  //@}
180  //@{
181  ///@name Other
182  /// Clone
183  virtual ClpMatrixBase * clone() const = 0;
184  /** Subset clone (without gaps).  Duplicates are allowed
185      and order is as given.
186      Derived classes need not provide this as it may not always make
187      sense */
188  virtual ClpMatrixBase * subsetClone (
189                    int numberRows, const int * whichRows,
190                    int numberColumns, const int * whichColumns) const;
191 
192  /// Returns type
193  inline int type() const
194  { return type_;};
195  /// Sets type
196  void setType(int type) {type_=type;};
197   //@}
198 
199 
200protected:
201
202   /**@name Constructors, destructor<br>
203      <strong>NOTE</strong>: All constructors are protected. There's no need
204      to expose them, after all, this is an abstract class. */
205   //@{
206   /** Default constructor. */
207   ClpMatrixBase();
208   /** Destructor (has to be public) */
209public:
210   virtual ~ClpMatrixBase();
211protected:
212  // Copy
213   ClpMatrixBase(const ClpMatrixBase&);
214  // Assignment
215   ClpMatrixBase& operator=(const ClpMatrixBase&);
216   //@}
217   
218   
219protected:
220   /**@name Data members
221      The data members are protected to allow access for derived classes. */
222   //@{
223   /// type (may be useful)
224   int type_;
225   //@}
226};
227
228#endif
Note: See TracBrowser for help on using the repository browser.