source: trunk/Clp/src/ClpPlusMinusOneMatrix.hpp @ 800

Last change on this file since 800 was 800, checked in by ladanyi, 14 years ago

finishing conversion to svn

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.3 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  // and for advanced use
44  int * getMutableIndices() const
45  { return indices_;};
46
47  virtual const CoinBigIndex * getVectorStarts() const;
48   /** The lengths of the major-dimension vectors. */
49  virtual const int * getVectorLengths() const;
50
51    /** Delete the columns whose indices are listed in <code>indDel</code>. */
52  virtual void deleteCols(const int numDel, const int * indDel);
53    /** Delete the rows whose indices are listed in <code>indDel</code>. */
54  virtual void deleteRows(const int numDel, const int * indDel);
55  /// Append Columns
56  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
57  /// Append Rows
58  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
59#ifndef SLIM_CLP
60  /** Append a set of rows/columns to the end of the matrix. Returns number of errors
61      i.e. if any of the new rows/columns contain an index that's larger than the
62      number of columns-1/rows-1 (if numberOther>0) or duplicates
63      If 0 then rows, 1 if columns */
64  virtual int appendMatrix(int number, int type,
65                           const CoinBigIndex * starts, const int * index,
66                           const double * element, int numberOther=-1);
67#endif
68  /** Returns a new matrix in reverse order without gaps */
69  virtual ClpMatrixBase * reverseOrderedCopy() const;
70  /// Returns number of elements in column part of basis
71  virtual CoinBigIndex countBasis(ClpSimplex * model,
72                                 const int * whichColumn, 
73                                 int numberRowBasic,
74                                  int & numberColumnBasic);
75  /// Fills in column part of basis
76  virtual void fillBasis(ClpSimplex * model,
77                                 const int * whichColumn, 
78                                 int & numberColumnBasic,
79                                 int * row, int * start,
80                                 int * rowCount, int * columnCount,
81                                 double * element);
82  /** Given positive integer weights for each row fills in sum of weights
83      for each column (and slack).
84      Returns weights vector
85  */
86  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
87  /** Returns largest and smallest elements of both signs.
88      Largest refers to largest absolute value.
89  */
90  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
91                       double & smallestPositive, double & largestPositive);
92  /** Unpacks a column into an CoinIndexedvector
93   */
94  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
95                   int column) const ;
96  /** Unpacks a column into an CoinIndexedvector
97   ** in packed foramt
98      Note that model is NOT const.  Bounds and objective could
99      be modified if doing column generation (just for this variable) */
100  virtual void unpackPacked(ClpSimplex * model,
101                            CoinIndexedVector * rowArray,
102                            int column) const;
103  /** Adds multiple of a column into an CoinIndexedvector
104      You can use quickAdd to add to vector */
105  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
106                   int column, double multiplier) const ;
107  /** Adds multiple of a column into an array */
108  virtual void add(const ClpSimplex * model,double * array,
109                   int column, double multiplier) const;
110   /// Allow any parts of a created CoinMatrix to be deleted
111   virtual void releasePackedMatrix() const;
112  /** Set the dimensions of the matrix. In effect, append new empty
113      columns/rows to the matrix. A negative number for either dimension
114      means that that dimension doesn't change. Otherwise the new dimensions
115      MUST be at least as large as the current ones otherwise an exception
116      is thrown. */
117  virtual void setDimensions(int numrows, int numcols);
118  /// Just checks matrix valid - will say if dimensions not quite right if detail
119  void checkValid(bool detail) const;
120   //@}
121
122  /**@name Matrix times vector methods */
123  //@{
124    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
125        @pre <code>x</code> must be of size <code>numColumns()</code>
126        @pre <code>y</code> must be of size <code>numRows()</code> */
127  virtual void times(double scalar,
128                       const double * x, double * y) const;
129  /// And for scaling
130  virtual void times(double scalar,
131                     const double * x, double * y,
132                     const double * rowScale, 
133                     const double * columnScale) const;
134    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
135        @pre <code>x</code> must be of size <code>numRows()</code>
136        @pre <code>y</code> must be of size <code>numColumns()</code> */
137    virtual void transposeTimes(double scalar,
138                                const double * x, double * y) const;
139  /// And for scaling
140    virtual void transposeTimes(double scalar,
141                                const double * x, double * y,
142                                const double * rowScale, 
143                                const double * columnScale) const;
144    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
145        Can use y as temporary array (will be empty at end)
146        Note - If x packed mode - then z packed mode
147        Squashes small elements and knows about ClpSimplex */
148  virtual void transposeTimes(const ClpSimplex * model, double scalar,
149                              const CoinIndexedVector * x,
150                              CoinIndexedVector * y,
151                              CoinIndexedVector * z) const;
152    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
153        Can use y as temporary array (will be empty at end)
154        Note - If x packed mode - then z packed mode
155        Squashes small elements and knows about ClpSimplex.
156    This version uses row copy*/
157  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
158                              const CoinIndexedVector * x,
159                              CoinIndexedVector * y,
160                              CoinIndexedVector * z) const;
161    /** Return <code>x *A</code> in <code>z</code> but
162        just for indices in y.
163        Note - z always packed mode */
164  virtual void subsetTransposeTimes(const ClpSimplex * model,
165                                    const CoinIndexedVector * x,
166                                    const CoinIndexedVector * y,
167                                    CoinIndexedVector * z) const;
168  /** Returns true if can combine transposeTimes and subsetTransposeTimes
169      and if it would be faster */
170  virtual bool canCombine(const ClpSimplex * model,
171                          const CoinIndexedVector * pi) const;
172  /// Updates two arrays for steepest
173  virtual void transposeTimes2(const ClpSimplex * model,
174                               const CoinIndexedVector * pi1, CoinIndexedVector * dj1,
175                               const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
176                               CoinIndexedVector * spare,
177                               double referenceIn, double devex,
178                               // Array for exact devex to say what is in reference framework
179                               unsigned int * reference,
180                               double * weights, double scaleFactor);
181  /// Updates second array for steepest and does devex weights
182  virtual void subsetTimes2(const ClpSimplex * model,
183                                CoinIndexedVector * dj1,
184                               const CoinIndexedVector * pi2, CoinIndexedVector * dj2,
185                               double referenceIn, double devex,
186                               // Array for exact devex to say what is in reference framework
187                               unsigned int * reference,
188                               double * weights, double scaleFactor);
189  //@}
190
191  /**@name Other */
192   //@{
193  /// Return starts of +1s
194  inline CoinBigIndex * startPositive() const
195  { return startPositive_;};
196  /// Return starts of -1s
197  inline CoinBigIndex * startNegative() const
198  { return startNegative_;};
199   //@}
200
201
202  /**@name Constructors, destructor */
203   //@{
204   /** Default constructor. */
205   ClpPlusMinusOneMatrix();
206   /** Destructor */
207   virtual ~ClpPlusMinusOneMatrix();
208   //@}
209
210   /**@name Copy method */
211   //@{
212   /** The copy constructor. */
213   ClpPlusMinusOneMatrix(const ClpPlusMinusOneMatrix&);
214   /** The copy constructor from an CoinPlusMinusOneMatrix.
215       If not a valid matrix then getIndices will be NULL and
216       startPositive[0] will have number of +1,
217       startPositive[1] will have number of -1,
218       startPositive[2] will have number of others,
219   */
220   ClpPlusMinusOneMatrix(const CoinPackedMatrix&);
221  /// Constructor from arrays
222  ClpPlusMinusOneMatrix(int numberRows, int numberColumns,
223                        bool columnOrdered, const int * indices,
224                        const CoinBigIndex * startPositive, const CoinBigIndex * startNegative);
225  /** Subset constructor (without gaps).  Duplicates are allowed
226      and order is as given */
227  ClpPlusMinusOneMatrix (const ClpPlusMinusOneMatrix & wholeModel,
228                    int numberRows, const int * whichRows,
229                    int numberColumns, const int * whichColumns);
230
231   ClpPlusMinusOneMatrix& operator=(const ClpPlusMinusOneMatrix&);
232  /// Clone
233  virtual ClpMatrixBase * clone() const ;
234  /** Subset clone (without gaps).  Duplicates are allowed
235      and order is as given */
236  virtual ClpMatrixBase * subsetClone (
237                    int numberRows, const int * whichRows,
238                    int numberColumns, const int * whichColumns) const ;
239  /// pass in copy (object takes ownership)
240  void passInCopy(int numberRows, int numberColumns,
241                  bool columnOrdered, int * indices,
242                  CoinBigIndex * startPositive, CoinBigIndex * startNegative);
243  /// Says whether it can do partial pricing
244  virtual bool canDoPartialPricing() const;
245  /// Partial pricing
246  virtual void partialPricing(ClpSimplex * model, double start, double end,
247                      int & bestSequence, int & numberWanted);
248   //@}
249   
250   
251protected:
252   /**@name Data members
253      The data members are protected to allow access for derived classes. */
254   //@{
255  /// For fake CoinPackedMatrix
256  mutable double * elements_;
257  mutable int * lengths_;
258  /// Start of +1's for each
259  CoinBigIndex * startPositive_;
260  /// Start of -1's for each
261  CoinBigIndex * startNegative_;
262  /// Data -1, then +1 rows in pairs (row==-1 if one entry)
263  int * indices_;
264  /// Number of rows
265  int numberRows_;
266  /// Number of columns
267  int numberColumns_;
268  /// True if column ordered
269  bool columnOrdered_;
270 
271   //@}
272};
273
274#endif
Note: See TracBrowser for help on using the repository browser.