source: branches/devel-1/include/ClpMatrixBase.hpp @ 15

Last change on this file since 15 was 2, checked in by forrest, 18 years ago

Adding Clp to development branch

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