source: trunk/Clp/src/ClpNetworkMatrix.hpp @ 1525

Last change on this file since 1525 was 1525, checked in by mjs, 10 years ago

Formatted .cpp, .hpp, .c, .h files with "astyle -A4 -p". This matches the formatting used in the grand CBC reorganization.

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