source: trunk/include/ClpPackedMatrix.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 ClpPackedMatrix_H
4#define ClpPackedMatrix_H
5
6
7#include "CoinPragma.hpp"
8
9#include "ClpMatrixBase.hpp"
10
11/** This implements OsiPackedMatrix as derived from ClpMatrixBase.
12
13    It adds a few methods that know about model as well as matrix
14
15    For details see OsiPackedMatrix */
16
17class ClpPackedMatrix : public ClpMatrixBase {
18 
19public:
20  /**@name Useful methods */
21   //@{
22   /// Return a complete CoinPackedMatrix
23  virtual CoinPackedMatrix * getPackedMatrix() const { return matrix_;};
24    /** Whether the packed matrix is column major ordered or not. */
25    virtual bool isColOrdered() const { return matrix_->isColOrdered(); }
26   /** Number of entries in the packed matrix. */
27  virtual  CoinBigIndex getNumElements() const 
28  { return matrix_->getNumElements(); }
29   /** Number of columns. */
30   virtual int getNumCols() const { return matrix_->getNumCols(); }
31   /** Number of rows. */
32  virtual int getNumRows() const { return matrix_->getNumRows(); };
33
34   /** A vector containing the elements in the packed matrix. Note that there
35        might be gaps in this list, entries that do not belong to any
36        major-dimension vector. To get the actual elements one should look at
37        this vector together with vectorStarts and vectorLengths. */
38   virtual const double * getElements() const 
39  { return matrix_->getElements();};
40   /** A vector containing the minor indices of the elements in the packed
41        matrix. Note that there might be gaps in this list, entries that do not
42        belong to any major-dimension vector. To get the actual elements one
43        should look at this vector together with vectorStarts and
44        vectorLengths. */
45   virtual const int * getIndices() const 
46  { return matrix_->getIndices();};
47
48   virtual const CoinBigIndex * getVectorStarts() const 
49  { return matrix_->getVectorStarts();};
50   /** The lengths of the major-dimension vectors. */
51   virtual const int * getVectorLengths() const 
52  { return matrix_->getVectorLengths();} ;
53
54    /** Delete the columns whose indices are listed in <code>indDel</code>. */
55    virtual void deleteCols(const int numDel, const int * indDel)
56  { matrix_->deleteCols(numDel,indDel);};
57    /** Delete the rows whose indices are listed in <code>indDel</code>. */
58    virtual void deleteRows(const int numDel, const int * indDel)
59  { matrix_->deleteRows(numDel,indDel);};
60  /** Replace the elements of a vector.  The indices remain the same.
61      This is only needed if scaling and a row copy is used.
62      At most the number specified will be replaced.
63      The index is between 0 and major dimension of matrix */
64  void replaceVector(const int index,
65                       const int numReplace, const double * newElements)
66      {matrix_->replaceVector(index,numReplace,newElements);};
67  /** Returns a new matrix in reverse order without gaps */
68  virtual ClpMatrixBase * reverseOrderedCopy() const;
69  /** Returns number of elements in basis
70      column is basic if entry >=0 */
71  virtual CoinBigIndex numberInBasis(const int * columnIsBasic) const ;
72  /// Fills in basis (Returns number of elements and updates numberBasic)
73  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
74                                const int * columnIsBasic, int & numberBasic,
75                                int * row, int * column,
76                                double * element) const ;
77  /** Creates scales for column copy (rowCopy in model may be modified)
78      returns non-zero if no scaling done */
79  virtual int scale(ClpSimplex * model) const ;
80  /** Checks if all elements are in valid range.  Can just
81      return true if you are not paranoid.  For Clp I will
82      probably expect no zeros.  Code can modify matrix to get rid of
83      small elements.
84  */
85  virtual bool allElementsInRange(ClpSimplex * model,
86                                  double smallest, double largest);
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 */
91  virtual void unpack(ClpSimplex * model,CoinIndexedVector * rowArray,
92                   int column) const ;
93  /** Adds multiple of a column into an CoinIndexedvector
94      You can use quickAdd to add to vector */
95  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
96                   int column, double multiplier) const ;
97   /// Allow any parts of a created CoinPackedMatrix to be deleted
98   virtual void releasePackedMatrix() const { };
99   //@}
100
101  /**@name Matrix times vector methods */
102  //@{
103    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
104        @pre <code>x</code> must be of size <code>numColumns()</code>
105        @pre <code>y</code> must be of size <code>numRows()</code> */
106  virtual void times(double scalar,
107                       const double * x, double * y) const;
108  /// And for scaling
109  virtual void times(double scalar,
110                     const double * x, double * y,
111                     const double * rowScale, 
112                     const double * columnScale) const;
113    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
114        @pre <code>x</code> must be of size <code>numRows()</code>
115        @pre <code>y</code> must be of size <code>numColumns()</code> */
116    virtual void transposeTimes(double scalar,
117                                const double * x, double * y) const;
118  /// And for scaling
119    virtual void transposeTimes(double scalar,
120                                const double * x, double * y,
121                                const double * rowScale, 
122                                const double * columnScale) const;
123    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
124        Can use y as temporary array (will be empty at end)
125        Squashes small elements and knows about ClpSimplex */
126  virtual void transposeTimes(const ClpSimplex * model, double scalar,
127                              const CoinIndexedVector * x,
128                              CoinIndexedVector * y,
129                              CoinIndexedVector * z) 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    This version uses row copy*/
134  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
135                              const CoinIndexedVector * x,
136                              CoinIndexedVector * y,
137                              CoinIndexedVector * z) const;
138    /** Return <code>x *A</code> in <code>z</code> but
139        just for indices in y.
140        Squashes small elements and knows about ClpSimplex */
141  virtual void subsetTransposeTimes(const ClpSimplex * model,
142                                    const CoinIndexedVector * x,
143                                    const CoinIndexedVector * y,
144                                    CoinIndexedVector * z) const;
145  //@}
146
147  /**@name Other */
148   //@{
149  /// Returns CoinPackedMatrix (non const)
150  inline CoinPackedMatrix * matrix() const { return matrix_;};
151   //@}
152
153
154  /**@name Constructors, destructor */
155   //@{
156   /** Default constructor. */
157   ClpPackedMatrix();
158   /** Destructor */
159   virtual ~ClpPackedMatrix();
160   //@}
161
162   /**@name Copy method */
163   //@{
164   /** The copy constructor. */
165   ClpPackedMatrix(const ClpPackedMatrix&);
166   /** The copy constructor from an CoinPackedMatrix. */
167   ClpPackedMatrix(const CoinPackedMatrix&);
168
169  /** This takes over ownership (for space reasons) */
170   ClpPackedMatrix(CoinPackedMatrix * matrix);
171
172   ClpPackedMatrix& operator=(const ClpPackedMatrix&);
173  /// Clone
174  virtual ClpMatrixBase * clone() const ;
175   //@}
176   
177   
178protected:
179   /**@name Data members
180      The data members are protected to allow access for derived classes. */
181   //@{
182  /// Data
183  CoinPackedMatrix * matrix_;
184   //@}
185};
186
187#endif
Note: See TracBrowser for help on using the repository browser.