Cbc  2.9.8
CbcSolver.hpp
Go to the documentation of this file.
1 /* $Id: CbcSolver.hpp 1998 2013-12-19 18:11:05Z 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 
240 typedef struct {
241  // Priorities
242  int * priorities_;
243  // SOS priorities
245  // Direction to branch first
247  // Input solution
248  double * primalSolution_;
249  // Down pseudo costs
250  double * pseudoDown_;
251  // Up pseudo costs
252  double * pseudoUp_;
254 
255 //#############################################################################
256 
263 
264 public:
266 
269 
273 
276 
280 
282 
283  // For time
284  double totalTime_;
285  // Parameters
286  CbcOrClpParam parameters_[CBCMAXPARAMETERS];
287  // Printing
289  // Whether to use signal handler
291  // Number of Parameters
293  // Default pump tuning
296 };
298 // When we want to load up CbcModel with options first
299 void CbcMain0 (CbcModel & babSolver,CbcSolverUsefulData & solverData);
300 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom),CbcSolverUsefulData & solverData);
301 
302 //#############################################################################
303 
308 class CbcUser {
309 
310 public:
312 
313 
320  virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
321  return -1;
322  }
323 
331  virtual void exportSolution(CbcSolver * /*model*/,
332  int /*mode*/, const char * /*message*/ = NULL) {}
333 
335  virtual void exportData(CbcSolver * /*model*/) {}
336 
338  virtual void fillInformation(CbcSolver * /*model*/,
339  CbcSolverUsefulData & /*info*/) {}
341 
343 
344  inline CoinModel *coinModel() const {
346  return coinModel_;
347  }
349  virtual void * stuff() {
350  return NULL;
351  }
353  inline std::string name() const {
354  return userName_;
355  }
357  virtual void solve(CbcSolver * model, const char * options) = 0;
359  virtual bool canDo(const char * options) = 0;
361 
363 
364  CbcUser();
366 
368  CbcUser(const CbcUser & rhs);
369 
371  CbcUser & operator=(const CbcUser& rhs);
372 
374  virtual CbcUser * clone() const = 0;
375 
377  virtual ~CbcUser ();
379 
380 protected:
382 
383 
385  CoinModel * coinModel_;
386 
388  std::string userName_;
389 
391 };
392 //#############################################################################
393 
399 class CbcStopNow {
400 
401 public:
403 
404 
417  virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/) {
418  return 0;
419  }
421 
423 
424  CbcStopNow();
426 
429  CbcStopNow(const CbcStopNow & rhs);
430 
432  CbcStopNow & operator=(const CbcStopNow& rhs);
433 
435  virtual CbcStopNow * clone() const;
436 
438  virtual ~CbcStopNow ();
440 
441 private:
443 
444 
445 };
446 #endif
447 
CbcUser ** userFunctionArray() const
User function array.
Definition: CbcSolver.hpp:156
void fillValuesInSolver()
Set default values in solvers from parameters.
int intValue(CbcOrClpParameterType type) const
Get int value.
virtual void * stuff()
Other info - needs expanding.
Definition: CbcSolver.hpp:349
int numberCutGenerators() const
Number of cutgenerators.
Definition: CbcSolver.hpp:172
virtual void exportSolution(CbcSolver *, int, const char *=NULL)
Export.
Definition: CbcSolver.hpp:331
CoinModel * originalCoinModel() const
Copy of model on initial load.
Definition: CbcSolver.hpp:164
CbcModel * model()
Return original Cbc model.
Definition: CbcSolver.hpp:144
void setOriginalCoinModel(CoinModel *originalCoinModel)
Copy of model on initial load.
std::string userName_
Name of user function.
Definition: CbcSolver.hpp:388
virtual void exportData(CbcSolver *)
Export Data (i.e. at very end)
Definition: CbcSolver.hpp:335
void setReadMode(int value)
Where to start reading commands.
Definition: CbcSolver.hpp:188
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:308
CbcUser * userFunction(const char *name) const
User function (NULL if no match)
Support the use of a call back class to decide whether to stop.
Definition: CbcSolver.hpp:399
void CbcMain0(CbcModel &babSolver, CbcSolverUsefulData &solverData)
And this uses it.
This allows the use of the standalone solver in a flexible manner.
Definition: CbcSolver.hpp:56
virtual void fillInformation(CbcSolver *, CbcSolverUsefulData &)
Get useful stuff.
Definition: CbcSolver.hpp:338
CbcModel * babModel()
Return updated Cbc model.
Definition: CbcSolver.hpp:148
void fillParameters()
Fill with standard parameters.
~CbcSolver()
Destructor.
void setIntValue(CbcOrClpParameterType type, int value)
Set int value.
double startTime() const
Start time.
Definition: CbcSolver.hpp:180
void setDoubleValue(CbcOrClpParameterType type, double value)
Set double value.
double * primalSolution_
Definition: CbcSolver.hpp:248
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:320
The CbcSolver class was taken out at a 9/12/09 meeting This is a feeble replacement.
Definition: CbcSolver.hpp:262
virtual int callBack(CbcModel *, int)
Import.
Definition: CbcSolver.hpp:417
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.
CglCutGenerator ** cutGeneratorArray() const
Cut generator array.
Definition: CbcSolver.hpp:176
double doubleValue(CbcOrClpParameterType type) const
Get double value.
CoinModel * coinModel_
CoinModel.
Definition: CbcSolver.hpp:385
std::string name() const
Name.
Definition: CbcSolver.hpp:353
int numberUserFunctions() const
Number of userFunctions.
Definition: CbcSolver.hpp:152
void setOriginalSolver(OsiClpSolverInterface *originalSolver)
Copy of model on initial load (will contain output solutions)
void setPrinting(bool onOff)
Whether to print to std::cout.
Definition: CbcSolver.hpp:184
OsiClpSolverInterface * originalSolver() const
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:160
Simple Branch and bound class.
Definition: CbcModel.hpp:101
Structure to hold useful arrays.
Definition: CbcSolver.hpp:240
int * analyze(OsiClpSolverInterface *solverMod, int &numberChanged, double &increment, bool changeInt, CoinMessageHandler *generalMessageHandler)
CbcSolver & operator=(const CbcSolver &rhs)
Assignment operator.
void setUserCallBack(CbcStopNow *function)
Set user call back.
CbcSolver()
Default Constructor.