source: branches/pre/include/ClpNetworkMatrix.hpp @ 223

Last change on this file since 223 was 223, checked in by forrest, 17 years ago

Stuff

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