coin-Cgl
|
00001 // Copyright (C) 2005, Pierre Bonami and others. All Rights Reserved. 00002 // Author: Pierre Bonami 00003 // Tepper School of Business 00004 // Carnegie Mellon University, Pittsburgh, PA 15213 00005 // Date: 07/21/05 00006 //--------------------------------------------------------------------------- 00007 #ifndef CglLandP_H 00008 #define CglLandP_H 00009 00010 //Several level of Debug 00011 // 1 - A few simple sanity check 00012 // 2 - do extra computations on cut quality 00013 // 3 - Output cut in initial non-basic space (only if logLevel >= 3 ) 00014 // 4 - Double check (compute in two different ways) reduced cost and f+ f- 00015 //#define LandP_DEBUG 1 00016 00017 00018 #include "CglLandPValidator.hpp" 00019 #include "CglCutGenerator.hpp" 00020 #include "CglParam.hpp" 00021 00022 #ifdef DO_STAT 00023 #include "CglLandPStats.hpp" 00024 #endif 00025 #include <iostream> 00026 class CoinWarmStartBasis; 00031 namespace LAP 00032 { 00033 enum LapMessagesTypes { 00034 BEGIN_ROUND, 00035 END_ROUND, 00036 DURING_SEP, 00037 CUT_REJECTED, 00038 CUT_FAILED, 00039 LAP_CUT_FAILED_DO_MIG, 00040 LAP_MESSAGES_DUMMY_END 00041 }; 00043 class LapMessages : public CoinMessages 00044 { 00045 public: 00047 LapMessages( ); 00049 virtual ~LapMessages(){} 00050 }; 00051 class CglLandPSimplex; 00052 } 00053 00054 class CglLandP : public CglCutGenerator 00055 { 00056 friend void CglLandPUnitTest(OsiSolverInterface *si, const std::string & mpsDir); 00057 00058 friend class LAP::CglLandPSimplex; 00059 friend class CftCglp; 00060 00061 public: 00062 00063 enum SelectionRules { 00064 mostNegativeRc , 00065 bestPivot , 00066 initialReducedCosts 00067 }; 00068 00069 enum ExtraCutsMode { 00070 none, 00071 AtOptimalBasis , 00072 WhenEnteringBasis , 00073 AllViolatedMigs 00074 }; 00075 00077 enum SeparationSpaces { 00078 Fractional=0 , 00079 Fractional_rc, 00080 Full 00081 }; 00082 00084 enum Normalization{ 00085 Unweighted = 0, 00086 WeightRHS, 00087 WeightLHS, 00088 WeightBoth 00089 }; 00090 00091 enum LHSnorm { 00092 L1 = 0, 00093 L2, 00094 SupportSize, 00095 Infinity, 00096 Average, 00097 Uniform 00098 }; 00100 enum RhsWeightType { 00101 Fixed = 0 , 00102 Dynamic 00103 }; 00106 class Parameters : public CglParam 00107 { 00108 public: 00110 Parameters(); 00112 Parameters(const Parameters &other); 00114 Parameters & operator=(const Parameters &other); 00117 00120 int pivotLimit; 00123 int pivotLimitInTree; 00125 int maxCutPerRound; 00127 int failedPivotLimit; 00130 int degeneratePivotLimit; 00132 int extraCutsLimit; 00136 00137 double pivotTol; 00139 double away; 00141 mutable double timeLimit; 00143 double singleCutTimeLimit; 00145 double rhsWeight; 00147 00150 00151 bool useTableauRow; 00153 bool modularize; 00155 bool strengthen; 00157 bool countMistakenRc; 00159 SeparationSpaces sepSpace; 00161 bool perturb; 00163 Normalization normalization; 00165 RhsWeightType rhsWeightType; 00167 LHSnorm lhs_norm; 00169 ExtraCutsMode generateExtraCuts; 00171 SelectionRules pivotSelection; 00173 }; 00174 00175 00177 CglLandP(const CglLandP::Parameters ¶ms = CglLandP::Parameters(), 00178 const LAP::Validator &validator = LAP::Validator()); 00180 ~CglLandP(); 00182 CglLandP(const CglLandP &source); 00184 CglLandP& operator=(const CglLandP &rhs); 00186 CglCutGenerator * clone() const; 00187 00188 #ifdef DO_STAT 00189 void setIdString(const std::string &id) { 00190 roundsStats_.setIdString(id); 00191 } 00192 #endif 00193 00196 00197 virtual void generateCuts(const OsiSolverInterface & si, OsiCuts & cs, 00198 const CglTreeInfo info = CglTreeInfo()) const; 00199 00201 00202 virtual bool needsOptimalBasis() const { 00203 return true; 00204 } 00205 00206 LAP::Validator & validator() { 00207 return validator_; 00208 } 00216 void setLogLevel(int level) { 00217 handler_->setLogLevel(level); 00218 } 00219 00220 class NoBasisError : public CoinError 00221 { 00222 public: 00223 NoBasisError(): CoinError("No basis available","LandP","") {} 00224 }; 00225 00226 class SimplexInterfaceError : public CoinError 00227 { 00228 public: 00229 SimplexInterfaceError(): CoinError("Invalid conversion to simplex interface", "CglLandP","CglLandP") {} 00230 }; 00231 Parameters & parameter() { 00232 return params_; 00233 } 00234 private: 00235 00236 00237 void scanExtraCuts(OsiCuts& cs, const double * colsol) const; 00238 00239 Parameters params_; 00240 00242 struct CachedData { 00243 CachedData(int nBasics = 0 , int nNonBasics = 0); 00244 CachedData(const CachedData & source); 00245 00246 CachedData& operator=(const CachedData &source); 00248 void getData(const OsiSolverInterface &si); 00249 ~CachedData(); 00251 int * basics_; 00253 int *nonBasics_; 00255 int nBasics_; 00257 int nNonBasics_; 00259 CoinWarmStartBasis * basis_; 00261 double * colsol_; 00263 double * slacks_; 00265 bool * integers_; 00266 }; 00269 int getSortedFractionals(CoinPackedVector &xFrac, 00270 const CachedData & data, 00271 const CglLandP::Parameters& params) const; 00274 void getSortedFractionalIndices(std::vector<int>& indices, 00275 const CachedData &data, 00276 const CglLandP::Parameters & params) const; 00278 mutable CachedData cached_; 00280 CoinMessageHandler * handler_; 00282 CoinMessages messages_; 00284 LAP::Validator validator_; 00286 mutable int numrows_; 00288 mutable int numcols_; 00290 mutable double * originalColLower_; 00292 mutable double * originalColUpper_; 00294 mutable bool canLift_; 00296 mutable OsiCuts extraCuts_; 00297 #ifdef DO_STAT 00298 public: 00300 mutable roundsStatistics roundsStats_; 00301 #endif 00302 }; 00303 void CglLandPUnitTest(OsiSolverInterface *si, const std::string & mpsDir); 00304 00305 #endif 00306