Bonmin  1.8.8
BonOaDecBase.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines (IBM) 2006
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // P. Bonami, International Business Machines
7 //
8 // Date : 12/07/2006
9 #ifndef BonOaDecBase_HPP
10 #define BonOaDecBase_HPP
11 #include "BonSubMipSolver.hpp"
12 #include "CglCutGenerator.hpp"
13 #include "BonBabSetupBase.hpp"
14 #include "BonOAMessages.hpp"
15 #include "CbcModel.hpp"
16 
17 #include "CbcStrategy.hpp"
18 
19 #include "CoinTime.hpp"
20 #include "OsiAuxInfo.hpp"
21 #include "OsiBranchingObject.hpp"
22 #include <iostream>
23 #include "BonBabInfos.hpp"
24 namespace Bonmin
25 {
27  class OaDecompositionBase : public CglCutGenerator
28  {
29  public:
30 
31 
35  {
36  public:
38  solverManip(OsiSolverInterface *si , bool saveNumRows=true,
39  bool saveBasis=true, bool saveBounds=false,
40  bool saveCutoff = false, bool resolve=true);
41 
43  solverManip(const OsiSolverInterface & si);
45  ~solverManip();
47  void restore();
48 
50  OsiSolverInterface * si()
51  {
52  return si_;
53  }
54 
56  void setObjects(OsiObject ** objects, int nObjects)
57  {
58  objects_ = objects;
59  nObjects_ = nObjects;
60  }
61 
62  private:
64  OsiSolverInterface * si_;
67 
69  double * colLower_;
70 
72  double * colUpper_;
73 
75  CoinWarmStart * warm_;
76 
78  double cutoff_;
79 
82 
84  OsiObject * * objects_;
86  int nObjects_;
90  int numcols_;
92  int numrows_;
94  const double * siColLower_;
96  const double * siColUpper_;
97 
98  void getCached();
100  };
101 
103  OaDecompositionBase(BabSetupBase &b, bool leaveSiUnchanged,
104  bool reassignLpsolver);
105 
108 
109 
111  virtual ~OaDecompositionBase();
112 
114  virtual void generateCuts(const OsiSolverInterface &si, OsiCuts & cs,
115  const CglTreeInfo info = CglTreeInfo());
116 
119  {
120  nlp_ = nlp;
121  }
122 
124  void assignLpInterface(OsiSolverInterface * si)
125  {
126  lp_ = si;
127  }
128 
130  {
131  return reassignLpsolver_;
132  }
134  void setObjects(OsiObject ** objects, int nObjects)
135  {
136  objects_ = objects;
137  nObjects_ = nObjects;
138  }
140  inline void setLeaveSiUnchanged(bool yesno)
141  {
142  leaveSiUnchanged_ = yesno;
143  }
144 
146  struct Parameters
147  {
149  bool global_;
157  double gap_tol_;
165  int maxSols_;
168 
169 
171  Parameters();
172 
174  Parameters(const Parameters & other);
175 
178  {
179  if (strategy_) delete strategy_;
180  }
181 
183  void setStrategy(const CbcStrategy & strategy)
184  {
185  if (strategy_) delete strategy_;
186  strategy_ = strategy.clone();
187  }
188 
189  const CbcStrategy * strategy() const
190  {
191  return strategy_;
192  }
193 
194 private:
196  CbcStrategy * strategy_;
197 
198  };
199 
201  {
202  return parameters_;
203  }
204 
205  const Parameters& parameter()const
206  {
207  return parameters_;
208  }
209 
210  void setLogLevel(int level)
211  {
212  handler_->setLogLevel(level);
213  }
214 
215  void setReassignLpSolver(bool v){
216  reassignLpsolver_ = v;
217  }
218  void passInMessageHandler(CoinMessageHandler * handler);
219  protected:
220  void setupMipSolver(BabSetupBase &b, const std::string &prefix);
222 
226  bool post_nlp_solve(BabInfo * babInfo, double cutoff) const;
229  virtual double performOa(OsiCuts &cs, solverManip &lpManip,
231  BabInfo * babInfo, double &, const CglTreeInfo & info) const = 0;
233  virtual bool doLocalSearch(BabInfo * babInfo) const = 0;
234 
236 
237  mutable OsiTMINLPInterface * nlp_;
242  mutable int nSolve_;
244  mutable OsiSolverInterface * lp_;
246  OsiObject * * objects_;
250  mutable int nLocalSearch_;
252  CoinMessageHandler * handler_;
254  CoinMessages messages_;
260  double timeBegin_;
262  mutable int numSols_;
263 
266 
270  mutable OsiCuts savedCuts_;
272  mutable int currentNodeNumber_;
275 #ifdef OA_DEBUG
276  class OaDebug
277  {
278  public:
279  bool checkInteger(const OsiSolverInterface&nlp, std::ostream & os) const;
280 
281  void printEndOfProcedureDebugMessage(const OsiCuts &cs,
282  bool foundSolution,
283  double solValue,
284  double milpBound,
285  bool isInteger,
286  bool feasible,
287  std::ostream & os) const;
288  };
289 
291  OaDebug debug_;
292 
293 #endif
294  };
295 }
296 #endif
297 
OaDecompositionBase(BabSetupBase &b, bool leaveSiUnchanged, bool reassignLpsolver)
New usefull constructor.
int maxSols_
maximum number of solutions
Small class to manipulatee various things in an OsiSolverInterface and restore them.
int nLocalSearch_
number of local searches performed
void setObjects(OsiObject **objects, int nObjects)
Set objects.
const double * siColUpper_
Upper bounds on variables.
const double * siColLower_
Lower bounds on variables.
OsiCuts savedCuts_
Saved cuts: in some cases when using OA to check feasible solution algorithm may loop because Cbc rem...
void passInMessageHandler(CoinMessageHandler *handler)
void setLeaveSiUnchanged(bool yesno)
Set whether to leave the solverinterface unchanged.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
bool reassignLpsolver_
Do we need to reassign the lp solver with Cbc.
bool addOnlyViolated_
Add only violated OA inequalities.
double maxLocalSearchTime_
maximum time for local searches
int initialNumberRows_
Initial number of rows (-1 if don&#39;t save).
OsiSolverInterface * lp_
A linear solver.
virtual bool doLocalSearch(BabInfo *babInfo) const =0
virutal method to decide if local search is performed
double cbcIntegerTolerance_
integer tolerance (has to be the same as Cbc&#39;s)
void setStrategy(const CbcStrategy &strategy)
Strategy to apply when using Cbc as MILP sub-solver.
OsiObject ** objects_
Some objects the feasiblitiy of which to verify.
solverManip(OsiSolverInterface *si, bool saveNumRows=true, bool saveBasis=true, bool saveBounds=false, bool saveCutoff=false, bool resolve=true)
Constructor.
CoinMessageHandler * handler_
messages handler.
double gap_tol_
setting for gap tolerance.
int nObjects_
Number of objects.*/.
void assignNlpInterface(OsiTMINLPInterface *nlp)
Assign an OsiTMINLPInterface.
void assignLpInterface(OsiSolverInterface *si)
Assign an OsiTMINLPInterface.
A class to have all elements necessary to setup a branch-and-bound.
double timeBegin_
time of construction
void setupMipSolver(BabSetupBase &b, const std::string &prefix)
CoinWarmStart * warm_
Inital basis.
double * colLower_
Initial lower bounds.
Parameters parameters_
Parameters.
int currentNodeNumber_
Store the current node number.
int numSols_
number of solutions found by OA_decomposition.
virtual void generateCuts(const OsiSolverInterface &si, OsiCuts &cs, const CglTreeInfo info=CglTreeInfo())
Standard cut generation methods.
double cbcCutoffIncrement_
cutoff min increase (has to be intialized trhough Cbc)
void getCached()
Number of columns.
virtual ~OaDecompositionBase()
Destructor.
int nSolve_
Number of nlp solved done.
int subMilpLogLevel_
sub milp log level.
bool leaveSiUnchanged_
Wether or not we should remove cuts at the end of the procedure.
double logFrequency_
Frequency of log.
CoinMessages messages_
Messages for OA.
int maxLocalSearch_
Total max number of local searches.
virtual double performOa(OsiCuts &cs, solverManip &lpManip, BabInfo *babInfo, double &, const CglTreeInfo &info) const =0
virtual method which performs the OA algorithm by modifying lp and nlp.
double * colUpper_
Initial Upper bounds.
BabSetupBase * s_
Pointer to setup.
OsiSolverInterface * si()
Get pointer to solver interface.
void setObjects(OsiObject **objects, int nObjects)
Set objects.
const CbcStrategy * strategy() const
Base class for OA algorithms.
int nObjects_
Number of objects.*/.
OsiObject ** objects_
Some objects the feasiblitiy of which to verify.
OsiTMINLPInterface * nlp_
Pointer to nlp interface.
const Parameters & parameter() const
Parameters()
Constructor with default values.
Bonmin class for passing info between components of branch-and-cuts.
Definition: BonBabInfos.hpp:19
CbcStrategy * strategy_
Strategy to apply when using Cbc as MILP sub-solver.
bool post_nlp_solve(BabInfo *babInfo, double cutoff) const
Solve the nlp and do output.
OsiSolverInterface * si_
Interface saved.