source: branches/unlabeled-1.1.2/include/ClpPlusMinusOneMatrix.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: 6.5 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  /** Returns a new matrix in reverse order without gaps */
53  virtual ClpMatrixBase * reverseOrderedCopy() const;
54  /** Returns number of elements in basis
55      column is basic if entry >=0 */
56  virtual CoinBigIndex numberInBasis(const int * columnIsBasic) const ;
57  /// Fills in basis (Returns number of elements and updates numberBasic)
58  virtual CoinBigIndex fillBasis(const ClpSimplex * model,
59                                const int * columnIsBasic, int & numberBasic,
60                                int * row, int * column,
61                                double * element) const ;
62  /** Unpacks a column into an CoinIndexedvector
63      Note that model is NOT const.  Bounds and objective could
64      be modified if doing column generation */
65  virtual void unpack(ClpSimplex * model,CoinIndexedVector * rowArray,
66                   int column) const ;
67  /** Adds multiple of a column into an CoinIndexedvector
68      You can use quickAdd to add to vector */
69  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
70                   int column, double multiplier) const ;
71   /// Allow any parts of a created CoinMatrix to be deleted
72   virtual void releasePlusMinusOneMatrix() const { };
73   //@}
74
75  /**@name Matrix times vector methods */
76  //@{
77    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
78        @pre <code>x</code> must be of size <code>numColumns()</code>
79        @pre <code>y</code> must be of size <code>numRows()</code> */
80  virtual void times(double scalar,
81                       const double * x, double * y) const;
82  /// And for scaling
83  virtual void times(double scalar,
84                     const double * x, double * y,
85                     const double * rowScale, 
86                     const double * columnScale) const;
87    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
88        @pre <code>x</code> must be of size <code>numRows()</code>
89        @pre <code>y</code> must be of size <code>numColumns()</code> */
90    virtual void transposeTimes(double scalar,
91                                const double * x, double * y) const;
92  /// And for scaling
93    virtual void transposeTimes(double scalar,
94                                const double * x, double * y,
95                                const double * rowScale, 
96                                const double * columnScale) const;
97    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
98        Can use y as temporary array (will be empty at end)
99        Squashes small elements and knows about ClpSimplex */
100  virtual void transposeTimes(const ClpSimplex * model, double scalar,
101                              const CoinIndexedVector * x,
102                              CoinIndexedVector * y,
103                              CoinIndexedVector * z) const;
104    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
105        Can use y as temporary array (will be empty at end)
106        Squashes small elements and knows about ClpSimplex.
107    This version uses row copy*/
108  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
109                              const CoinIndexedVector * x,
110                              CoinIndexedVector * y,
111                              CoinIndexedVector * z) const;
112    /** Return <code>x *A</code> in <code>z</code> but
113        just for indices in y.
114        Squashes small elements and knows about ClpSimplex */
115  virtual void subsetTransposeTimes(const ClpSimplex * model,
116                                    const CoinIndexedVector * x,
117                                    const CoinIndexedVector * y,
118                                    CoinIndexedVector * z) const;
119  //@}
120
121  /**@name Other */
122   //@{
123  /// Return starts of +1s
124  inline int * startPositive() const
125  { return startPositive_;};
126  /// Return starts of -1s
127  inline int * startNegative() const
128  { return startNegative_;};
129   //@}
130
131
132  /**@name Constructors, destructor */
133   //@{
134   /** Default constructor. */
135   ClpPlusMinusOneMatrix();
136   /** Destructor */
137   virtual ~ClpPlusMinusOneMatrix();
138   //@}
139
140   /**@name Copy method */
141   //@{
142   /** The copy constructor. */
143   ClpPlusMinusOneMatrix(const ClpPlusMinusOneMatrix&);
144   /** The copy constructor from an CoinPlusMinusOneMatrix. */
145   ClpPlusMinusOneMatrix(const CoinPackedMatrix&);
146
147   ClpPlusMinusOneMatrix& operator=(const ClpPlusMinusOneMatrix&);
148  /// Clone
149  virtual ClpMatrixBase * clone() const ;
150  /// pass in copy (object takes ownership)
151  void passInCopy(int numberRows, int numberColumns,
152                  bool columnOrdered, int * indices,
153                  int * startPositive, int * startNegative);
154   //@}
155   
156   
157protected:
158   /**@name Data members
159      The data members are protected to allow access for derived classes. */
160   //@{
161  /// For fake CoinPackedMatrix
162  mutable double * elements_;
163  mutable int * lengths_;
164  /// Start of +1's for each
165  int * startPositive_;
166  /// Start of -1's for each
167  int * startNegative_;
168  /// Data -1, then +1 rows in pairs (row==-1 if one entry)
169  int * indices_;
170  /// Number of rows
171  int numberRows_;
172  /// Number of columns
173  int numberColumns_;
174  /// True if column ordered
175  bool columnOrdered_;
176 
177   //@}
178};
179
180#endif
Note: See TracBrowser for help on using the repository browser.