source: trunk/include/ClpMatrixBase.hpp @ 225

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

This should break everything

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 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  /** Returns largest and smallest elements of both signs.
102      Largest refers to largest absolute value.
103      If returns zeros then can't tell anything */
104  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
105                       double & smallestPositive, double & largestPositive);
106
107  /** Unpacks a column into an CoinIndexedvector
108   */
109  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
110                   int column) const =0;
111  /** Unpacks a column into an CoinIndexedvector
112   ** in packed foramt
113      Note that model is NOT const.  Bounds and objective could
114      be modified if doing column generation (just for this variable) */
115  virtual void unpackPacked(ClpSimplex * model,
116                            CoinIndexedVector * rowArray,
117                            int column) const =0;
118  /** Purely for column generation and similar ideas.  Allows
119      matrix and any bounds or costs to be updated (sensibly).
120      Returns non-zero if any changes.
121  */
122  int refresh(ClpSimplex * model)
123    { return 0;};
124  /** Given positive integer weights for each row fills in sum of weights
125      for each column (and slack).
126      Returns weights vector
127      Default returns vector of ones
128  */
129  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
130  /** Adds multiple of a column into an CoinIndexedvector
131      You can use quickAdd to add to vector */
132  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
133                   int column, double multiplier) const =0;
134   /// Allow any parts of a created CoinPackedMatrix to be deleted
135   virtual void releasePackedMatrix() const {};
136   //@}
137
138  //---------------------------------------------------------------------------
139  /**@name Matrix times vector methods
140     They can be faster if scalar is +- 1
141     Also for simplex I am not using basic/non-basic split */
142  //@{
143    /** Return <code>y + A * x * scalar</code> in <code>y</code>.
144        @pre <code>x</code> must be of size <code>numColumns()</code>
145        @pre <code>y</code> must be of size <code>numRows()</code> */
146  virtual void times(double scalar,
147                       const double * x, double * y) const=0;
148  /** And for scaling - default aborts for when scaling not supported
149      (unless pointers NULL when as normal)
150  */
151  virtual void times(double scalar,
152                     const double * x, double * y,
153                     const double * rowScale, 
154                     const double * columnScale) const;
155    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
156        @pre <code>x</code> must be of size <code>numRows()</code>
157        @pre <code>y</code> must be of size <code>numColumns()</code> */
158    virtual void transposeTimes(double scalar,
159                                const double * x, double * y) const = 0;
160  /** And for scaling - default aborts for when scaling not supported
161      (unless pointers NULL when as normal)
162  */
163  virtual void transposeTimes(double scalar,
164                                const double * x, double * y,
165                                const double * rowScale, 
166                                const double * columnScale) const;
167    /** Return <code>x * scalar *A + y</code> in <code>z</code>.
168        Can use y as temporary array (will be empty at end)
169        Note - If x packed mode - then z packed mode
170        Squashes small elements and knows about ClpSimplex */
171  virtual void transposeTimes(const ClpSimplex * model, double scalar,
172                              const CoinIndexedVector * x,
173                              CoinIndexedVector * y,
174                              CoinIndexedVector * z) const = 0;
175    /** Return <code>x *A</code> in <code>z</code> but
176        just for indices in y.
177        This is only needed for primal steepest edge.
178        Note - If x packed mode - then z packed mode
179        Squashes small elements and knows about ClpSimplex */
180  virtual void subsetTransposeTimes(const ClpSimplex * model,
181                              const CoinIndexedVector * x,
182                              const CoinIndexedVector * y,
183                              CoinIndexedVector * z) const = 0;
184  //@}
185  //@{
186  ///@name Other
187  /// Clone
188  virtual ClpMatrixBase * clone() const = 0;
189  /** Subset clone (without gaps).  Duplicates are allowed
190      and order is as given.
191      Derived classes need not provide this as it may not always make
192      sense */
193  virtual ClpMatrixBase * subsetClone (
194                    int numberRows, const int * whichRows,
195                    int numberColumns, const int * whichColumns) const;
196 
197  /// Returns type
198  inline int type() const
199  { return type_;};
200  /// Sets type
201  void setType(int type) {type_=type;};
202   //@}
203 
204 
205protected:
206
207   /**@name Constructors, destructor<br>
208      <strong>NOTE</strong>: All constructors are protected. There's no need
209      to expose them, after all, this is an abstract class. */
210   //@{
211   /** Default constructor. */
212   ClpMatrixBase();
213   /** Destructor (has to be public) */
214public:
215   virtual ~ClpMatrixBase();
216protected:
217  // Copy
218   ClpMatrixBase(const ClpMatrixBase&);
219  // Assignment
220   ClpMatrixBase& operator=(const ClpMatrixBase&);
221   //@}
222   
223   
224protected:
225   /**@name Data members
226      The data members are protected to allow access for derived classes. */
227   //@{
228   /// type (may be useful)
229   int type_;
230   //@}
231};
232
233#endif
Note: See TracBrowser for help on using the repository browser.