source: stable/1.15/Clp/src/ClpNetworkMatrix.hpp @ 1949

Last change on this file since 1949 was 1665, checked in by lou, 9 years ago

Add EPL license notice in src.

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