Clp trunk
|
00001 /* $Id$ */ 00002 // Copyright (C) 2003, International Business Machines 00003 // Corporation and others. All Rights Reserved. 00004 // This code is licensed under the terms of the Eclipse Public License (EPL). 00005 /* 00006 Authors 00007 00008 John Tomlin (pdco) 00009 John Forrest (standard predictor-corrector) 00010 00011 Note JJF has added arrays - this takes more memory but makes 00012 flow easier to understand and hopefully easier to extend 00013 00014 */ 00015 #ifndef ClpInterior_H 00016 #define ClpInterior_H 00017 00018 #include <iostream> 00019 #include <cfloat> 00020 #include "ClpModel.hpp" 00021 #include "ClpMatrixBase.hpp" 00022 #include "ClpSolve.hpp" 00023 #include "CoinDenseVector.hpp" 00024 class ClpLsqr; 00025 class ClpPdcoBase; 00027 typedef struct { 00028 double atolmin; 00029 double r3norm; 00030 double LSdamp; 00031 double* deltay; 00032 } Info; 00034 00035 typedef struct { 00036 double atolold; 00037 double atolnew; 00038 double r3ratio; 00039 int istop; 00040 int itncg; 00041 } Outfo; 00043 00044 typedef struct { 00045 double gamma; 00046 double delta; 00047 int MaxIter; 00048 double FeaTol; 00049 double OptTol; 00050 double StepTol; 00051 double x0min; 00052 double z0min; 00053 double mu0; 00054 int LSmethod; // 1=Cholesky 2=QR 3=LSQR 00055 int LSproblem; // See below 00056 int LSQRMaxIter; 00057 double LSQRatol1; // Initial atol 00058 double LSQRatol2; // Smallest atol (unless atol1 is smaller) 00059 double LSQRconlim; 00060 int wait; 00061 } Options; 00062 class Lsqr; 00063 class ClpCholeskyBase; 00064 // ***** END 00072 class ClpInterior : public ClpModel { 00073 friend void ClpInteriorUnitTest(const std::string & mpsDir, 00074 const std::string & netlibDir); 00075 00076 public: 00077 00080 00081 ClpInterior ( ); 00082 00084 ClpInterior(const ClpInterior &); 00086 ClpInterior(const ClpModel &); 00091 ClpInterior (const ClpModel * wholeModel, 00092 int numberRows, const int * whichRows, 00093 int numberColumns, const int * whichColumns, 00094 bool dropNames = true, bool dropIntegers = true); 00096 ClpInterior & operator=(const ClpInterior & rhs); 00098 ~ClpInterior ( ); 00099 // Ones below are just ClpModel with some changes 00111 void loadProblem ( const ClpMatrixBase& matrix, 00112 const double* collb, const double* colub, 00113 const double* obj, 00114 const double* rowlb, const double* rowub, 00115 const double * rowObjective = NULL); 00116 void loadProblem ( const CoinPackedMatrix& matrix, 00117 const double* collb, const double* colub, 00118 const double* obj, 00119 const double* rowlb, const double* rowub, 00120 const double * rowObjective = NULL); 00121 00124 void loadProblem ( const int numcols, const int numrows, 00125 const CoinBigIndex* start, const int* index, 00126 const double* value, 00127 const double* collb, const double* colub, 00128 const double* obj, 00129 const double* rowlb, const double* rowub, 00130 const double * rowObjective = NULL); 00132 void loadProblem ( const int numcols, const int numrows, 00133 const CoinBigIndex* start, const int* index, 00134 const double* value, const int * length, 00135 const double* collb, const double* colub, 00136 const double* obj, 00137 const double* rowlb, const double* rowub, 00138 const double * rowObjective = NULL); 00140 int readMps(const char *filename, 00141 bool keepNames = false, 00142 bool ignoreErrors = false); 00147 void borrowModel(ClpModel & otherModel); 00149 void returnModel(ClpModel & otherModel); 00151 00155 int pdco(); 00156 // ** Temporary version 00157 int pdco( ClpPdcoBase * stuff, Options &options, Info &info, Outfo &outfo); 00159 int primalDual(); 00161 00164 00165 inline bool primalFeasible() const { 00166 return (sumPrimalInfeasibilities_ <= 1.0e-5); 00167 } 00169 inline bool dualFeasible() const { 00170 return (sumDualInfeasibilities_ <= 1.0e-5); 00171 } 00173 inline int algorithm() const { 00174 return algorithm_; 00175 } 00177 inline void setAlgorithm(int value) { 00178 algorithm_ = value; 00179 } 00181 inline CoinWorkDouble sumDualInfeasibilities() const { 00182 return sumDualInfeasibilities_; 00183 } 00185 inline CoinWorkDouble sumPrimalInfeasibilities() const { 00186 return sumPrimalInfeasibilities_; 00187 } 00189 inline CoinWorkDouble dualObjective() const { 00190 return dualObjective_; 00191 } 00193 inline CoinWorkDouble primalObjective() const { 00194 return primalObjective_; 00195 } 00197 inline CoinWorkDouble diagonalNorm() const { 00198 return diagonalNorm_; 00199 } 00201 inline CoinWorkDouble linearPerturbation() const { 00202 return linearPerturbation_; 00203 } 00204 inline void setLinearPerturbation(CoinWorkDouble value) { 00205 linearPerturbation_ = value; 00206 } 00208 inline CoinWorkDouble projectionTolerance() const { 00209 return projectionTolerance_; 00210 } 00211 inline void setProjectionTolerance(CoinWorkDouble value) { 00212 projectionTolerance_ = value; 00213 } 00215 inline CoinWorkDouble diagonalPerturbation() const { 00216 return diagonalPerturbation_; 00217 } 00218 inline void setDiagonalPerturbation(CoinWorkDouble value) { 00219 diagonalPerturbation_ = value; 00220 } 00222 inline CoinWorkDouble gamma() const { 00223 return gamma_; 00224 } 00225 inline void setGamma(CoinWorkDouble value) { 00226 gamma_ = value; 00227 } 00229 inline CoinWorkDouble delta() const { 00230 return delta_; 00231 } 00232 inline void setDelta(CoinWorkDouble value) { 00233 delta_ = value; 00234 } 00236 inline CoinWorkDouble complementarityGap() const { 00237 return complementarityGap_; 00238 } 00240 00243 00244 inline CoinWorkDouble largestPrimalError() const { 00245 return largestPrimalError_; 00246 } 00248 inline CoinWorkDouble largestDualError() const { 00249 return largestDualError_; 00250 } 00252 inline int maximumBarrierIterations() const { 00253 return maximumBarrierIterations_; 00254 } 00255 inline void setMaximumBarrierIterations(int value) { 00256 maximumBarrierIterations_ = value; 00257 } 00259 void setCholesky(ClpCholeskyBase * cholesky); 00261 int numberFixed() const; 00264 void fixFixed(bool reallyFix = true); 00266 inline CoinWorkDouble * primalR() const { 00267 return primalR_; 00268 } 00270 inline CoinWorkDouble * dualR() const { 00271 return dualR_; 00272 } 00274 00275 protected: 00278 00279 void gutsOfDelete(); 00281 void gutsOfCopy(const ClpInterior & rhs); 00283 bool createWorkingData(); 00284 void deleteWorkingData(); 00286 bool sanityCheck(); 00288 int housekeeping(); 00290 public: 00293 00294 inline CoinWorkDouble rawObjectiveValue() const { 00295 return objectiveValue_; 00296 } 00298 inline int isColumn(int sequence) const { 00299 return sequence < numberColumns_ ? 1 : 0; 00300 } 00302 inline int sequenceWithin(int sequence) const { 00303 return sequence < numberColumns_ ? sequence : sequence - numberColumns_; 00304 } 00306 void checkSolution(); 00309 CoinWorkDouble quadraticDjs(CoinWorkDouble * djRegion, const CoinWorkDouble * solution, 00310 CoinWorkDouble scaleFactor); 00311 00313 inline void setFixed( int sequence) { 00314 status_[sequence] = static_cast<unsigned char>(status_[sequence] | 1) ; 00315 } 00316 inline void clearFixed( int sequence) { 00317 status_[sequence] = static_cast<unsigned char>(status_[sequence] & ~1) ; 00318 } 00319 inline bool fixed(int sequence) const { 00320 return ((status_[sequence] & 1) != 0); 00321 } 00322 00324 inline void setFlagged( int sequence) { 00325 status_[sequence] = static_cast<unsigned char>(status_[sequence] | 2) ; 00326 } 00327 inline void clearFlagged( int sequence) { 00328 status_[sequence] = static_cast<unsigned char>(status_[sequence] & ~2) ; 00329 } 00330 inline bool flagged(int sequence) const { 00331 return ((status_[sequence] & 2) != 0); 00332 } 00333 00335 inline void setFixedOrFree( int sequence) { 00336 status_[sequence] = static_cast<unsigned char>(status_[sequence] | 4) ; 00337 } 00338 inline void clearFixedOrFree( int sequence) { 00339 status_[sequence] = static_cast<unsigned char>(status_[sequence] & ~4) ; 00340 } 00341 inline bool fixedOrFree(int sequence) const { 00342 return ((status_[sequence] & 4) != 0); 00343 } 00344 00346 inline void setLowerBound( int sequence) { 00347 status_[sequence] = static_cast<unsigned char>(status_[sequence] | 8) ; 00348 } 00349 inline void clearLowerBound( int sequence) { 00350 status_[sequence] = static_cast<unsigned char>(status_[sequence] & ~8) ; 00351 } 00352 inline bool lowerBound(int sequence) const { 00353 return ((status_[sequence] & 8) != 0); 00354 } 00355 00357 inline void setUpperBound( int sequence) { 00358 status_[sequence] = static_cast<unsigned char>(status_[sequence] | 16) ; 00359 } 00360 inline void clearUpperBound( int sequence) { 00361 status_[sequence] = static_cast<unsigned char>(status_[sequence] & ~16) ; 00362 } 00363 inline bool upperBound(int sequence) const { 00364 return ((status_[sequence] & 16) != 0); 00365 } 00366 00368 inline void setFakeLower( int sequence) { 00369 status_[sequence] = static_cast<unsigned char>(status_[sequence] | 32) ; 00370 } 00371 inline void clearFakeLower( int sequence) { 00372 status_[sequence] = static_cast<unsigned char>(status_[sequence] & ~32) ; 00373 } 00374 inline bool fakeLower(int sequence) const { 00375 return ((status_[sequence] & 32) != 0); 00376 } 00377 00379 inline void setFakeUpper( int sequence) { 00380 status_[sequence] = static_cast<unsigned char>(status_[sequence] | 64) ; 00381 } 00382 inline void clearFakeUpper( int sequence) { 00383 status_[sequence] = static_cast<unsigned char>(status_[sequence] & ~64) ; 00384 } 00385 inline bool fakeUpper(int sequence) const { 00386 return ((status_[sequence] & 64) != 0); 00387 } 00389 00391 protected: 00392 00399 00400 CoinWorkDouble largestPrimalError_; 00402 CoinWorkDouble largestDualError_; 00404 CoinWorkDouble sumDualInfeasibilities_; 00406 CoinWorkDouble sumPrimalInfeasibilities_; 00408 CoinWorkDouble worstComplementarity_; 00410 public: 00411 CoinWorkDouble xsize_; 00412 CoinWorkDouble zsize_; 00413 protected: 00415 CoinWorkDouble * lower_; 00417 CoinWorkDouble * rowLowerWork_; 00419 CoinWorkDouble * columnLowerWork_; 00421 CoinWorkDouble * upper_; 00423 CoinWorkDouble * rowUpperWork_; 00425 CoinWorkDouble * columnUpperWork_; 00427 CoinWorkDouble * cost_; 00428 public: 00430 CoinWorkDouble * rhs_; 00431 CoinWorkDouble * x_; 00432 CoinWorkDouble * y_; 00433 CoinWorkDouble * dj_; 00434 protected: 00436 ClpLsqr * lsqrObject_; 00438 ClpPdcoBase * pdcoStuff_; 00441 CoinWorkDouble mu_; 00443 CoinWorkDouble objectiveNorm_; 00445 CoinWorkDouble rhsNorm_; 00447 CoinWorkDouble solutionNorm_; 00449 CoinWorkDouble dualObjective_; 00451 CoinWorkDouble primalObjective_; 00453 CoinWorkDouble diagonalNorm_; 00455 CoinWorkDouble stepLength_; 00457 CoinWorkDouble linearPerturbation_; 00459 CoinWorkDouble diagonalPerturbation_; 00460 // gamma from Saunders and Tomlin regularized 00461 CoinWorkDouble gamma_; 00462 // delta from Saunders and Tomlin regularized 00463 CoinWorkDouble delta_; 00465 CoinWorkDouble targetGap_; 00467 CoinWorkDouble projectionTolerance_; 00469 CoinWorkDouble maximumRHSError_; 00471 CoinWorkDouble maximumBoundInfeasibility_; 00473 CoinWorkDouble maximumDualError_; 00475 CoinWorkDouble diagonalScaleFactor_; 00477 CoinWorkDouble scaleFactor_; 00479 CoinWorkDouble actualPrimalStep_; 00481 CoinWorkDouble actualDualStep_; 00483 CoinWorkDouble smallestInfeasibility_; 00485 #define LENGTH_HISTORY 5 00486 CoinWorkDouble historyInfeasibility_[LENGTH_HISTORY]; 00488 CoinWorkDouble complementarityGap_; 00490 CoinWorkDouble baseObjectiveNorm_; 00492 CoinWorkDouble worstDirectionAccuracy_; 00494 CoinWorkDouble maximumRHSChange_; 00496 CoinWorkDouble * errorRegion_; 00498 CoinWorkDouble * rhsFixRegion_; 00500 CoinWorkDouble * upperSlack_; 00502 CoinWorkDouble * lowerSlack_; 00504 CoinWorkDouble * diagonal_; 00506 CoinWorkDouble * solution_; 00508 CoinWorkDouble * workArray_; 00510 CoinWorkDouble * deltaX_; 00512 CoinWorkDouble * deltaY_; 00514 CoinWorkDouble * deltaZ_; 00516 CoinWorkDouble * deltaW_; 00518 CoinWorkDouble * deltaSU_; 00519 CoinWorkDouble * deltaSL_; 00521 CoinWorkDouble * primalR_; 00523 CoinWorkDouble * dualR_; 00525 CoinWorkDouble * rhsB_; 00527 CoinWorkDouble * rhsU_; 00529 CoinWorkDouble * rhsL_; 00531 CoinWorkDouble * rhsZ_; 00533 CoinWorkDouble * rhsW_; 00535 CoinWorkDouble * rhsC_; 00537 CoinWorkDouble * zVec_; 00539 CoinWorkDouble * wVec_; 00541 ClpCholeskyBase * cholesky_; 00543 int numberComplementarityPairs_; 00545 int numberComplementarityItems_; 00547 int maximumBarrierIterations_; 00549 bool gonePrimalFeasible_; 00551 bool goneDualFeasible_; 00553 int algorithm_; 00555 }; 00556 //############################################################################# 00565 void 00566 ClpInteriorUnitTest(const std::string & mpsDir, 00567 const std::string & netlibDir); 00568 00569 00570 #endif