source: trunk/Clp/src/ClpNetworkMatrix.hpp

Last change on this file was 2385, checked in by unxusr, 11 months ago

formatting

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