00001
00002
00003
00004
00005
00006
00007
00008
00009
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
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
00051 #if 1
00052
00053 void cloneOther(const OsiSolverInterface &si);
00054 #endif
00055
00056
00058 OsiSolverInterface * si()
00059 {
00060 return si_;
00061 }
00062
00064 void setObjects(OsiObject ** objects, int nObjects)
00065 {
00066 objects_ = objects;
00067 nObjects_ = nObjects;
00068 }
00069
00070 private:
00072 OsiSolverInterface * si_;
00074 int initialNumberRows_;
00075
00077 double * colLower_;
00078
00080 double * colUpper_;
00081
00083 CoinWarmStart * warm_;
00084
00086 double cutoff_;
00087
00089 bool deleteSolver_;
00090
00092 OsiObject * * objects_;
00094 int nObjects_;
00098 int numcols_;
00100 int numrows_;
00102 const double * siColLower_;
00104 const double * siColUpper_;
00105
00106 void getCached();
00108 };
00110 OaDecompositionBase(OsiTMINLPInterface * nlp = NULL
00111 #if 0
00112 ,
00113 OsiSolverInterface * si = NULL,
00114 CbcStrategy * strategy = NULL,
00115 double cbcCutoffIncrement_=1e-07,
00116 double cbcIntegerTolerance = 1e-05,
00117 bool leaveSiUnchanged = 0
00118 #endif
00119 );
00121 OaDecompositionBase(BabSetupBase &b, bool leaveSiUnchanged,
00122 bool reassignLpsolver);
00123
00125 OaDecompositionBase(const OaDecompositionBase & copy);
00126
00127
00129 virtual ~OaDecompositionBase();
00130
00132 virtual void generateCuts(const OsiSolverInterface &si, OsiCuts & cs,
00133 const CglTreeInfo info = CglTreeInfo()) const;
00134
00136 void assignNlpInterface(OsiTMINLPInterface * nlp)
00137 {
00138 nlp_ = nlp;
00139 }
00140
00142 void assignLpInterface(OsiSolverInterface * si)
00143 {
00144 lp_ = si;
00145 }
00146
00147 bool reassignLpsolver()
00148 {
00149 return reassignLpsolver_;
00150 }
00152 void setObjects(OsiObject ** objects, int nObjects)
00153 {
00154 objects_ = objects;
00155 nObjects_ = nObjects;
00156 }
00158 inline void setLeaveSiUnchanged(bool yesno)
00159 {
00160 leaveSiUnchanged_ = yesno;
00161 }
00162
00164 struct Parameters
00165 {
00167 bool global_;
00169 bool addOnlyViolated_;
00171 double cbcCutoffIncrement_;
00173 double cbcIntegerTolerance_;
00175 int maxLocalSearch_;
00177 double maxLocalSearchTime_;
00179 int subMilpLogLevel_;
00181 int maxSols_;
00183 double logFrequency_;
00184
00186 Parameters();
00187
00189 Parameters(const Parameters & other);
00190
00192 ~Parameters()
00193 {
00194 if (strategy_) delete strategy_;
00195 }
00196
00198 void setStrategy(const CbcStrategy & strategy)
00199 {
00200 if (strategy_) delete strategy_;
00201 strategy_ = strategy.clone();
00202 }
00203
00204 const CbcStrategy * strategy() const
00205 {
00206 return strategy_;
00207 }
00208 private:
00210 CbcStrategy * strategy_;
00211
00212 };
00213
00214 Parameters& parameter()
00215 {
00216 return parameters_;
00217 }
00218
00219 const Parameters& parameter()const
00220 {
00221 return parameters_;
00222 }
00223
00224 void setLogLevel(int level)
00225 {
00226 handler_->setLogLevel(level);
00227 }
00228
00229 void passInMessageHandler(CoinMessageHandler * handler);
00230 protected:
00232
00236 bool post_nlp_solve(BabInfo * babInfo, double cutoff) const;
00239
00240 virtual double performOa(OsiCuts &cs, solverManip &lpManip,
00241 SubMipSolver * &subMip, BabInfo * babInfo, double &, const CglTreeInfo & info) const = 0;
00243 virtual bool doLocalSearch(BabInfo * babInfo) const = 0;
00244
00246
00247
00248 mutable OsiTMINLPInterface * nlp_;
00250 BabSetupBase * s_;
00252 mutable int nSolve_;
00254 mutable OsiSolverInterface * lp_;
00256 OsiObject * * objects_;
00258 int nObjects_;
00260 mutable int nLocalSearch_;
00262 CoinMessageHandler * handler_;
00264 CoinMessages messages_;
00266 bool leaveSiUnchanged_;
00268 bool reassignLpsolver_;
00270 double timeBegin_;
00272 mutable int numSols_;
00273
00275 Parameters parameters_;
00276
00280 mutable OsiCuts savedCuts_;
00282 mutable int currentNodeNumber_;
00285 #ifdef OA_DEBUG
00286 class OaDebug
00287 {
00288 public:
00289 bool checkInteger(const OsiSolverInterface&nlp, std::ostream & os) const;
00290
00291 void printEndOfProcedureDebugMessage(const OsiCuts &cs,
00292 bool foundSolution,
00293 double solValue,
00294 double milpBound,
00295 bool isInteger,
00296 bool feasible,
00297 std::ostream & os) const;
00298 };
00299
00301 OaDebug debug_;
00302
00303 #endif
00304 };
00305 }
00306 #endif
00307