Bonmin 1.4trunk
|
00001 // (C) Copyright International Business Machines (IBM) 2006 00002 // All Rights Reserved. 00003 // This code is published under the Common Public License. 00004 // 00005 // Authors : 00006 // P. Bonami, International Business Machines 00007 // 00008 // Date : 12/07/2006 00009 //#define OA_DEBUG 00010 #ifndef BonOaDecBase_HPP 00011 #define BonOaDecBase_HPP 00012 #include "BonSubMipSolver.hpp" 00013 #include "CglCutGenerator.hpp" 00014 #include "BonBabSetupBase.hpp" 00015 #include "BonOAMessages.hpp" 00016 #include "CbcModel.hpp" 00017 00018 #include "CbcStrategy.hpp" 00019 00020 #include "CoinTime.hpp" 00021 #include "OsiAuxInfo.hpp" 00022 #include "OsiBranchingObject.hpp" 00023 #include <iostream> 00024 #include "BonBabInfos.hpp" 00025 //#define OA_DEBUG 00026 namespace Bonmin 00027 { 00029 class OaDecompositionBase : public CglCutGenerator 00030 { 00031 public: 00032 00033 00036 class solverManip 00037 { 00038 public: 00040 solverManip(OsiSolverInterface *si , bool saveNumRows=true, 00041 bool saveBasis=true, bool saveBounds=false, 00042 bool saveCutoff = false, bool resolve=true); 00043 00045 solverManip(const OsiSolverInterface & si); 00047 ~solverManip(); 00049 void restore(); 00050 00052 OsiSolverInterface * si() 00053 { 00054 return si_; 00055 } 00056 00058 void setObjects(OsiObject ** objects, int nObjects) 00059 { 00060 objects_ = objects; 00061 nObjects_ = nObjects; 00062 } 00063 00064 private: 00066 OsiSolverInterface * si_; 00068 int initialNumberRows_; 00069 00071 double * colLower_; 00072 00074 double * colUpper_; 00075 00077 CoinWarmStart * warm_; 00078 00080 double cutoff_; 00081 00083 bool deleteSolver_; 00084 00086 OsiObject * * objects_; 00088 int nObjects_; 00092 int numcols_; 00094 int numrows_; 00096 const double * siColLower_; 00098 const double * siColUpper_; 00099 00100 void getCached(); 00102 }; 00103 00105 OaDecompositionBase(BabSetupBase &b, bool leaveSiUnchanged, 00106 bool reassignLpsolver); 00107 00109 OaDecompositionBase(const OaDecompositionBase & copy); 00110 00111 00113 virtual ~OaDecompositionBase(); 00114 00116 virtual void generateCuts(const OsiSolverInterface &si, OsiCuts & cs, 00117 const CglTreeInfo info = CglTreeInfo()) const; 00118 00120 void assignNlpInterface(OsiTMINLPInterface * nlp) 00121 { 00122 nlp_ = nlp; 00123 } 00124 00126 void assignLpInterface(OsiSolverInterface * si) 00127 { 00128 lp_ = si; 00129 } 00130 00131 bool reassignLpsolver() 00132 { 00133 return reassignLpsolver_; 00134 } 00136 void setObjects(OsiObject ** objects, int nObjects) 00137 { 00138 objects_ = objects; 00139 nObjects_ = nObjects; 00140 } 00142 inline void setLeaveSiUnchanged(bool yesno) 00143 { 00144 leaveSiUnchanged_ = yesno; 00145 } 00146 00148 struct Parameters 00149 { 00151 bool global_; 00153 bool addOnlyViolated_; 00155 double cbcCutoffIncrement_; 00157 double cbcIntegerTolerance_; 00159 double gap_tol_; 00161 int maxLocalSearch_; 00163 double maxLocalSearchTime_; 00165 int subMilpLogLevel_; 00167 int maxSols_; 00169 double logFrequency_; 00170 00171 00173 Parameters(); 00174 00176 Parameters(const Parameters & other); 00177 00179 ~Parameters() 00180 { 00181 if (strategy_) delete strategy_; 00182 } 00183 00185 void setStrategy(const CbcStrategy & strategy) 00186 { 00187 if (strategy_) delete strategy_; 00188 strategy_ = strategy.clone(); 00189 } 00190 00191 const CbcStrategy * strategy() const 00192 { 00193 return strategy_; 00194 } 00195 00196 private: 00198 CbcStrategy * strategy_; 00199 00200 }; 00201 00202 Parameters& parameter() 00203 { 00204 return parameters_; 00205 } 00206 00207 const Parameters& parameter()const 00208 { 00209 return parameters_; 00210 } 00211 00212 void setLogLevel(int level) 00213 { 00214 handler_->setLogLevel(level); 00215 } 00216 00217 void setReassignLpSolver(bool v){ 00218 reassignLpsolver_ = v; 00219 } 00220 void passInMessageHandler(CoinMessageHandler * handler); 00221 protected: 00222 void setupMipSolver(BabSetupBase &b, const std::string &prefix); 00224 00228 bool post_nlp_solve(BabInfo * babInfo, double cutoff) const; 00231 00232 virtual double performOa(OsiCuts &cs, solverManip &lpManip, 00233 BabInfo * babInfo, double &, const CglTreeInfo & info) const = 0; 00235 virtual bool doLocalSearch(BabInfo * babInfo) const = 0; 00236 00238 00239 00240 mutable OsiTMINLPInterface * nlp_; 00242 BabSetupBase * s_; 00244 mutable int nSolve_; 00246 mutable OsiSolverInterface * lp_; 00248 OsiObject * * objects_; 00250 int nObjects_; 00252 mutable int nLocalSearch_; 00254 CoinMessageHandler * handler_; 00256 CoinMessages messages_; 00258 bool leaveSiUnchanged_; 00260 bool reassignLpsolver_; 00262 double timeBegin_; 00264 mutable int numSols_; 00265 00267 Parameters parameters_; 00268 00272 mutable OsiCuts savedCuts_; 00274 mutable int currentNodeNumber_; 00277 #ifdef OA_DEBUG 00278 class OaDebug 00279 { 00280 public: 00281 bool checkInteger(const OsiSolverInterface&nlp, std::ostream & os) const; 00282 00283 void printEndOfProcedureDebugMessage(const OsiCuts &cs, 00284 bool foundSolution, 00285 double solValue, 00286 double milpBound, 00287 bool isInteger, 00288 bool feasible, 00289 std::ostream & os) const; 00290 }; 00291 00293 OaDebug debug_; 00294 00295 #endif 00296 }; 00297 } 00298 #endif 00299