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