CbcSolver.hpp
Go to the documentation of this file.
1 /* $Id: CbcSolver.hpp 1212 2009-08-21 16:19:13Z forrest $ */
2 // Copyright (C) 2007, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 
16 #ifndef CbcSolver_H
17 #define CbcSolver_H
18 
19 #include <string>
20 #include <vector>
21 #include "CoinFinite.hpp"
22 #include "CoinMessageHandler.hpp"
23 #include "OsiClpSolverInterface.hpp"
24 
25 #if CBC_OTHER_SOLVER==1
26 #include "OsiCpxSolverInterface.hpp"
27 #endif
28 
29 #include "CbcModel.hpp"
30 #include "CbcOrClpParam.hpp"
31 
32 class CbcUser;
33 class CbcStopNow;
34 class CglCutGenerator;
35 
36 //#############################################################################
37 
55 class CbcSolver {
56 
57 public:
59 
60 
66  int solve(int argc, const char * argv[], int returnMode);
73  int solve(const char * input, int returnMode);
75 
76 
77 
78  CbcSolver();
79 
81  CbcSolver(const OsiClpSolverInterface &);
82 
84  CbcSolver(const CbcModel &);
85 
88  CbcSolver(const CbcSolver & rhs);
89 
91  CbcSolver & operator=(const CbcSolver& rhs);
92 
94  ~CbcSolver ();
96  void fillParameters();
103  void fillValuesInSolver();
105  void addUserFunction(CbcUser * function);
107  void setUserCallBack(CbcStopNow * function);
109  void addCutGenerator(CglCutGenerator * generator);
111 
112 
113  // analyze model
114  int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
115  bool changeInt, CoinMessageHandler * generalMessageHandler);
121  //int doHeuristics(CbcModel * model, int type);
128  void updateModel(ClpSimplex * model2, int returnMode);
130 
131 
132 
133  int intValue(CbcOrClpParameterType type) const;
135  void setIntValue(CbcOrClpParameterType type, int value);
137  double doubleValue(CbcOrClpParameterType type) const;
139  void setDoubleValue(CbcOrClpParameterType type, double value);
141  CbcUser * userFunction(const char * name) const;
143  inline CbcModel * model() {
144  return &model_;
145  }
147  inline CbcModel * babModel() {
148  return babModel_;
149  }
151  inline int numberUserFunctions() const {
152  return numberUserFunctions_;
153  }
155  inline CbcUser ** userFunctionArray() const {
156  return userFunction_;
157  }
159  inline OsiClpSolverInterface * originalSolver() const {
160  return originalSolver_;
161  }
163  inline CoinModel * originalCoinModel() const {
164  return originalCoinModel_;
165  }
167  void setOriginalSolver(OsiClpSolverInterface * originalSolver);
169  void setOriginalCoinModel(CoinModel * originalCoinModel);
171  inline int numberCutGenerators() const {
172  return numberCutGenerators_;
173  }
175  inline CglCutGenerator ** cutGeneratorArray() const {
176  return cutGenerator_;
177  }
179  inline double startTime() const {
180  return startTime_;
181  }
183  inline void setPrinting(bool onOff) {
184  noPrinting_ = !onOff;
185  }
187  inline void setReadMode(int value) {
188  readMode_ = value;
189  }
191 private:
193 
194 
197 
200 
211  OsiClpSolverInterface * originalSolver_;
213  CoinModel * originalCoinModel_;
215  CglCutGenerator ** cutGenerator_;
223  double startTime_;
225  CbcOrClpParam * parameters_;
229  bool doMiplib_;
235 };
236 //#############################################################################
237 
239 typedef struct {
240  // Priorities
241  int * priorities_;
242  // SOS priorities
244  // Direction to branch first
246  // Input solution
247  double * primalSolution_;
248  // Down pseudo costs
249  double * pseudoDown_;
250  // Up pseudo costs
251  double * pseudoUp_;
253 
254 
259 class CbcUser {
260 
261 public:
263 
264 
271  virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
272  return -1;
273  }
274 
282  virtual void exportSolution(CbcSolver * /*model*/,
283  int /*mode*/, const char * /*message*/ = NULL) {}
284 
286  virtual void exportData(CbcSolver * /*model*/) {}
287 
289  virtual void fillInformation(CbcSolver * /*model*/,
290  CbcSolverUsefulData & /*info*/) {}
292 
294 
295 
296  inline CoinModel *coinModel() const {
297  return coinModel_;
298  }
300  virtual void * stuff() {
301  return NULL;
302  }
304  inline std::string name() const {
305  return userName_;
306  }
308  virtual void solve(CbcSolver * model, const char * options) = 0;
310  virtual bool canDo(const char * options) = 0;
312 
314 
315 
316  CbcUser();
317 
319  CbcUser(const CbcUser & rhs);
320 
322  CbcUser & operator=(const CbcUser& rhs);
323 
325  virtual CbcUser * clone() const = 0;
326 
328  virtual ~CbcUser ();
330 
331 protected:
333 
334 
336  CoinModel * coinModel_;
337 
339  std::string userName_;
340 
342 };
343 //#############################################################################
344 
350 class CbcStopNow {
351 
352 public:
354 
355 
368  virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/) {
369  return 0;
370  }
372 
374 
375 
376  CbcStopNow();
377 
380  CbcStopNow(const CbcStopNow & rhs);
381 
383  CbcStopNow & operator=(const CbcStopNow& rhs);
384 
386  virtual CbcStopNow * clone() const;
387 
389  virtual ~CbcStopNow ();
391 
392 private:
394 
395 
396 };
397 #endif
398