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

Last change on this file since 1304 was 1302, checked in by forrest, 12 years ago

adding possibility of long doubles

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 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  /// Append Columns
55  virtual void appendCols(int number, const CoinPackedVectorBase * const * columns);
56  /// Append Rows
57  virtual void appendRows(int number, const CoinPackedVectorBase * const * rows);
58#ifndef SLIM_CLP
59  /** Append a set of rows/columns to the end of the matrix. Returns number of errors
60      i.e. if any of the new rows/columns contain an index that's larger than the
61      number of columns-1/rows-1 (if numberOther>0) or duplicates
62      If 0 then rows, 1 if columns */
63  virtual int appendMatrix(int number, int type,
64                           const CoinBigIndex * starts, const int * index,
65                           const double * element, int numberOther=-1);
66#endif
67  /** Returns a new matrix in reverse order without gaps */
68  virtual ClpMatrixBase * reverseOrderedCopy() const;
69  /// Returns number of elements in column part of basis
70  virtual CoinBigIndex countBasis(ClpSimplex * model,
71                                 const int * whichColumn, 
72                                 int numberRowBasic,
73                                  int & numberColumnBasic);
74  /// Fills in column part of basis
75  virtual void fillBasis(ClpSimplex * model,
76                                 const int * whichColumn, 
77                                 int & numberColumnBasic,
78                                 int * row, int * start,
79                                 int * rowCount, int * columnCount,
80                                 CoinFactorizationDouble * element);
81  /** Given positive integer weights for each row fills in sum of weights
82      for each column (and slack).
83      Returns weights vector
84  */
85  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
86  /** Returns largest and smallest elements of both signs.
87      Largest refers to largest absolute value.
88  */
89  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
90                       double & smallestPositive, double & largestPositive);
91  /** Unpacks a column into an CoinIndexedvector
92   */
93  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
94                   int column) const ;
95  /** Unpacks a column into an CoinIndexedvector
96   ** in packed format
97      Note that model is NOT const.  Bounds and objective could
98      be modified if doing column generation (just for this variable) */
99  virtual void unpackPacked(ClpSimplex * model,
100                            CoinIndexedVector * rowArray,
101                            int column) const;
102  /** Adds multiple of a column into an CoinIndexedvector
103      You can use quickAdd to add to vector */
104  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
105                   int column, double multiplier) const ;
106  /** Adds multiple of a column into an array */
107  virtual void add(const ClpSimplex * model,double * array,
108                   int column, double multiplier) const;
109   /// Allow any parts of a created CoinMatrix to be deleted
110   virtual void releasePackedMatrix() const ;
111  /// Says whether it can do partial pricing
112  virtual bool canDoPartialPricing() const;
113  /// Partial pricing
114  virtual void partialPricing(ClpSimplex * model, double start, double end,
115                      int & bestSequence, int & numberWanted);
116   //@}
117
118  /**@name Matrix times vector methods */
119  //@{
120    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
121        @pre <code>x</code> must be of size <code>numColumns()</code>
122        @pre <code>y</code> must be of size <code>numRows()</code> */
123  virtual void times(double scalar,
124                       const double * x, double * y) const;
125  /// And for scaling
126  virtual void times(double scalar,
127                     const double * x, double * y,
128                     const double * rowScale, 
129                     const double * columnScale) const;
130    /** Return <code>y + x * scalar * A</code> in <code>y</code>.
131        @pre <code>x</code> must be of size <code>numRows()</code>
132        @pre <code>y</code> must be of size <code>numColumns()</code> */
133    virtual void transposeTimes(double scalar,
134                                const double * x, double * y) const;
135  /// And for scaling
136    virtual void transposeTimes(double scalar,
137                                const double * x, double * y,
138                                const double * rowScale, 
139                                const double * columnScale, double * spare=NULL) const;
140    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
141        Can use y as temporary array (will be empty at end)
142        Note - If x packed mode - then z packed mode
143        Squashes small elements and knows about ClpSimplex */
144  virtual void transposeTimes(const ClpSimplex * model, double scalar,
145                              const CoinIndexedVector * x,
146                              CoinIndexedVector * y,
147                              CoinIndexedVector * z) const;
148    /** Return <code>x *A</code> in <code>z</code> but
149        just for indices in y.
150        Note - z always packed mode */
151  virtual void subsetTransposeTimes(const ClpSimplex * model,
152                                    const CoinIndexedVector * x,
153                                    const CoinIndexedVector * y,
154                                    CoinIndexedVector * z) const;
155  //@}
156
157  /**@name Other */
158   //@{
159  /// Return true if really network, false if has slacks
160  inline bool trueNetwork() const
161  { return trueNetwork_;}
162   //@}
163
164
165  /**@name Constructors, destructor */
166   //@{
167   /** Default constructor. */
168   ClpNetworkMatrix();
169  /** Constructor from two arrays */
170  ClpNetworkMatrix(int numberColumns, const int * head,
171                   const int * tail);
172   /** Destructor */
173   virtual ~ClpNetworkMatrix();
174   //@}
175
176   /**@name Copy method */
177   //@{
178   /** The copy constructor. */
179   ClpNetworkMatrix(const ClpNetworkMatrix&);
180   /** The copy constructor from an CoinNetworkMatrix. */
181   ClpNetworkMatrix(const CoinPackedMatrix&);
182
183   ClpNetworkMatrix& operator=(const ClpNetworkMatrix&);
184  /// Clone
185  virtual ClpMatrixBase * clone() const ;
186  /** Subset constructor (without gaps).  Duplicates are allowed
187      and order is as given */
188  ClpNetworkMatrix (const ClpNetworkMatrix & wholeModel,
189                    int numberRows, const int * whichRows,
190                    int numberColumns, const int * whichColumns);
191  /** Subset clone (without gaps).  Duplicates are allowed
192      and order is as given */
193  virtual ClpMatrixBase * subsetClone (
194                    int numberRows, const int * whichRows,
195                    int numberColumns, const int * whichColumns) const ;
196   //@}
197   
198   
199protected:
200   /**@name Data members
201      The data members are protected to allow access for derived classes. */
202   //@{
203  /// For fake CoinPackedMatrix
204  mutable CoinPackedMatrix * matrix_;
205  mutable int * lengths_;
206  /// Data -1, then +1 rows in pairs (row==-1 if one entry)
207  int * indices_;
208  /// Number of rows
209  int numberRows_;
210  /// Number of columns
211  int numberColumns_;
212  /// True if all entries have two elements
213  bool trueNetwork_;
214 
215   //@}
216};
217
218#endif
Note: See TracBrowser for help on using the repository browser.