[2] | 1 | // Copyright (C) 2002, International Business Machines |
---|
| 2 | // Corporation and others. All Rights Reserved. |
---|
| 3 | #ifndef ClpFactorization_H |
---|
| 4 | #define ClpFactorization_H |
---|
| 5 | |
---|
| 6 | |
---|
[63] | 7 | #include "CoinPragma.hpp" |
---|
| 8 | |
---|
[50] | 9 | #include "CoinFactorization.hpp" |
---|
[440] | 10 | class ClpMatrixBase; |
---|
| 11 | class ClpSimplex; |
---|
| 12 | class ClpNetworkBasis; |
---|
[1284] | 13 | #ifndef CLP_MULTIPLE_FACTORIZATIONS |
---|
[1286] | 14 | #define CLP_MULTIPLE_FACTORIZATIONS 3 |
---|
[1284] | 15 | #endif |
---|
| 16 | #if CLP_MULTIPLE_FACTORIZATIONS == 1 |
---|
[1152] | 17 | #include "CoinDenseFactorization.hpp" |
---|
[1286] | 18 | typedef CoinDenseFactorization CoinSmallFactorization; |
---|
[1284] | 19 | #elif CLP_MULTIPLE_FACTORIZATIONS == 2 |
---|
| 20 | #include "CoinSimpFactorization.hpp" |
---|
[1286] | 21 | typedef CoinSimpFactorization CoinSmallFactorization; |
---|
| 22 | #elif CLP_MULTIPLE_FACTORIZATIONS == 3 |
---|
| 23 | #include "CoinDenseFactorization.hpp" |
---|
| 24 | #include "CoinSimpFactorization.hpp" |
---|
[1152] | 25 | #endif |
---|
[2] | 26 | |
---|
[50] | 27 | /** This just implements CoinFactorization when an ClpMatrixBase object |
---|
[118] | 28 | is passed. If a network then has a dummy CoinFactorization and |
---|
| 29 | a genuine ClpNetworkBasis object |
---|
[2] | 30 | */ |
---|
[1147] | 31 | class ClpFactorization |
---|
| 32 | #ifndef CLP_MULTIPLE_FACTORIZATIONS |
---|
| 33 | : public CoinFactorization |
---|
| 34 | #endif |
---|
| 35 | { |
---|
[2] | 36 | |
---|
[1147] | 37 | //friend class CoinFactorization; |
---|
[2] | 38 | |
---|
| 39 | public: |
---|
| 40 | /**@name factorization */ |
---|
| 41 | //@{ |
---|
| 42 | /** When part of LP - given by basic variables. |
---|
| 43 | Actually does factorization. |
---|
| 44 | Arrays passed in have non negative value to say basic. |
---|
| 45 | If status is okay, basic variables have pivot row - this is only needed |
---|
| 46 | if increasingRows_ >1. |
---|
| 47 | Allows scaling |
---|
| 48 | If status is singular, then basic variables have pivot row |
---|
| 49 | and ones thrown out have -1 |
---|
| 50 | returns 0 -okay, -1 singular, -2 too many in basis, -99 memory */ |
---|
[225] | 51 | int factorize (ClpSimplex * model,int solveType, bool valuesPass); |
---|
[2] | 52 | //@} |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | /**@name Constructors, destructor */ |
---|
| 56 | //@{ |
---|
| 57 | /** Default constructor. */ |
---|
| 58 | ClpFactorization(); |
---|
| 59 | /** Destructor */ |
---|
| 60 | ~ClpFactorization(); |
---|
| 61 | //@} |
---|
| 62 | |
---|
| 63 | /**@name Copy method */ |
---|
| 64 | //@{ |
---|
[50] | 65 | /** The copy constructor from an CoinFactorization. */ |
---|
| 66 | ClpFactorization(const CoinFactorization&); |
---|
[1287] | 67 | /** The copy constructor. */ |
---|
| 68 | ClpFactorization(const ClpFactorization&,int denseIfSmaller=0); |
---|
[1152] | 69 | #ifdef CLP_MULTIPLE_FACTORIZATIONS |
---|
[1286] | 70 | /** The copy constructor from an CoinSmallFactorization. */ |
---|
| 71 | ClpFactorization(const CoinSmallFactorization&); |
---|
[1152] | 72 | #endif |
---|
[2] | 73 | ClpFactorization& operator=(const ClpFactorization&); |
---|
| 74 | //@} |
---|
| 75 | |
---|
[118] | 76 | /* **** below here is so can use networkish basis */ |
---|
| 77 | /**@name rank one updates which do exist */ |
---|
| 78 | //@{ |
---|
| 79 | |
---|
| 80 | /** Replaces one Column to basis, |
---|
| 81 | returns 0=OK, 1=Probably OK, 2=singular, 3=no room |
---|
| 82 | If checkBeforeModifying is true will do all accuracy checks |
---|
| 83 | before modifying factorization. Whether to set this depends on |
---|
| 84 | speed considerations. You could just do this on first iteration |
---|
| 85 | after factorization and thereafter re-factorize |
---|
| 86 | partial update already in U */ |
---|
[336] | 87 | int replaceColumn ( const ClpSimplex * model, |
---|
| 88 | CoinIndexedVector * regionSparse, |
---|
| 89 | CoinIndexedVector * tableauColumn, |
---|
[118] | 90 | int pivotRow, |
---|
| 91 | double pivotCheck , |
---|
| 92 | bool checkBeforeModifying=false); |
---|
| 93 | //@} |
---|
| 94 | |
---|
| 95 | /**@name various uses of factorization (return code number elements) |
---|
| 96 | which user may want to know about */ |
---|
| 97 | //@{ |
---|
| 98 | /** Updates one column (FTRAN) from region2 |
---|
[225] | 99 | Tries to do FT update |
---|
[118] | 100 | number returned is negative if no room |
---|
| 101 | region1 starts as zero and is zero at end */ |
---|
[225] | 102 | int updateColumnFT ( CoinIndexedVector * regionSparse, |
---|
| 103 | CoinIndexedVector * regionSparse2); |
---|
[1197] | 104 | /** Updates one column (FTRAN) from region2 |
---|
| 105 | region1 starts as zero and is zero at end */ |
---|
[118] | 106 | int updateColumn ( CoinIndexedVector * regionSparse, |
---|
[225] | 107 | CoinIndexedVector * regionSparse2, |
---|
| 108 | bool noPermute=false) const; |
---|
[1197] | 109 | /** Updates one column (FTRAN) from region2 |
---|
| 110 | Tries to do FT update |
---|
| 111 | number returned is negative if no room. |
---|
| 112 | Also updates region3 |
---|
| 113 | region1 starts as zero and is zero at end */ |
---|
| 114 | int updateTwoColumnsFT ( CoinIndexedVector * regionSparse1, |
---|
| 115 | CoinIndexedVector * regionSparse2, |
---|
| 116 | CoinIndexedVector * regionSparse3, |
---|
| 117 | bool noPermuteRegion3=false) ; |
---|
[518] | 118 | /// For debug (no statistics update) |
---|
| 119 | int updateColumnForDebug ( CoinIndexedVector * regionSparse, |
---|
| 120 | CoinIndexedVector * regionSparse2, |
---|
| 121 | bool noPermute=false) const; |
---|
[118] | 122 | /** Updates one column (BTRAN) from region2 |
---|
| 123 | region1 starts as zero and is zero at end */ |
---|
| 124 | int updateColumnTranspose ( CoinIndexedVector * regionSparse, |
---|
| 125 | CoinIndexedVector * regionSparse2) const; |
---|
| 126 | //@} |
---|
[1147] | 127 | #ifdef CLP_MULTIPLE_FACTORIZATIONS |
---|
| 128 | /**@name Lifted from CoinFactorization */ |
---|
| 129 | //@{ |
---|
| 130 | /// Total number of elements in factorization |
---|
| 131 | inline int numberElements ( ) const { |
---|
[1152] | 132 | if (coinFactorizationA_) return coinFactorizationA_->numberElements(); else return coinFactorizationB_->numberElements() ; |
---|
[1147] | 133 | } |
---|
| 134 | /// Returns address of permute region |
---|
| 135 | inline int *permute ( ) const { |
---|
[1152] | 136 | if (coinFactorizationA_) return coinFactorizationA_->permute(); else return coinFactorizationB_->permute() ; |
---|
[1147] | 137 | } |
---|
| 138 | /// Returns address of pivotColumn region (also used for permuting) |
---|
| 139 | inline int *pivotColumn ( ) const { |
---|
[1152] | 140 | if (coinFactorizationA_) return coinFactorizationA_->pivotColumn(); else return coinFactorizationB_->permute() ; |
---|
[1147] | 141 | } |
---|
| 142 | /// Maximum number of pivots between factorizations |
---|
| 143 | inline int maximumPivots ( ) const { |
---|
[1152] | 144 | if (coinFactorizationA_) return coinFactorizationA_->maximumPivots(); else return coinFactorizationB_->maximumPivots() ; |
---|
[1147] | 145 | } |
---|
| 146 | /// Set maximum number of pivots between factorizations |
---|
| 147 | inline void maximumPivots ( int value) { |
---|
[1152] | 148 | if (coinFactorizationA_) coinFactorizationA_->maximumPivots(value); else coinFactorizationB_->maximumPivots(value); |
---|
[1147] | 149 | } |
---|
| 150 | /// Returns number of pivots since factorization |
---|
| 151 | inline int pivots ( ) const { |
---|
[1152] | 152 | if (coinFactorizationA_) return coinFactorizationA_->pivots(); else return coinFactorizationB_->pivots() ; |
---|
[1147] | 153 | } |
---|
| 154 | /// Whether larger areas needed |
---|
| 155 | inline double areaFactor ( ) const { |
---|
| 156 | if (coinFactorizationA_) return coinFactorizationA_->areaFactor(); else return 0.0 ; |
---|
| 157 | } |
---|
| 158 | /// Set whether larger areas needed |
---|
| 159 | inline void areaFactor ( double value) { |
---|
| 160 | if (coinFactorizationA_) coinFactorizationA_->areaFactor(value); |
---|
| 161 | } |
---|
| 162 | /// Zero tolerance |
---|
| 163 | inline double zeroTolerance ( ) const { |
---|
[1152] | 164 | if (coinFactorizationA_) return coinFactorizationA_->zeroTolerance(); else return coinFactorizationB_->zeroTolerance() ; |
---|
[1147] | 165 | } |
---|
| 166 | /// Set zero tolerance |
---|
| 167 | inline void zeroTolerance ( double value) { |
---|
[1152] | 168 | if (coinFactorizationA_) coinFactorizationA_->zeroTolerance(value); else coinFactorizationB_->zeroTolerance(value); |
---|
[1147] | 169 | } |
---|
[1344] | 170 | /// Set tolerances to safer of existing and given |
---|
| 171 | void saferTolerances ( double zeroTolerance, double pivotTolerance); |
---|
[1147] | 172 | /** get sparse threshold */ |
---|
| 173 | inline int sparseThreshold ( ) const |
---|
| 174 | { if (coinFactorizationA_) return coinFactorizationA_->sparseThreshold(); else return 0 ;} |
---|
| 175 | /** Set sparse threshold */ |
---|
| 176 | inline void sparseThreshold ( int value) |
---|
| 177 | { if (coinFactorizationA_) coinFactorizationA_->sparseThreshold(value); } |
---|
| 178 | /// Returns status |
---|
| 179 | inline int status ( ) const { |
---|
[1152] | 180 | if (coinFactorizationA_) return coinFactorizationA_->status(); else return coinFactorizationB_->status() ; |
---|
[1147] | 181 | } |
---|
[1152] | 182 | /// Sets status |
---|
| 183 | inline void setStatus ( int value) { |
---|
| 184 | if (coinFactorizationA_) coinFactorizationA_->setStatus(value); else coinFactorizationB_->setStatus(value) ; |
---|
| 185 | } |
---|
[1147] | 186 | /// Returns number of dense rows |
---|
| 187 | inline int numberDense() const |
---|
| 188 | { if (coinFactorizationA_) return coinFactorizationA_->numberDense(); else return 0 ;} |
---|
[1266] | 189 | #if 1 |
---|
[1147] | 190 | /// Returns number in U area |
---|
| 191 | inline CoinBigIndex numberElementsU ( ) const { |
---|
[1266] | 192 | if (coinFactorizationA_) return coinFactorizationA_->numberElementsU(); else return -1 ; |
---|
[1147] | 193 | } |
---|
| 194 | /// Returns number in L area |
---|
| 195 | inline CoinBigIndex numberElementsL ( ) const { |
---|
[1266] | 196 | if (coinFactorizationA_) return coinFactorizationA_->numberElementsL(); else return -1 ; |
---|
[1147] | 197 | } |
---|
| 198 | /// Returns number in R area |
---|
| 199 | inline CoinBigIndex numberElementsR ( ) const { |
---|
| 200 | if (coinFactorizationA_) return coinFactorizationA_->numberElementsR(); else return 0 ; |
---|
| 201 | } |
---|
| 202 | #endif |
---|
| 203 | inline bool timeToRefactorize() const |
---|
| 204 | { |
---|
| 205 | if (coinFactorizationA_) { |
---|
| 206 | return (coinFactorizationA_->pivots()*3>coinFactorizationA_->maximumPivots()*2&& |
---|
| 207 | coinFactorizationA_->numberElementsR()*3>(coinFactorizationA_->numberElementsL()+ |
---|
| 208 | coinFactorizationA_->numberElementsU())*2+1000&& |
---|
| 209 | !coinFactorizationA_->numberDense()); |
---|
| 210 | } else { |
---|
[1152] | 211 | return coinFactorizationB_->pivots()>coinFactorizationB_->numberRows()/2.45+20; |
---|
[1147] | 212 | } |
---|
| 213 | } |
---|
| 214 | /// Level of detail of messages |
---|
| 215 | inline int messageLevel ( ) const { |
---|
| 216 | if (coinFactorizationA_) return coinFactorizationA_->messageLevel(); else return 0 ; |
---|
| 217 | } |
---|
| 218 | /// Set level of detail of messages |
---|
| 219 | inline void messageLevel ( int value) { |
---|
| 220 | if (coinFactorizationA_) coinFactorizationA_->messageLevel(value); |
---|
| 221 | } |
---|
| 222 | /// Get rid of all memory |
---|
| 223 | inline void clearArrays() |
---|
| 224 | { if (coinFactorizationA_) coinFactorizationA_->clearArrays();} |
---|
| 225 | /// Number of Rows after factorization |
---|
| 226 | inline int numberRows ( ) const { |
---|
[1152] | 227 | if (coinFactorizationA_) return coinFactorizationA_->numberRows(); else return coinFactorizationB_->numberRows() ; |
---|
[1147] | 228 | } |
---|
| 229 | /// Gets dense threshold |
---|
| 230 | inline int denseThreshold() const |
---|
| 231 | { if (coinFactorizationA_) return coinFactorizationA_->denseThreshold(); else return 0 ;} |
---|
| 232 | /// Sets dense threshold |
---|
| 233 | inline void setDenseThreshold(int value) |
---|
| 234 | { if (coinFactorizationA_) coinFactorizationA_->setDenseThreshold(value);} |
---|
| 235 | /// Pivot tolerance |
---|
| 236 | inline double pivotTolerance ( ) const { |
---|
| 237 | if (coinFactorizationA_) return coinFactorizationA_->pivotTolerance(); else return 1.0e-8 ; |
---|
| 238 | } |
---|
| 239 | /// Set pivot tolerance |
---|
| 240 | inline void pivotTolerance ( double value) { |
---|
| 241 | if (coinFactorizationA_) coinFactorizationA_->pivotTolerance(value); |
---|
| 242 | } |
---|
| 243 | /// Allows change of pivot accuracy check 1.0 == none >1.0 relaxed |
---|
| 244 | inline void relaxAccuracyCheck(double value) |
---|
| 245 | { if (coinFactorizationA_) coinFactorizationA_->relaxAccuracyCheck(value);} |
---|
| 246 | /** Array persistence flag |
---|
| 247 | If 0 then as now (delete/new) |
---|
| 248 | 1 then only do arrays if bigger needed |
---|
| 249 | 2 as 1 but give a bit extra if bigger needed |
---|
| 250 | */ |
---|
| 251 | inline int persistenceFlag() const |
---|
| 252 | { if (coinFactorizationA_) return coinFactorizationA_->persistenceFlag(); else return 0 ;} |
---|
| 253 | inline void setPersistenceFlag(int value) |
---|
| 254 | { if (coinFactorizationA_) coinFactorizationA_->setPersistenceFlag(value);} |
---|
| 255 | /// Delete all stuff (leaves as after CoinFactorization()) |
---|
| 256 | inline void almostDestructor() |
---|
| 257 | { if (coinFactorizationA_) coinFactorizationA_->almostDestructor(); } |
---|
| 258 | /// Returns areaFactor but adjusted for dense |
---|
| 259 | inline double adjustedAreaFactor() const |
---|
| 260 | { if (coinFactorizationA_) return coinFactorizationA_->adjustedAreaFactor(); else return 0.0 ; } |
---|
| 261 | inline void setBiasLU(int value) |
---|
| 262 | { if (coinFactorizationA_) coinFactorizationA_->setBiasLU(value);} |
---|
| 263 | /// true if Forrest Tomlin update, false if PFI |
---|
| 264 | inline void setForrestTomlin(bool value) |
---|
| 265 | { if (coinFactorizationA_) coinFactorizationA_->setForrestTomlin(value);} |
---|
| 266 | /// Sets default values |
---|
| 267 | inline void setDefaultValues() { |
---|
| 268 | if (coinFactorizationA_) { |
---|
| 269 | // row activities have negative sign |
---|
[1197] | 270 | #ifndef COIN_FAST_CODE |
---|
[1147] | 271 | coinFactorizationA_->slackValue(-1.0); |
---|
[1197] | 272 | #endif |
---|
[1147] | 273 | coinFactorizationA_->zeroTolerance(1.0e-13); |
---|
| 274 | } |
---|
| 275 | } |
---|
[1197] | 276 | /// Get switch to dense if number rows <= this |
---|
| 277 | inline int goDenseThreshold() const |
---|
| 278 | { return goDenseThreshold_;} |
---|
| 279 | /// Set switch to dense if number rows <= this |
---|
| 280 | inline void setGoDenseThreshold(int value) |
---|
| 281 | { goDenseThreshold_ = value;} |
---|
[1286] | 282 | /// Get switch to small if number rows <= this |
---|
| 283 | inline int goSmallThreshold() const |
---|
| 284 | { return goSmallThreshold_;} |
---|
| 285 | /// Set switch to small if number rows <= this |
---|
| 286 | inline void setGoSmallThreshold(int value) |
---|
| 287 | { goSmallThreshold_ = value;} |
---|
| 288 | /// Go over to dense or small code if small enough |
---|
| 289 | void goDenseOrSmall(int numberRows) ; |
---|
[1197] | 290 | /// Return 1 if dense code |
---|
[1286] | 291 | inline int isDenseOrSmall() const |
---|
[1197] | 292 | { return coinFactorizationB_ ? 1 : 0;} |
---|
[1147] | 293 | #else |
---|
| 294 | inline bool timeToRefactorize() const |
---|
| 295 | { |
---|
| 296 | return (pivots()*3>maximumPivots()*2&& |
---|
| 297 | numberElementsR()*3>(numberElementsL()+numberElementsU())*2+1000&& |
---|
| 298 | !numberDense()); |
---|
| 299 | } |
---|
| 300 | /// Sets default values |
---|
| 301 | inline void setDefaultValues() { |
---|
| 302 | // row activities have negative sign |
---|
[1197] | 303 | #ifndef COIN_FAST_CODE |
---|
[1147] | 304 | slackValue(-1.0); |
---|
[1197] | 305 | #endif |
---|
[1147] | 306 | zeroTolerance(1.0e-13); |
---|
| 307 | } |
---|
[1152] | 308 | /// Go over to dense code |
---|
| 309 | inline void goDense() {} |
---|
[1147] | 310 | #endif |
---|
| 311 | //@} |
---|
[2] | 312 | |
---|
[119] | 313 | /**@name other stuff */ |
---|
| 314 | //@{ |
---|
| 315 | /** makes a row copy of L for speed and to allow very sparse problems */ |
---|
| 316 | void goSparse(); |
---|
[130] | 317 | /// Cleans up i.e. gets rid of network basis |
---|
| 318 | void cleanUp(); |
---|
| 319 | /// Says whether to redo pivot order |
---|
| 320 | bool needToReorder() const; |
---|
[650] | 321 | #ifndef SLIM_CLP |
---|
[225] | 322 | /// Says if a network basis |
---|
[660] | 323 | inline bool networkBasis() const |
---|
[1055] | 324 | { return (networkBasis_!=NULL);} |
---|
[650] | 325 | #else |
---|
| 326 | /// Says if a network basis |
---|
[660] | 327 | inline bool networkBasis() const |
---|
[1055] | 328 | { return false;} |
---|
[650] | 329 | #endif |
---|
[454] | 330 | /// Fills weighted row list |
---|
| 331 | void getWeights(int * weights) const; |
---|
[119] | 332 | //@} |
---|
| 333 | |
---|
[118] | 334 | ////////////////// data ////////////////// |
---|
| 335 | private: |
---|
| 336 | |
---|
| 337 | /**@name data */ |
---|
| 338 | //@{ |
---|
| 339 | /// Pointer to network basis |
---|
[650] | 340 | #ifndef SLIM_CLP |
---|
[118] | 341 | ClpNetworkBasis * networkBasis_; |
---|
[650] | 342 | #endif |
---|
[1147] | 343 | #ifdef CLP_MULTIPLE_FACTORIZATIONS |
---|
| 344 | /// Pointer to CoinFactorization |
---|
| 345 | CoinFactorization * coinFactorizationA_; |
---|
[1286] | 346 | /// Pointer to CoinSmallFactorization |
---|
| 347 | CoinSmallFactorization * coinFactorizationB_; |
---|
| 348 | /// Switch to small if number rows <= this |
---|
| 349 | int goSmallThreshold_; |
---|
[1197] | 350 | /// Switch to dense if number rows <= this |
---|
| 351 | int goDenseThreshold_; |
---|
[1147] | 352 | #endif |
---|
[118] | 353 | //@} |
---|
[2] | 354 | }; |
---|
| 355 | |
---|
| 356 | #endif |
---|