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