source: trunk/include/ClpPlusMinusOneMatrix.hpp @ 461

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

Trying to make faster

  • 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) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpPlusMinusOneMatrix_H
4#define ClpPlusMinusOneMatrix_H
5
6
7#include "CoinPragma.hpp"
8
9#include "ClpMatrixBase.hpp"
10
11/** This implements a simple +- one matrix as derived from ClpMatrixBase.
12
13*/
14
15class ClpPlusMinusOneMatrix : public ClpMatrixBase {
16 
17public:
18  /**@name Useful methods */
19   //@{
20   /// Return a complete CoinPackedMatrix
21   virtual CoinPackedMatrix * getPackedMatrix() const;
22    /** Whether the packed matrix is column major ordered or not. */
23  virtual bool isColOrdered() const ;
24   /** Number of entries in the packed matrix. */
25  virtual  CoinBigIndex getNumElements() const; 
26   /** Number of columns. */
27   virtual int getNumCols() const { return numberColumns_; }
28   /** Number of rows. */
29  virtual int getNumRows() const { return numberRows_; };
30
31   /** A vector containing the elements in the packed matrix. Note that there
32        might be gaps in this list, entries that do not belong to any
33        major-dimension vector. To get the actual elements one should look at
34        this vector together with vectorStarts and vectorLengths. */
35  virtual const double * getElements() const; 
36   /** A vector containing the minor indices of the elements in the packed
37        matrix. Note that there might be gaps in this list, entries that do not
38        belong to any major-dimension vector. To get the actual elements one
39        should look at this vector together with vectorStarts and
40        vectorLengths. */
41  virtual const int * getIndices() const
42  { return indices_;};
43
44  virtual const CoinBigIndex * getVectorStarts() const;
45   /** The lengths of the major-dimension vectors. */
46  virtual const int * getVectorLengths() const;
47
48    /** Delete the columns whose indices are listed in <code>indDel</code>. */
49  virtual void deleteCols(const int numDel, const int * indDel);
50    /** Delete the rows whose indices are listed in <code>indDel</code>. */
51  virtual void deleteRows(const int numDel, const int * indDel);
52  /// Append Columns
53  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
54  /// Append Rows
55  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
56  /** Returns a new matrix in reverse order without gaps */
57  virtual ClpMatrixBase * reverseOrderedCopy() const;
58  /// Returns number of elements in column part of basis
59  virtual CoinBigIndex countBasis(ClpSimplex * model,
60                                 const int * whichColumn, 
61                                 int numberRowBasic,
62                                  int & numberColumnBasic);
63  /// Fills in column part of basis
64  virtual void fillBasis(ClpSimplex * model,
65                                 const int * whichColumn, 
66                                 int & numberColumnBasic,
67                                 int * row, int * start,
68                                 int * rowCount, int * columnCount,
69                                 double * element);
70  /** Given positive integer weights for each row fills in sum of weights
71      for each column (and slack).
72      Returns weights vector
73  */
74  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
75  /** Returns largest and smallest elements of both signs.
76      Largest refers to largest absolute value.
77  */
78  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
79                       double & smallestPositive, double & largestPositive);
80  /** Unpacks a column into an CoinIndexedvector
81   */
82  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
83                   int column) const ;
84  /** Unpacks a column into an CoinIndexedvector
85   ** in packed foramt
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 unpackPacked(ClpSimplex * model,
89                            CoinIndexedVector * rowArray,
90                            int column) const;
91  /** Adds multiple of a column into an CoinIndexedvector
92      You can use quickAdd to add to vector */
93  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
94                   int column, double multiplier) const ;
95  /** Adds multiple of a column into an array */
96  virtual void add(const ClpSimplex * model,double * array,
97                   int column, double multiplier) const;
98   /// Allow any parts of a created CoinMatrix to be deleted
99   virtual void releasePackedMatrix() const;
100   //@}
101
102  /**@name Matrix times vector methods */
103  //@{
104    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
105        @pre <code>x</code> must be of size <code>numColumns()</code>
106        @pre <code>y</code> must be of size <code>numRows()</code> */
107  virtual void times(double scalar,
108                       const double * x, double * y) const;
109  /// And for scaling
110  virtual void times(double scalar,
111                     const double * x, double * y,
112                     const double * rowScale, 
113                     const double * columnScale) const;
114    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
115        @pre <code>x</code> must be of size <code>numRows()</code>
116        @pre <code>y</code> must be of size <code>numColumns()</code> */
117    virtual void transposeTimes(double scalar,
118                                const double * x, double * y) const;
119  /// And for scaling
120    virtual void transposeTimes(double scalar,
121                                const double * x, double * y,
122                                const double * rowScale, 
123                                const double * columnScale) const;
124    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
125        Can use y as temporary array (will be empty at end)
126        Note - If x packed mode - then z packed mode
127        Squashes small elements and knows about ClpSimplex */
128  virtual void transposeTimes(const ClpSimplex * model, double scalar,
129                              const CoinIndexedVector * x,
130                              CoinIndexedVector * y,
131                              CoinIndexedVector * z) const;
132    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
133        Can use y as temporary array (will be empty at end)
134        Note - If x packed mode - then z packed mode
135        Squashes small elements and knows about ClpSimplex.
136    This version uses row copy*/
137  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
138                              const CoinIndexedVector * x,
139                              CoinIndexedVector * y,
140                              CoinIndexedVector * z) const;
141    /** Return <code>x *A</code> in <code>z</code> but
142        just for indices in y.
143        Note - z always packed mode */
144  virtual void subsetTransposeTimes(const ClpSimplex * model,
145                                    const CoinIndexedVector * x,
146                                    const CoinIndexedVector * y,
147                                    CoinIndexedVector * z) const;
148  //@}
149
150  /**@name Other */
151   //@{
152  /// Return starts of +1s
153  inline CoinBigIndex * startPositive() const
154  { return startPositive_;};
155  /// Return starts of -1s
156  inline CoinBigIndex * startNegative() const
157  { return startNegative_;};
158   //@}
159
160
161  /**@name Constructors, destructor */
162   //@{
163   /** Default constructor. */
164   ClpPlusMinusOneMatrix();
165   /** Destructor */
166   virtual ~ClpPlusMinusOneMatrix();
167   //@}
168
169   /**@name Copy method */
170   //@{
171   /** The copy constructor. */
172   ClpPlusMinusOneMatrix(const ClpPlusMinusOneMatrix&);
173   /** The copy constructor from an CoinPlusMinusOneMatrix. */
174   ClpPlusMinusOneMatrix(const CoinPackedMatrix&);
175  /// Constructor from arrays
176  ClpPlusMinusOneMatrix(int numberRows, int numberColumns,
177                        bool columnOrdered, const int * indices,
178                        const CoinBigIndex * startPositive, const CoinBigIndex * startNegative);
179  /** Subset constructor (without gaps).  Duplicates are allowed
180      and order is as given */
181  ClpPlusMinusOneMatrix (const ClpPlusMinusOneMatrix & wholeModel,
182                    int numberRows, const int * whichRows,
183                    int numberColumns, const int * whichColumns);
184
185   ClpPlusMinusOneMatrix& operator=(const ClpPlusMinusOneMatrix&);
186  /// Clone
187  virtual ClpMatrixBase * clone() const ;
188  /** Subset clone (without gaps).  Duplicates are allowed
189      and order is as given */
190  virtual ClpMatrixBase * subsetClone (
191                    int numberRows, const int * whichRows,
192                    int numberColumns, const int * whichColumns) const ;
193  /// pass in copy (object takes ownership)
194  void passInCopy(int numberRows, int numberColumns,
195                  bool columnOrdered, int * indices,
196                  CoinBigIndex * startPositive, CoinBigIndex * startNegative);
197  /// Says whether it can do partial pricing
198  virtual bool canDoPartialPricing() const;
199  /// Partial pricing
200  virtual void partialPricing(ClpSimplex * model, double start, double end,
201                      int & bestSequence, int & numberWanted);
202   //@}
203   
204   
205protected:
206   /**@name Data members
207      The data members are protected to allow access for derived classes. */
208   //@{
209  /// For fake CoinPackedMatrix
210  mutable double * elements_;
211  mutable int * lengths_;
212  /// Start of +1's for each
213  CoinBigIndex * startPositive_;
214  /// Start of -1's for each
215  CoinBigIndex * startNegative_;
216  /// Data -1, then +1 rows in pairs (row==-1 if one entry)
217  int * indices_;
218  /// Number of rows
219  int numberRows_;
220  /// Number of columns
221  int numberColumns_;
222  /// True if column ordered
223  bool columnOrdered_;
224 
225   //@}
226};
227
228#endif
Note: See TracBrowser for help on using the repository browser.