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

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

BSP changes from 1247 to 1259

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1// Copyright (C) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef ClpGubDynamicMatrix_H
4#define ClpGubDynamicMatrix_H
5
6
7#include "CoinPragma.hpp"
8
9#include "ClpGubMatrix.hpp"
10/** This implements Gub rows plus a ClpPackedMatrix.
11    This a dynamic version which stores the gub part and dynamically creates matrix.
12    All bounds are assumed to be zero and infinity
13
14    This is just a simple example for real column generation
15*/
16
17class ClpGubDynamicMatrix : public ClpGubMatrix {
18 
19public:
20  /**@name Main functions provided */
21   //@{
22  /// Partial pricing
23  virtual void partialPricing(ClpSimplex * model, double start, double end,
24                              int & bestSequence, int & numberWanted);
25  /** This is local to Gub to allow synchronization:
26      mode=0 when status of basis is good
27      mode=1 when variable is flagged
28      mode=2 when all variables unflagged (returns number flagged)
29      mode=3 just reset costs (primal)
30      mode=4 correct number of dual infeasibilities
31      mode=5 return 4 if time to re-factorize
32      mode=8  - make sure set is clean
33      mode=9  - adjust lower, upper on set by incoming
34  */
35  virtual int synchronize(ClpSimplex * model,int mode);
36  /// Sets up an effective RHS and does gub crash if needed
37  virtual void useEffectiveRhs(ClpSimplex * model,bool cheapest=true);
38  /**
39     update information for a pivot (and effective rhs)
40  */
41  virtual int updatePivot(ClpSimplex * model,double oldInValue, double oldOutValue);
42  /// Add a new variable to a set
43  void insertNonBasic(int sequence, int iSet);
44  /** Returns effective RHS offset if it is being used.  This is used for long problems
45      or big gub or anywhere where going through full columns is
46      expensive.  This may re-compute */
47  virtual double * rhsOffset(ClpSimplex * model,bool forceRefresh=false,
48                                bool check=false);
49
50  using ClpPackedMatrix::times ;
51    /** Return <code>y + A * scalar *x</code> in <code>y</code>.
52        @pre <code>x</code> must be of size <code>numColumns()</code>
53        @pre <code>y</code> must be of size <code>numRows()</code> */
54  virtual void times(double scalar,
55                       const double * x, double * y) const;
56  /** Just for debug
57      Returns sum and number of primal infeasibilities. Recomputes keys
58  */
59  virtual int checkFeasible(ClpSimplex * model,double & sum) const;
60  /// Cleans data after setWarmStart
61  void cleanData(ClpSimplex * model);
62  //@}
63
64 
65 
66  /**@name Constructors, destructor */
67  //@{
68  /** Default constructor. */
69  ClpGubDynamicMatrix();
70  /** Destructor */
71  virtual ~ClpGubDynamicMatrix();
72  //@}
73 
74  /**@name Copy method */
75  //@{
76  /** The copy constructor. */
77  ClpGubDynamicMatrix(const ClpGubDynamicMatrix&);
78  /** This is the real constructor.
79      It assumes factorization frequency will not be changed.
80      This resizes model !!!!
81   */
82  ClpGubDynamicMatrix(ClpSimplex * model, int numberSets,
83                      int numberColumns, const int * starts,
84                      const double * lower, const double * upper,
85                      const int * startColumn, const int * row,
86                      const double * element, const double * cost,
87                      const double * lowerColumn=NULL, const double * upperColumn=NULL,
88                      const unsigned char * status=NULL);
89 
90  ClpGubDynamicMatrix& operator=(const ClpGubDynamicMatrix&);
91  /// Clone
92  virtual ClpMatrixBase * clone() const ;
93  //@}
94  /**@name gets and sets */
95  //@{
96  /// enums for status of various sorts
97  enum DynamicStatus {
98    inSmall = 0x01,
99    atUpperBound = 0x02,
100    atLowerBound = 0x03
101  };
102  /// Whether flagged
103  inline bool flagged(int i) const {
104    return (dynamicStatus_[i]&8)!=0;
105  }
106  inline void setFlagged(int i) {
107    dynamicStatus_[i] = static_cast<unsigned char>(dynamicStatus_[i] | 8);
108  }
109  inline void unsetFlagged(int i) {
110    dynamicStatus_[i] = static_cast<unsigned char>(dynamicStatus_[i] & ~8);
111  }
112  inline void setDynamicStatus(int sequence, DynamicStatus status)
113  {
114    unsigned char & st_byte = dynamicStatus_[sequence];
115    st_byte = static_cast<unsigned char>(st_byte & ~7);
116    st_byte = static_cast<unsigned char>(st_byte | status);
117  }
118  inline DynamicStatus getDynamicStatus(int sequence) const
119  {return static_cast<DynamicStatus> (dynamicStatus_[sequence]&7);}
120  /// Saved value of objective offset
121  inline double objectiveOffset() const
122  { return objectiveOffset_;}
123  /// Starts of each column
124  inline CoinBigIndex * startColumn() const
125  { return startColumn_;}
126  /// rows
127  inline int * row() const
128  { return row_;}
129  /// elements
130  inline double * element() const
131  { return element_;}
132  /// costs
133  inline double * cost() const
134  { return cost_;}
135  /// full starts
136  inline int * fullStart() const
137  { return fullStart_;}
138  /// ids of active columns (just index here)
139  inline int * id() const
140  { return id_;}
141  /// Optional lower bounds on columns
142  inline double * lowerColumn() const
143  { return lowerColumn_;}
144  /// Optional upper bounds on columns
145  inline double * upperColumn() const
146  { return upperColumn_;}
147  /// Optional true lower bounds on sets
148  inline double * lowerSet() const
149  { return lowerSet_;}
150  /// Optional true upper bounds on sets
151  inline double * upperSet() const
152  { return upperSet_;}
153  /// size
154  inline int numberGubColumns() const
155  { return numberGubColumns_;}
156  /// first free
157  inline int firstAvailable() const
158  { return firstAvailable_;}
159  /// set first free
160  inline void setFirstAvailable(int value)
161  { firstAvailable_ = value;}
162  /// first dynamic
163  inline int firstDynamic() const
164  { return firstDynamic_;}
165  /// number of columns in dynamic model
166  inline int lastDynamic() const
167  { return lastDynamic_;}
168  /// size of working matrix (max)
169  inline int numberElements() const
170  { return numberElements_;}
171  /// Status region for gub slacks
172  inline unsigned char * gubRowStatus() const
173  { return status_;}
174  /// Status region for gub variables
175  inline unsigned char * dynamicStatus() const
176  { return dynamicStatus_;}
177  /// Returns which set a variable is in
178  int whichSet (int sequence) const;
179  //@}
180   
181   
182protected:
183  /**@name Data members
184     The data members are protected to allow access for derived classes. */
185  //@{
186  /// Saved value of objective offset
187  double objectiveOffset_;
188  /// Starts of each column
189  CoinBigIndex * startColumn_;
190  /// rows
191  int * row_;
192  /// elements
193  double * element_;
194  /// costs
195  double * cost_;
196  /// full starts
197  int * fullStart_;
198  /// ids of active columns (just index here)
199  int * id_;
200  /// for status and which bound
201  unsigned char * dynamicStatus_;
202  /// Optional lower bounds on columns
203  double * lowerColumn_;
204  /// Optional upper bounds on columns
205  double * upperColumn_;
206  /// Optional true lower bounds on sets
207  double * lowerSet_;
208  /// Optional true upper bounds on sets
209  double * upperSet_;
210  /// size
211  int numberGubColumns_;
212  /// first free
213  int firstAvailable_;
214  /// saved first free
215  int savedFirstAvailable_;
216  /// first dynamic
217  int firstDynamic_;
218  /// number of columns in dynamic model
219  int lastDynamic_;
220  /// size of working matrix (max)
221  int numberElements_;
222   //@}
223};
224
225#endif
Note: See TracBrowser for help on using the repository browser.