Cbc  2.8.12
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CbcSolver.hpp
Go to the documentation of this file.
1 /* $Id: CbcSolver.hpp 2004 2014-01-14 14:50:43Z forrest $ */
2 // Copyright (C) 2007, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 
18 #ifndef CbcSolver_H
19 #define CbcSolver_H
20 
21 #include <string>
22 #include <vector>
23 #include "CoinMessageHandler.hpp"
24 #include "OsiClpSolverInterface.hpp"
25 
26 #if CBC_OTHER_SOLVER==1
27 #include "OsiCpxSolverInterface.hpp"
28 #endif
29 
30 #include "CbcModel.hpp"
31 #include "CbcOrClpParam.hpp"
32 
33 class CbcUser;
34 class CbcStopNow;
35 class CglCutGenerator;
36 
37 //#############################################################################
38 
56 class CbcSolver {
57 
58 public:
60 
61 
67  int solve(int argc, const char * argv[], int returnMode);
74  int solve(const char * input, int returnMode);
76 
78  CbcSolver();
80 
82  CbcSolver(const OsiClpSolverInterface &);
83 
85  CbcSolver(const CbcModel &);
86 
89  CbcSolver(const CbcSolver & rhs);
90 
92  CbcSolver & operator=(const CbcSolver& rhs);
93 
95  ~CbcSolver ();
97  void fillParameters();
104  void fillValuesInSolver();
106  void addUserFunction(CbcUser * function);
108  void setUserCallBack(CbcStopNow * function);
110  void addCutGenerator(CglCutGenerator * generator);
112 
114  // analyze model
115  int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
116  bool changeInt, CoinMessageHandler * generalMessageHandler);
122  //int doHeuristics(CbcModel * model, int type);
129  void updateModel(ClpSimplex * model2, int returnMode);
131 
133  int intValue(CbcOrClpParameterType type) const;
136  void setIntValue(CbcOrClpParameterType type, int value);
138  double doubleValue(CbcOrClpParameterType type) const;
140  void setDoubleValue(CbcOrClpParameterType type, double value);
142  CbcUser * userFunction(const char * name) const;
144  inline CbcModel * model() {
145  return &model_;
146  }
148  inline CbcModel * babModel() {
149  return babModel_;
150  }
152  inline int numberUserFunctions() const {
153  return numberUserFunctions_;
154  }
156  inline CbcUser ** userFunctionArray() const {
157  return userFunction_;
158  }
160  inline OsiClpSolverInterface * originalSolver() const {
161  return originalSolver_;
162  }
164  inline CoinModel * originalCoinModel() const {
165  return originalCoinModel_;
166  }
168  void setOriginalSolver(OsiClpSolverInterface * originalSolver);
170  void setOriginalCoinModel(CoinModel * originalCoinModel);
172  inline int numberCutGenerators() const {
173  return numberCutGenerators_;
174  }
176  inline CglCutGenerator ** cutGeneratorArray() const {
177  return cutGenerator_;
178  }
180  inline double startTime() const {
181  return startTime_;
182  }
184  inline void setPrinting(bool onOff) {
185  noPrinting_ = !onOff;
186  }
188  inline void setReadMode(int value) {
189  readMode_ = value;
190  }
192 private:
194 
195 
197  CbcModel model_;
198 
200  CbcModel * babModel_;
201 
203  CbcUser ** userFunction_;
210  int * statusUserFunction_;
212  OsiClpSolverInterface * originalSolver_;
214  CoinModel * originalCoinModel_;
216  CglCutGenerator ** cutGenerator_;
218  int numberUserFunctions_;
220  int numberCutGenerators_;
222  CbcStopNow * callBack_;
224  double startTime_;
226  CbcOrClpParam * parameters_;
228  int numberParameters_ ;
230  bool doMiplib_;
232  bool noPrinting_;
234  int readMode_;
236 };
237 //#############################################################################
238 
245 
246 public:
248 
251 
255 
258 
262 
264 
265  // For time
266  double totalTime_;
267  // Parameters
268  CbcOrClpParam parameters_[CBCMAXPARAMETERS];
269  // Printing
271  // Whether to use signal handler
273  // Number of Parameters
275  // Default pump tuning
278 };
280 // When we want to load up CbcModel with options first
281 void CbcMain0 (CbcModel & babSolver,CbcSolverUsefulData & solverData);
282 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom),CbcSolverUsefulData & solverData);
283 
284 //#############################################################################
285 
290 class CbcUser {
291 
292 public:
294 
295 
302  virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
303  return -1;
304  }
305 
313  virtual void exportSolution(CbcSolver * /*model*/,
314  int /*mode*/, const char * /*message*/ = NULL) {}
315 
317  virtual void exportData(CbcSolver * /*model*/) {}
318 
320  virtual void fillInformation(CbcSolver * /*model*/,
321  CbcSolverUsefulData & /*info*/) {}
323 
325 
326  inline CoinModel *coinModel() const {
328  return coinModel_;
329  }
331  virtual void * stuff() {
332  return NULL;
333  }
335  inline std::string name() const {
336  return userName_;
337  }
339  virtual void solve(CbcSolver * model, const char * options) = 0;
341  virtual bool canDo(const char * options) = 0;
343 
345 
346  CbcUser();
348 
350  CbcUser(const CbcUser & rhs);
351 
353  CbcUser & operator=(const CbcUser& rhs);
354 
356  virtual CbcUser * clone() const = 0;
357 
359  virtual ~CbcUser ();
361 
362 protected:
364 
365 
367  CoinModel * coinModel_;
368 
370  std::string userName_;
371 
373 };
374 //#############################################################################
375 
381 class CbcStopNow {
382 
383 public:
385 
386 
399  virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/) {
400  return 0;
401  }
403 
405 
406  CbcStopNow();
408 
411  CbcStopNow(const CbcStopNow & rhs);
412 
414  CbcStopNow & operator=(const CbcStopNow& rhs);
415 
417  virtual CbcStopNow * clone() const;
418 
420  virtual ~CbcStopNow ();
422 
423 private:
425 
426 
427 };
428 #endif
429 
CoinModel * coinModel() const
CoinModel if valid.
Definition: CbcSolver.hpp:327
void fillValuesInSolver()
Set default values in solvers from parameters.
CbcUser & operator=(const CbcUser &rhs)
Assignment operator.
virtual void * stuff()
Other info - needs expanding.
Definition: CbcSolver.hpp:331
CbcSolverUsefulData()
Default Constructor.
CbcUser * userFunction(const char *name) const
User function (NULL if no match)
virtual void exportSolution(CbcSolver *, int, const char *=NULL)
Export.
Definition: CbcSolver.hpp:313
CbcModel * model()
Return original Cbc model.
Definition: CbcSolver.hpp:144
~CbcSolverUsefulData()
Destructor.
void setOriginalCoinModel(CoinModel *originalCoinModel)
Copy of model on initial load.
CbcUser()
Default Constructor.
double startTime() const
Start time.
Definition: CbcSolver.hpp:180
OsiClpSolverInterface * originalSolver() const
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:160
std::string userName_
Name of user function.
Definition: CbcSolver.hpp:370
CglCutGenerator ** cutGeneratorArray() const
Cut generator array.
Definition: CbcSolver.hpp:176
virtual void exportData(CbcSolver *)
Export Data (i.e. at very end)
Definition: CbcSolver.hpp:317
void setReadMode(int value)
Where to start reading commands.
Definition: CbcSolver.hpp:188
int intValue(CbcOrClpParameterType type) const
Get int value.
double doubleValue(CbcOrClpParameterType type) const
Get double value.
void addCutGenerator(CglCutGenerator *generator)
Add cut generator.
int CbcMain1(int argc, const char *argv[], CbcModel &babSolver, int(CbcModel *currentSolver, int whereFrom), CbcSolverUsefulData &solverData)
A class to allow the use of unknown user functionality.
Definition: CbcSolver.hpp:290
Support the use of a call back class to decide whether to stop.
Definition: CbcSolver.hpp:381
void CbcMain0(CbcModel &babSolver, CbcSolverUsefulData &solverData)
And this uses it.
CbcStopNow & operator=(const CbcStopNow &rhs)
Assignment operator.
This allows the use of the standalone solver in a flexible manner.
Definition: CbcSolver.hpp:56
virtual ~CbcStopNow()
Destructor.
virtual CbcUser * clone() const =0
Clone.
virtual void fillInformation(CbcSolver *, CbcSolverUsefulData &)
Get useful stuff.
Definition: CbcSolver.hpp:320
CbcModel * babModel()
Return updated Cbc model.
Definition: CbcSolver.hpp:148
void fillParameters()
Fill with standard parameters.
CbcSolverUsefulData & operator=(const CbcSolverUsefulData &rhs)
Assignment operator.
~CbcSolver()
Destructor.
virtual bool canDo(const char *options)=0
Returns true if function knows about option.
void setIntValue(CbcOrClpParameterType type, int value)
Set int value.
CbcOrClpParam parameters_[CBCMAXPARAMETERS]
Definition: CbcSolver.hpp:268
void setDoubleValue(CbcOrClpParameterType type, double value)
Set double value.
CoinModel * originalCoinModel() const
Copy of model on initial load.
Definition: CbcSolver.hpp:164
int solve(int argc, const char *argv[], int returnMode)
This takes a list of commands, does "stuff" and returns returnMode - 0 model and solver untouched - b...
virtual int importData(CbcSolver *, int &, char **)
Import - gets full command arguments.
Definition: CbcSolver.hpp:302
The CbcSolver class was taken out at a 9/12/09 meeting This is a feeble replacement.
Definition: CbcSolver.hpp:244
virtual ~CbcUser()
Destructor.
virtual int callBack(CbcModel *, int)
Import.
Definition: CbcSolver.hpp:399
void updateModel(ClpSimplex *model2, int returnMode)
1 - add heuristics to model 2 - do heuristics (and set cutoff and best solution) 3 - for miplib test ...
void addUserFunction(CbcUser *function)
Add user function.
CbcStopNow()
Default Constructor.
CbcUser ** userFunctionArray() const
User function array.
Definition: CbcSolver.hpp:156
int numberUserFunctions() const
Number of userFunctions.
Definition: CbcSolver.hpp:152
std::string name() const
Name.
Definition: CbcSolver.hpp:335
CoinModel * coinModel_
CoinModel.
Definition: CbcSolver.hpp:367
void setOriginalSolver(OsiClpSolverInterface *originalSolver)
Copy of model on initial load (will contain output solutions)
virtual CbcStopNow * clone() const
Clone.
void setPrinting(bool onOff)
Whether to print to std::cout.
Definition: CbcSolver.hpp:184
int numberCutGenerators() const
Number of cutgenerators.
Definition: CbcSolver.hpp:172
Simple Branch and bound class.
Definition: CbcModel.hpp:100
int * analyze(OsiClpSolverInterface *solverMod, int &numberChanged, double &increment, bool changeInt, CoinMessageHandler *generalMessageHandler)
virtual void solve(CbcSolver *model, const char *options)=0
Solve (whatever that means)
CbcSolver & operator=(const CbcSolver &rhs)
Assignment operator.
void setUserCallBack(CbcStopNow *function)
Set user call back.
CbcSolver()
Default Constructor.