source: trunk/include/ClpNetworkMatrix.hpp @ 451

Last change on this file since 451 was 451, checked in by forrest, 16 years ago

Changes to make a difficult problem faster (dual) + quadratic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 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  /** If element NULL returns number of elements in column part of basis,
57      If not NULL fills in as well */
58  virtual CoinBigIndex fillBasis(ClpSimplex * model,
59                                 const int * whichColumn, 
60                                 int numberRowBasic,
61                                 int & numberColumnBasic,
62                                 int * row, int * column,
63                                 double * element)  ;
64  /** Given positive integer weights for each row fills in sum of weights
65      for each column (and slack).
66      Returns weights vector
67  */
68  virtual CoinBigIndex * dubiousWeights(const ClpSimplex * model,int * inputWeights) const;
69  /** Returns largest and smallest elements of both signs.
70      Largest refers to largest absolute value.
71  */
72  virtual void rangeOfElements(double & smallestNegative, double & largestNegative,
73                       double & smallestPositive, double & largestPositive);
74  /** Unpacks a column into an CoinIndexedvector
75   */
76  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
77                   int column) const ;
78  /** Unpacks a column into an CoinIndexedvector
79   ** in packed format
80      Note that model is NOT const.  Bounds and objective could
81      be modified if doing column generation (just for this variable) */
82  virtual void unpackPacked(ClpSimplex * model,
83                            CoinIndexedVector * rowArray,
84                            int column) const;
85  /** Adds multiple of a column into an CoinIndexedvector
86      You can use quickAdd to add to vector */
87  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
88                   int column, double multiplier) const ;
89  /** Adds multiple of a column into an array */
90  virtual void add(const ClpSimplex * model,double * array,
91                   int column, double multiplier) const;
92   /// Allow any parts of a created CoinMatrix to be deleted
93   virtual void releasePackedMatrix() const ;
94  /// Says whether it can do partial pricing
95  virtual bool canDoPartialPricing() const;
96  /// Partial pricing
97  virtual void partialPricing(ClpSimplex * model, double start, double end,
98                      int & bestSequence, int & numberWanted);
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 - z always packed mode */
134  virtual void subsetTransposeTimes(const ClpSimplex * model,
135                                    const CoinIndexedVector * x,
136                                    const CoinIndexedVector * y,
137                                    CoinIndexedVector * z) const;
138  //@}
139
140  /**@name Other */
141   //@{
142  /// Return true if really network, false if has slacks
143  inline bool trueNetwork() const
144  { return trueNetwork_;};
145   //@}
146
147
148  /**@name Constructors, destructor */
149   //@{
150   /** Default constructor. */
151   ClpNetworkMatrix();
152  /** Constructor from two arrays */
153  ClpNetworkMatrix(int numberColumns, const int * head,
154                   const int * tail);
155   /** Destructor */
156   virtual ~ClpNetworkMatrix();
157   //@}
158
159   /**@name Copy method */
160   //@{
161   /** The copy constructor. */
162   ClpNetworkMatrix(const ClpNetworkMatrix&);
163   /** The copy constructor from an CoinNetworkMatrix. */
164   ClpNetworkMatrix(const CoinPackedMatrix&);
165
166   ClpNetworkMatrix& operator=(const ClpNetworkMatrix&);
167  /// Clone
168  virtual ClpMatrixBase * clone() const ;
169   //@}
170   
171   
172protected:
173   /**@name Data members
174      The data members are protected to allow access for derived classes. */
175   //@{
176  /// For fake CoinPackedMatrix
177  mutable double * elements_;
178  mutable CoinBigIndex * starts_;
179  mutable int * lengths_;
180  /// Data -1, then +1 rows in pairs (row==-1 if one entry)
181  int * indices_;
182  /// Number of rows
183  int numberRows_;
184  /// Number of columns
185  int numberColumns_;
186  /// True if all entries have two elements
187  bool trueNetwork_;
188 
189   //@}
190};
191
192#endif
Note: See TracBrowser for help on using the repository browser.