source: trunk/include/ClpPackedMatrix.hpp @ 451

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

Changes to make a difficult problem faster (dual) + quadratic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.1 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 CoinPackedMatrix as derived from ClpMatrixBase.
12
13    It adds a few methods that know about model as well as matrix
14
15    For details see CoinPackedMatrix */
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);numberActiveColumns_ = matrix_->getNumCols();};
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);numberActiveColumns_ = matrix_->getNumCols();};
60  /// Append Columns
61  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns)
62  { matrix_->appendCols(number,columns);numberActiveColumns_ = matrix_->getNumCols();};
63  /// Append Rows
64  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows)
65  { matrix_->appendRows(number,rows);numberActiveColumns_ = matrix_->getNumCols();};
66  /** Replace the elements of a vector.  The indices remain the same.
67      This is only needed if scaling and a row copy is used.
68      At most the number specified will be replaced.
69      The index is between 0 and major dimension of matrix */
70  virtual void replaceVector(const int index,
71                       const int numReplace, const double * newElements)
72      {matrix_->replaceVector(index,numReplace,newElements);};
73  /** Returns a new matrix in reverse order without gaps */
74  virtual ClpMatrixBase * reverseOrderedCopy() const;
75  /** If element NULL returns number of elements in column part of basis,
76      If not NULL fills in as well */
77  virtual CoinBigIndex fillBasis(ClpSimplex * model,
78                                 const int * whichColumn, 
79                                 int numberRowBasic,
80                                 int & numberColumnBasic,
81                                 int * row, int * column,
82                                 double * element)  ;
83  /** Creates scales for column copy (rowCopy in model may be modified)
84      returns non-zero if no scaling done */
85  virtual int scale(ClpModel * model) const ;
86  /** Scales rowCopy if column copy scaled
87      Only called if scales already exist */
88  virtual void scaleRowCopy(ClpModel * model) const ;
89  /** Realy really scales column copy
90      Only called if scales already exist.
91      Up to user ro delete */
92  virtual ClpMatrixBase * scaledColumnCopy(ClpModel * model) const ;
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  /** Returns largest and smallest elements of both signs.
101      Largest refers to largest absolute value.
102  */
103  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
104                       double & smallestPositive, double & largestPositive);
105
106  /** Unpacks a column into an CoinIndexedvector
107   */
108  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
109                   int column) const ;
110  /** Unpacks a column into an CoinIndexedvector
111   ** in packed foramt
112      Note that model is NOT const.  Bounds and objective could
113      be modified if doing column generation (just for this variable) */
114  virtual void unpackPacked(ClpSimplex * model,
115                            CoinIndexedVector * rowArray,
116                            int column) const;
117  /** Adds multiple of a column into an CoinIndexedvector
118      You can use quickAdd to add to vector */
119  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
120                   int column, double multiplier) const ;
121  /** Adds multiple of a column into an array */
122  virtual void add(const ClpSimplex * model,double * array,
123                   int column, double multiplier) const;
124   /// Allow any parts of a created CoinPackedMatrix to be deleted
125   virtual void releasePackedMatrix() const { };
126  /** Given positive integer weights for each row fills in sum of weights
127      for each column (and slack).
128      Returns weights vector
129  */
130  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
131  /// Says whether it can do partial pricing
132  virtual bool canDoPartialPricing() const;
133  /// Partial pricing
134  virtual void partialPricing(ClpSimplex * model, double start, double end,
135                      int & bestSequence, int & numberWanted);
136  /// makes sure active columns correct
137  virtual int refresh(ClpSimplex * model);
138  // Really scale matrix
139  virtual void reallyScale(const double * rowScale, const double * columnScale);
140   //@}
141
142  /**@name Matrix times vector methods */
143  //@{
144    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
145        @pre <code>x</code> must be of size <code>numColumns()</code>
146        @pre <code>y</code> must be of size <code>numRows()</code> */
147  virtual void times(double scalar,
148                       const double * x, double * y) const;
149  /// And for scaling
150  virtual void times(double scalar,
151                     const double * x, double * y,
152                     const double * rowScale, 
153                     const double * columnScale) const;
154    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
155        @pre <code>x</code> must be of size <code>numRows()</code>
156        @pre <code>y</code> must be of size <code>numColumns()</code> */
157    virtual void transposeTimes(double scalar,
158                                const double * x, double * y) const;
159  /// And for scaling
160    virtual void transposeTimes(double scalar,
161                                const double * x, double * y,
162                                const double * rowScale, 
163                                const double * columnScale) const;
164    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
165        Can use y as temporary array (will be empty at end)
166        Note - If x packed mode - then z packed mode
167        Squashes small elements and knows about ClpSimplex */
168  virtual void transposeTimes(const ClpSimplex * model, double scalar,
169                              const CoinIndexedVector * x,
170                              CoinIndexedVector * y,
171                              CoinIndexedVector * z) const;
172    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
173        Note - If x packed mode - then z packed mode
174        This does by column and knows no gaps
175        Squashes small elements and knows about ClpSimplex */
176  void transposeTimesByColumn(const ClpSimplex * model, double scalar,
177                              const CoinIndexedVector * x,
178                              CoinIndexedVector * y,
179                              CoinIndexedVector * z) const;
180    /** Return <code>x * scalar * A in <code>z</code>.
181        Note - this version when x packed mode and so will be z
182        This does by column and knows no gaps and knows y empty
183        Squashes small elements and knows about ClpSimplex */
184  void transposeTimesByColumn(const ClpSimplex * model, double scalar,
185                              const CoinIndexedVector * x,
186                              CoinIndexedVector * z) const;
187    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
188        Can use y as temporary array (will be empty at end)
189        Note - If x packed mode - then z packed mode
190        Squashes small elements and knows about ClpSimplex.
191    This version uses row copy*/
192  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
193                              const CoinIndexedVector * x,
194                              CoinIndexedVector * y,
195                              CoinIndexedVector * z) const;
196    /** Return <code>x *A</code> in <code>z</code> but
197        just for indices in y.
198        Note - z always packed mode */
199  virtual void subsetTransposeTimes(const ClpSimplex * model,
200                                    const CoinIndexedVector * x,
201                                    const CoinIndexedVector * y,
202                                    CoinIndexedVector * z) const;
203  /// Sets up an effective RHS
204  void useEffectiveRhs(ClpSimplex * model);
205//@}
206
207  /**@name Other */
208   //@{
209  /// Returns CoinPackedMatrix (non const)
210  inline CoinPackedMatrix * matrix() const { return matrix_;};
211  /** Just sets matrix_ to NULL so it can be used elsewhere.
212      used in GUB
213  */
214  inline void setMatrixNull()
215  { matrix_=NULL;};
216   //@}
217
218
219  /**@name Constructors, destructor */
220   //@{
221   /** Default constructor. */
222   ClpPackedMatrix();
223   /** Destructor */
224   virtual ~ClpPackedMatrix();
225   //@}
226
227   /**@name Copy method */
228   //@{
229   /** The copy constructor. */
230   ClpPackedMatrix(const ClpPackedMatrix&);
231   /** The copy constructor from an CoinPackedMatrix. */
232   ClpPackedMatrix(const CoinPackedMatrix&);
233  /** Subset constructor (without gaps).  Duplicates are allowed
234      and order is as given */
235  ClpPackedMatrix (const ClpPackedMatrix & wholeModel,
236                    int numberRows, const int * whichRows,
237                    int numberColumns, const int * whichColumns);
238  ClpPackedMatrix (const CoinPackedMatrix & wholeModel,
239                    int numberRows, const int * whichRows,
240                    int numberColumns, const int * whichColumns);
241
242  /** This takes over ownership (for space reasons) */
243   ClpPackedMatrix(CoinPackedMatrix * matrix);
244
245   ClpPackedMatrix& operator=(const ClpPackedMatrix&);
246  /// Clone
247  virtual ClpMatrixBase * clone() const ;
248  /** Subset clone (without gaps).  Duplicates are allowed
249      and order is as given */
250  virtual ClpMatrixBase * subsetClone (
251                    int numberRows, const int * whichRows,
252                    int numberColumns, const int * whichColumns) const ;
253   //@}
254   
255   
256protected:
257   /**@name Data members
258      The data members are protected to allow access for derived classes. */
259   //@{
260  /// Data
261  CoinPackedMatrix * matrix_;
262  /// number of active columns (normally same as number of columns)
263  int numberActiveColumns_;
264  /// Zero element flag - set true if any zero elements
265  bool zeroElements_;
266  /// Gaps flag - set true if column start and length don't say contiguous
267  bool hasGaps_;
268   //@}
269};
270
271#endif
Note: See TracBrowser for help on using the repository browser.