source: trunk/include/ClpGubMatrix.hpp @ 452

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

compiler message on AIX

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.3 KB
Line 
1// Copyright (C) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpGubMatrix_H
4#define ClpGubMatrix_H
5
6
7#include "CoinPragma.hpp"
8
9#include "ClpPackedMatrix.hpp"
10class ClpSimplex;
11/** This implements Gub rows plus a ClpPackedMatrix.
12
13    There will be a version using ClpPlusMinusOne matrix but
14    there is no point doing one with ClpNetworkMatrix (although
15    an embedded network is attractive).
16
17*/
18
19class ClpGubMatrix : public ClpPackedMatrix {
20 
21public:
22  /**@name Main functions provided */
23   //@{
24  /** Returns a new matrix in reverse order without gaps (GUB wants NULL) */
25  virtual ClpMatrixBase * reverseOrderedCopy() const;
26  /** If element NULL returns number of elements in column part of basis,
27      If not NULL fills in as well */
28  virtual CoinBigIndex fillBasis(ClpSimplex * model,
29                                 const int * whichColumn, 
30                                 int numberRowBasic,
31                                 int & numberColumnBasic,
32                                 int * row, int * column,
33                                 double * element)  ;
34  /** Unpacks a column into an CoinIndexedvector
35   */
36  virtual void unpack(const ClpSimplex * model,CoinIndexedVector * rowArray,
37                   int column) const ;
38  /** Unpacks a column into an CoinIndexedvector
39   ** in packed foramt
40      Note that model is NOT const.  Bounds and objective could
41      be modified if doing column generation (just for this variable) */
42  virtual void unpackPacked(ClpSimplex * model,
43                            CoinIndexedVector * rowArray,
44                            int column) const;
45  /** Adds multiple of a column into an CoinIndexedvector
46      You can use quickAdd to add to vector */
47  virtual void add(const ClpSimplex * model,CoinIndexedVector * rowArray,
48                   int column, double multiplier) const ;
49  /** Adds multiple of a column into an array */
50  virtual void add(const ClpSimplex * model,double * array,
51                   int column, double multiplier) const;
52  /// Partial pricing
53  virtual void partialPricing(ClpSimplex * model, double start, double end,
54                      int & bestSequence, int & numberWanted);
55  /// Returns number of hidden rows e.g. gub
56  virtual int hiddenRows() const;
57   //@}
58
59  /**@name Matrix times vector methods */
60  //@{
61    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
62        Can use y as temporary array (will be empty at end)
63        Note - If x packed mode - then z packed mode
64        Squashes small elements and knows about ClpSimplex */
65  virtual void transposeTimes(const ClpSimplex * model, double scalar,
66                              const CoinIndexedVector * x,
67                              CoinIndexedVector * y,
68                              CoinIndexedVector * z) const;
69    /** Return <code>x * scalar * A + y</code> in <code>z</code>.
70        Can use y as temporary array (will be empty at end)
71        Note - If x packed mode - then z packed mode
72        Squashes small elements and knows about ClpSimplex.
73    This version uses row copy*/
74  virtual void transposeTimesByRow(const ClpSimplex * model, double scalar,
75                              const CoinIndexedVector * x,
76                              CoinIndexedVector * y,
77                              CoinIndexedVector * z) const;
78    /** Return <code>x *A</code> in <code>z</code> but
79        just for indices in y.
80        Note - z always packed mode */
81  virtual void subsetTransposeTimes(const ClpSimplex * model,
82                                    const CoinIndexedVector * x,
83                                    const CoinIndexedVector * y,
84                                    CoinIndexedVector * z) const;
85  /** expands an updated column to allow for extra rows which the main
86      solver does not know about and returns number added if mode 0.
87      If mode 1 deletes extra entries
88
89      This active in Gub
90  */
91  virtual int extendUpdated(ClpSimplex * model,CoinIndexedVector * update,int mode);
92  /**
93     mode=0  - Set up before "update" and "times" for primal solution using extended rows
94     mode=1  - Cleanup primal solution after "times" using extended rows.
95     mode=2  - Check (or report on) primal infeasibilities
96  */
97  virtual void primalExpanded(ClpSimplex * model,int mode);
98  /**
99      mode=0  - Set up before "updateTranspose" and "transposeTimes" for duals using extended
100                updates array (and may use other if dual values pass)
101      mode=1  - Update dual solution after "transposeTimes" using extended rows.
102      mode=2  - Compute all djs and compute key dual infeasibilities
103      mode=3  - Report on key dual infeasibilities
104      mode=4  - Modify before updateTranspose in partial pricing
105  */
106  virtual void dualExpanded(ClpSimplex * model,CoinIndexedVector * array,
107                            double * other,int mode);
108  /**
109      mode=0  - Create list of non-key basics in pivotVariable_ using
110                number as numberBasic in and out
111      mode=1  - Set all key variables as basic
112      mode=2  - return number extra rows needed, number gives maximum number basic
113      mode=3  - before replaceColumn
114      mode=4  - return 1 if can do primal, 2 if dual, 3 if both
115      mode=5  - save any status stuff (when in good state)
116      mode=6  - restore status stuff
117      mode=7  - flag given variable (normally sequenceIn)
118      mode=8  - unflag all variables
119      mode=9  - synchronize costs
120      mode=10  - return 1 if there may be changing bounds on variable (column generation)
121      mode=11  - make sure set is clean (used when a variable rejected - but not flagged)
122      mode=12  - after factorize but before permute stuff
123      mode=13  - at end of simplex to delete stuff
124  */
125  virtual int generalExpanded(ClpSimplex * model,int mode,int & number);
126  /**
127     update information for a pivot (and effective rhs)
128  */
129  virtual int updatePivot(ClpSimplex * model,double oldInValue, double oldOutValue);
130  /// Sets up an effective RHS and does gub crash if needed
131  virtual void useEffectiveRhs(ClpSimplex * model,bool cheapest=true);
132  /** Returns effective RHS offset if it is being used.  This is used for long problems
133      or big gub or anywhere where going through full columns is
134      expensive.  This may re-compute */
135  virtual double * rhsOffset(ClpSimplex * model,bool forceRefresh=false,
136                                bool check=false);
137  /** This is local to Gub to allow synchronization:
138      mode=0 when status of basis is good
139      mode=1 when variable is flagged
140      mode=2 when all variables unflagged (returns number flagged)
141      mode=3 just reset costs (primal)
142      mode=4 correct number of dual infeasibilities
143      mode=5 return 4 if time to re-factorize
144      mode=6  - return 1 if there may be changing bounds on variable (column generation)
145      mode=7  - do extra restores for column generation
146      mode=8  - make sure set is clean
147      mode=9  - adjust lower, upper on set by incoming
148  */
149  virtual int synchronize(ClpSimplex * model,int mode);
150  /// Correct sequence in and out to give true value
151  virtual void correctSequence(int & sequenceIn, int & sequenceOut) const;
152  //@}
153
154
155
156  /**@name Constructors, destructor */
157   //@{
158   /** Default constructor. */
159   ClpGubMatrix();
160   /** Destructor */
161   virtual ~ClpGubMatrix();
162   //@}
163
164   /**@name Copy method */
165   //@{
166   /** The copy constructor. */
167   ClpGubMatrix(const ClpGubMatrix&);
168   /** The copy constructor from an CoinPackedMatrix. */
169   ClpGubMatrix(const CoinPackedMatrix&);
170  /** Subset constructor (without gaps).  Duplicates are allowed
171      and order is as given */
172  ClpGubMatrix (const ClpGubMatrix & wholeModel,
173                    int numberRows, const int * whichRows,
174                    int numberColumns, const int * whichColumns);
175  ClpGubMatrix (const CoinPackedMatrix & wholeModel,
176                    int numberRows, const int * whichRows,
177                    int numberColumns, const int * whichColumns);
178
179  /** This takes over ownership (for space reasons) */
180   ClpGubMatrix(CoinPackedMatrix * matrix);
181
182  /** This takes over ownership (for space reasons) and is the
183      real constructor*/
184   ClpGubMatrix(ClpPackedMatrix * matrix, int numberSets,
185                const int * start, const int * end,
186                const double * lower, const double * upper,
187                const unsigned char * status=NULL);
188
189   ClpGubMatrix& operator=(const ClpGubMatrix&);
190  /// Clone
191  virtual ClpMatrixBase * clone() const ;
192  /** Subset clone (without gaps).  Duplicates are allowed
193      and order is as given */
194  virtual ClpMatrixBase * subsetClone (
195                    int numberRows, const int * whichRows,
196                    int numberColumns, const int * whichColumns) const ;
197  /** redoes next_ for a set.  */
198  void redoSet(ClpSimplex * model,int newKey, int oldKey, int iSet); 
199  //@}
200  /**@name gets and sets */
201  //@{
202  /// Status
203  inline ClpSimplex::Status getStatus(int sequence) const
204  {return static_cast<ClpSimplex::Status> (status_[sequence]&7);};
205  inline void setStatus(int sequence, ClpSimplex::Status status)
206  {
207    unsigned char & st_byte = status_[sequence];
208    st_byte &= ~7;
209    st_byte |= status;
210  };
211  /// To flag a variable
212  inline void setFlagged( int sequence)
213  {
214    status_[sequence] |= 64;
215  };
216  inline void clearFlagged( int sequence)
217  {
218    status_[sequence] &= ~64;
219  };
220  inline bool flagged(int sequence) const
221  {return ((status_[sequence]&64)!=0);};
222  /// To say key is above ub
223  inline void setAbove( int sequence)
224  {
225    unsigned char iStat = status_[sequence];
226    iStat &= ~24;
227    status_[sequence] = iStat|16;
228  };
229  /// To say key is feasible
230  inline void setFeasible( int sequence)
231  {
232    unsigned char iStat = status_[sequence];
233    iStat &= ~24;
234    status_[sequence] = iStat|8;
235  };
236  /// To say key is below lb
237  inline void setBelow( int sequence)
238  {
239    unsigned char iStat = status_[sequence];
240    iStat &= ~24;
241    status_[sequence] = iStat;
242  };
243  inline double weight( int sequence) const
244  {
245    int iStat = status_[sequence]&31;
246    iStat = iStat>>3;
247    return (double) (iStat-1);
248  };
249  /// Starts
250  inline int * start() const
251  { return start_;};
252  /// End
253  inline int * end() const
254  { return end_;};
255  /// Lower bounds on sets
256  inline double * lower() const
257  { return lower_;};
258  /// Upper bounds on sets
259  inline double * upper() const
260  { return upper_;};
261  /// Key variable of set
262  inline int * keyVariable() const
263  { return keyVariable_;};
264  /// Backward pointer to set number
265  inline int * backward() const
266  { return backward_;};
267  /// Number of sets (gub rows)
268  inline int numberSets() const
269  { return numberSets_;};
270  /// Switches off dj checking each factorization (for BIG models)
271  void switchOffCheck();
272   //@}
273   
274   
275protected:
276   /**@name Data members
277      The data members are protected to allow access for derived classes. */
278   //@{
279  /// Sum of dual infeasibilities
280  double sumDualInfeasibilities_;
281  /// Sum of primal infeasibilities
282  double sumPrimalInfeasibilities_;
283  /// Sum of Dual infeasibilities using tolerance based on error in duals
284  double sumOfRelaxedDualInfeasibilities_;
285  /// Sum of Primal infeasibilities using tolerance based on error in primals
286  double sumOfRelaxedPrimalInfeasibilities_;
287  /// Infeasibility weight when last full pass done
288  double infeasibilityWeight_;
289  /// Starts
290  int * start_;
291  /// End
292  int * end_;
293  /// Lower bounds on sets
294  double * lower_;
295  /// Upper bounds on sets
296  double * upper_;
297  /// Status of slacks
298  mutable unsigned char * status_;
299  /// Saved status of slacks
300  unsigned char * saveStatus_;
301  /// Saved key variables
302  int * savedKeyVariable_;
303  /// Backward pointer to set number
304  int * backward_;
305  /// Backward pointer to pivot row !!!
306  int * backToPivotRow_;
307  /// Change in costs for keys
308  double * changeCost_;
309  /// Key variable of set
310  mutable int * keyVariable_;
311  /** Next basic variable in set - starts at key and end with -(set+1).
312      Now changes to -(nonbasic+1).
313      next_ has extra space for 2* longest set */
314  mutable int * next_;
315  /// Backward pointer to index in CoinIndexedVector
316  int * toIndex_;
317  // Reverse pointer from index to set
318  int * fromIndex_; 
319  /// Pointer back to model
320  ClpSimplex * model_;
321  /// Number of dual infeasibilities
322  int numberDualInfeasibilities_;
323  /// Number of primal infeasibilities
324  int numberPrimalInfeasibilities_;
325  /** If pricing will declare victory (i.e. no check every factorization).
326      -1 - always check
327      0  - don't check
328      1  - in don't check mode but looks optimal
329  */
330  int noCheck_;
331  /// Number of sets (gub rows)
332  int numberSets_;
333  /// Number in vector without gub extension
334  int saveNumber_;
335  /// Pivot row of possible next key
336  int possiblePivotKey_;
337  /// Gub slack in (set number or -1)
338  int gubSlackIn_;
339  /// First gub variables (same as start_[0] at present)
340  int firstGub_;
341  /// last gub variable (same as end_[numberSets_-1] at present)
342  int lastGub_;
343  /** type of gub - 0 not contiguous, 1 contiguous
344      add 8 bit to say no ubs on individual variables */
345  int gubType_;
346   //@}
347};
348
349#endif
Note: See TracBrowser for help on using the repository browser.