source: trunk/include/ClpPlusMinusOneMatrix.hpp @ 225

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

This should break everything

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 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 basis
59      column is basic if entry >=0 */
60  virtual CoinBigIndex numberInBasis(const int * columnIsBasic) const ;
61  /// Fills in basis (Returns number of elements and updates numberBasic)
62  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
63                                const int * columnIsBasic, int & numberBasic,
64                                int * row, int * column,
65                                double * element) const ;
66  /** If element NULL returns number of elements in column part of basis,
67      If not NULL fills in as well */
68  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
69                                 const int * whichColumn, 
70                                 int numberRowBasic,
71                                 int numberColumnBasic,
72                                 int * row, int * column,
73                                 double * element) const ;
74  /** Given positive integer weights for each row fills in sum of weights
75      for each column (and slack).
76      Returns weights vector
77  */
78  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
79  /** Returns largest and smallest elements of both signs.
80      Largest refers to largest absolute value.
81  */
82  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
83                       double & smallestPositive, double & largestPositive);
84  /** Unpacks a column into an CoinIndexedvector
85   */
86  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
87                   int column) const ;
88  /** Unpacks a column into an CoinIndexedvector
89   ** in packed foramt
90      Note that model is NOT const.  Bounds and objective could
91      be modified if doing column generation (just for this variable) */
92  virtual void unpackPacked(ClpSimplex * model,
93                            CoinIndexedVector * rowArray,
94                            int column) const;
95  /** Adds multiple of a column into an CoinIndexedvector
96      You can use quickAdd to add to vector */
97  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
98                   int column, double multiplier) const ;
99   /// Allow any parts of a created CoinMatrix to be deleted
100   virtual void releasePlusMinusOneMatrix() const { };
101   //@}
102
103  /**@name Matrix times vector methods */
104  //@{
105    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
106        @pre <code>x</code> must be of size <code>numColumns()</code>
107        @pre <code>y</code> must be of size <code>numRows()</code> */
108  virtual void times(double scalar,
109                       const double * x, double * y) const;
110  /// And for scaling
111  virtual void times(double scalar,
112                     const double * x, double * y,
113                     const double * rowScale, 
114                     const double * columnScale) const;
115    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
116        @pre <code>x</code> must be of size <code>numRows()</code>
117        @pre <code>y</code> must be of size <code>numColumns()</code> */
118    virtual void transposeTimes(double scalar,
119                                const double * x, double * y) const;
120  /// And for scaling
121    virtual void transposeTimes(double scalar,
122                                const double * x, double * y,
123                                const double * rowScale, 
124                                const double * columnScale) const;
125    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
126        Can use y as temporary array (will be empty at end)
127        Note - If x packed mode - then z packed mode
128        Squashes small elements and knows about ClpSimplex */
129  virtual void transposeTimes(const ClpSimplex * model, double scalar,
130                              const CoinIndexedVector * x,
131                              CoinIndexedVector * y,
132                              CoinIndexedVector * z) const;
133    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
134        Can use y as temporary array (will be empty at end)
135        Note - If x packed mode - then z packed mode
136        Squashes small elements and knows about ClpSimplex.
137    This version uses row copy*/
138  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
139                              const CoinIndexedVector * x,
140                              CoinIndexedVector * y,
141                              CoinIndexedVector * z) const;
142    /** Return <code>x *A</code> in <code>z</code> but
143        just for indices in y.
144        Note - If x packed mode - then z packed mode
145        Squashes small elements and knows about ClpSimplex */
146  virtual void subsetTransposeTimes(const ClpSimplex * model,
147                                    const CoinIndexedVector * x,
148                                    const CoinIndexedVector * y,
149                                    CoinIndexedVector * z) const;
150  //@}
151
152  /**@name Other */
153   //@{
154  /// Return starts of +1s
155  inline int * startPositive() const
156  { return startPositive_;};
157  /// Return starts of -1s
158  inline int * startNegative() const
159  { return startNegative_;};
160   //@}
161
162
163  /**@name Constructors, destructor */
164   //@{
165   /** Default constructor. */
166   ClpPlusMinusOneMatrix();
167   /** Destructor */
168   virtual ~ClpPlusMinusOneMatrix();
169   //@}
170
171   /**@name Copy method */
172   //@{
173   /** The copy constructor. */
174   ClpPlusMinusOneMatrix(const ClpPlusMinusOneMatrix&);
175   /** The copy constructor from an CoinPlusMinusOneMatrix. */
176   ClpPlusMinusOneMatrix(const CoinPackedMatrix&);
177  /** Subset constructor (without gaps).  Duplicates are allowed
178      and order is as given */
179  ClpPlusMinusOneMatrix (const ClpPlusMinusOneMatrix & wholeModel,
180                    int numberRows, const int * whichRows,
181                    int numberColumns, const int * whichColumns);
182
183   ClpPlusMinusOneMatrix& operator=(const ClpPlusMinusOneMatrix&);
184  /// Clone
185  virtual ClpMatrixBase * clone() const ;
186  /** Subset clone (without gaps).  Duplicates are allowed
187      and order is as given */
188  virtual ClpMatrixBase * subsetClone (
189                    int numberRows, const int * whichRows,
190                    int numberColumns, const int * whichColumns) const ;
191  /// pass in copy (object takes ownership)
192  void passInCopy(int numberRows, int numberColumns,
193                  bool columnOrdered, int * indices,
194                  int * startPositive, int * startNegative);
195   //@}
196   
197   
198protected:
199   /**@name Data members
200      The data members are protected to allow access for derived classes. */
201   //@{
202  /// For fake CoinPackedMatrix
203  mutable double * elements_;
204  mutable int * lengths_;
205  /// Start of +1's for each
206  int * startPositive_;
207  /// Start of -1's for each
208  int * startNegative_;
209  /// Data -1, then +1 rows in pairs (row==-1 if one entry)
210  int * indices_;
211  /// Number of rows
212  int numberRows_;
213  /// Number of columns
214  int numberColumns_;
215  /// True if column ordered
216  bool columnOrdered_;
217 
218   //@}
219};
220
221#endif
Note: See TracBrowser for help on using the repository browser.