Cbc  2.10.8
CbcSolver.hpp
Go to the documentation of this file.
1 /* $Id$ */
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 
17 #ifndef CbcSolver_H
18 #define CbcSolver_H
19 
20 #include <string>
21 #include <vector>
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 
77  CbcSolver();
79 
81  CbcSolver(const OsiClpSolverInterface &);
82 
84  CbcSolver(const CbcModel &);
85 
88  CbcSolver(const CbcSolver &rhs);
89 
92 
105  void addUserFunction(CbcUser *function);
107  void setUserCallBack(CbcStopNow *function);
109  void addCutGenerator(CglCutGenerator *generator);
111 
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 
132  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  {
145  return &model_;
146  }
148  inline CbcModel *babModel()
149  {
150  return babModel_;
151  }
153  inline int numberUserFunctions() const
154  {
155  return numberUserFunctions_;
156  }
158  inline CbcUser **userFunctionArray() const
159  {
160  return userFunction_;
161  }
163  inline OsiClpSolverInterface *originalSolver() const
164  {
165  return originalSolver_;
166  }
168  inline CoinModel *originalCoinModel() const
169  {
170  return originalCoinModel_;
171  }
173  void setOriginalSolver(OsiClpSolverInterface *originalSolver);
177  inline int numberCutGenerators() const
178  {
179  return numberCutGenerators_;
180  }
182  inline CglCutGenerator **cutGeneratorArray() const
183  {
184  return cutGenerator_;
185  }
187  inline double startTime() const
188  {
189  return startTime_;
190  }
192  inline void setPrinting(bool onOff)
193  {
194  noPrinting_ = !onOff;
195  }
197  inline void setReadMode(int value)
198  {
199  readMode_ = value;
200  }
202 private:
204 
205 
208 
211 
222  OsiClpSolverInterface *originalSolver_;
224  CoinModel *originalCoinModel_;
226  CglCutGenerator **cutGenerator_;
234  double startTime_;
236  std::vector< CbcOrClpParam > parameters_;
238  bool doMiplib_;
244 };
245 //#############################################################################
246 
248 typedef struct {
249  // Priorities
251  // SOS priorities
253  // Direction to branch first
255  // Input solution
257  // Down pseudo costs
258  double *pseudoDown_;
259  // Up pseudo costs
260  double *pseudoUp_;
262 
263 //#############################################################################
264 
271 
272 public:
274 
277 
281 
284 
288 
290 
291  // For time
292  double totalTime_;
293  // Parameters
294  std::vector<CbcOrClpParam> parameters_;
295  // Printing
297  // Whether to use signal handler
299  // Default pump tuning
302 };
304 // When we want to load up CbcModel with options first
305 void CbcMain0(CbcModel &babSolver, CbcSolverUsefulData &solverData);
306 int CbcMain1(int argc, const char *argv[], CbcModel &babSolver, int(CbcModel *currentSolver, int whereFrom), CbcSolverUsefulData &solverData);
307 
308 //#############################################################################
309 
314 class CbcUser {
315 
316 public:
318 
319 
326  virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/)
327  {
328  return -1;
329  }
330 
338  virtual void exportSolution(CbcSolver * /*model*/,
339  int /*mode*/, const char * /*message*/ = NULL) {}
340 
342  virtual void exportData(CbcSolver * /*model*/) {}
343 
345  virtual void fillInformation(CbcSolver * /*model*/,
346  CbcSolverUsefulData & /*info*/) {}
348 
350 
351  inline CoinModel *coinModel() const
353  {
354  return coinModel_;
355  }
357  virtual void *stuff()
358  {
359  return NULL;
360  }
362  inline std::string name() const
363  {
364  return userName_;
365  }
367  virtual void solve(CbcSolver *model, const char *options) = 0;
369  virtual bool canDo(const char *options) = 0;
371 
373 
374  CbcUser();
376 
378  CbcUser(const CbcUser &rhs);
379 
381  CbcUser &operator=(const CbcUser &rhs);
382 
384  virtual CbcUser *clone() const = 0;
385 
387  virtual ~CbcUser();
389 
390 protected:
392 
393 
395  CoinModel *coinModel_;
396 
398  std::string userName_;
399 
401 };
402 //#############################################################################
403 
409 class CbcStopNow {
410 
411 public:
413 
414 
427  virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/)
428  {
429  return 0;
430  }
432 
434 
435  CbcStopNow();
437 
440  CbcStopNow(const CbcStopNow &rhs);
441 
444 
446  virtual CbcStopNow *clone() const;
447 
449  virtual ~CbcStopNow();
451 
452 private:
454 
455 
456 };
457 #endif
458 
459 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
460 */
int CbcMain1(int argc, const char *argv[], CbcModel &babSolver, int(CbcModel *currentSolver, int whereFrom), CbcSolverUsefulData &solverData)
void CbcMain0(CbcModel &babSolver, CbcSolverUsefulData &solverData)
And this uses it.
Simple Branch and bound class.
Definition: CbcModel.hpp:100
The CbcSolver class was taken out at a 9/12/09 meeting This is a feeble replacement.
Definition: CbcSolver.hpp:270
CbcSolverUsefulData(const CbcSolverUsefulData &rhs)
Copy constructor .
CbcSolverUsefulData()
Default Constructor.
std::vector< CbcOrClpParam > parameters_
Definition: CbcSolver.hpp:294
CbcSolverUsefulData & operator=(const CbcSolverUsefulData &rhs)
Assignment operator.
~CbcSolverUsefulData()
Destructor.
This allows the use of the standalone solver in a flexible manner.
Definition: CbcSolver.hpp:55
CbcModel * babModel_
Updated model.
Definition: CbcSolver.hpp:210
CbcSolver(const CbcSolver &rhs)
Copy constructor .
void setReadMode(int value)
Where to start reading commands.
Definition: CbcSolver.hpp:197
void updateModel(ClpSimplex *model2, int returnMode)
1 - add heuristics to model 2 - do heuristics (and set cutoff and best solution) 3 - for miplib test ...
int * statusUserFunction_
Status of user functions 0 - not used 1 - needs cbc_load 2 - available - data in coinModel 3 - data l...
Definition: CbcSolver.hpp:220
bool doMiplib_
Whether to do miplib test.
Definition: CbcSolver.hpp:238
void setPrinting(bool onOff)
Whether to print to std::cout.
Definition: CbcSolver.hpp:192
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...
OsiClpSolverInterface * originalSolver_
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:222
CoinModel * originalCoinModel() const
Copy of model on initial load.
Definition: CbcSolver.hpp:168
CbcModel * babModel()
Return updated Cbc model.
Definition: CbcSolver.hpp:148
CbcModel model_
Reference model.
Definition: CbcSolver.hpp:207
void addCutGenerator(CglCutGenerator *generator)
Add cut generator.
CoinModel * originalCoinModel_
Copy of model on initial load.
Definition: CbcSolver.hpp:224
int numberCutGenerators() const
Number of cutgenerators.
Definition: CbcSolver.hpp:177
void setUserCallBack(CbcStopNow *function)
Set user call back.
CbcUser * userFunction(const char *name) const
User function (NULL if no match)
void fillValuesInSolver()
Set default values in solvers from parameters.
std::vector< CbcOrClpParam > parameters_
Parameters and values.
Definition: CbcSolver.hpp:236
CbcUser ** userFunctionArray() const
User function array.
Definition: CbcSolver.hpp:158
double startTime_
Cpu time at instantiation.
Definition: CbcSolver.hpp:234
CglCutGenerator ** cutGeneratorArray() const
Cut generator array.
Definition: CbcSolver.hpp:182
double doubleValue(CbcOrClpParameterType type) const
Get double value.
CglCutGenerator ** cutGenerator_
Cut generators.
Definition: CbcSolver.hpp:226
int numberCutGenerators_
Number of cut generators.
Definition: CbcSolver.hpp:230
int solve(const char *input, int returnMode)
This takes a list of commands, does "stuff" and returns returnMode - 0 model and solver untouched - b...
CbcSolver(const CbcModel &)
Constructor from model.
int numberUserFunctions() const
Number of userFunctions.
Definition: CbcSolver.hpp:153
int numberUserFunctions_
Number of user functions.
Definition: CbcSolver.hpp:228
int intValue(CbcOrClpParameterType type) const
Get int value.
void setIntValue(CbcOrClpParameterType type, int value)
Set int value.
CbcSolver(const OsiClpSolverInterface &)
Constructor from solver.
CbcUser ** userFunction_
User functions.
Definition: CbcSolver.hpp:213
void fillParameters()
Fill with standard parameters.
double startTime() const
Start time.
Definition: CbcSolver.hpp:187
void setDoubleValue(CbcOrClpParameterType type, double value)
Set double value.
CbcModel * model()
Return original Cbc model.
Definition: CbcSolver.hpp:143
void addUserFunction(CbcUser *function)
Add user function.
int * analyze(OsiClpSolverInterface *solverMod, int &numberChanged, double &increment, bool changeInt, CoinMessageHandler *generalMessageHandler)
void setOriginalCoinModel(CoinModel *originalCoinModel)
Copy of model on initial load.
bool noPrinting_
Whether to print to std::cout.
Definition: CbcSolver.hpp:240
~CbcSolver()
Destructor.
CbcStopNow * callBack_
Stop now stuff.
Definition: CbcSolver.hpp:232
CbcSolver()
Default Constructor.
OsiClpSolverInterface * originalSolver() const
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:163
int readMode_
Where to start reading commands.
Definition: CbcSolver.hpp:242
void setOriginalSolver(OsiClpSolverInterface *originalSolver)
Copy of model on initial load (will contain output solutions)
CbcSolver & operator=(const CbcSolver &rhs)
Assignment operator.
Support the use of a call back class to decide whether to stop.
Definition: CbcSolver.hpp:409
virtual CbcStopNow * clone() const
Clone.
CbcStopNow & operator=(const CbcStopNow &rhs)
Assignment operator.
CbcStopNow()
Default Constructor.
virtual ~CbcStopNow()
Destructor.
CbcStopNow(const CbcStopNow &rhs)
Copy constructor .
virtual int callBack(CbcModel *, int)
Import.
Definition: CbcSolver.hpp:427
A class to allow the use of unknown user functionality.
Definition: CbcSolver.hpp:314
virtual void solve(CbcSolver *model, const char *options)=0
Solve (whatever that means)
virtual int importData(CbcSolver *, int &, char **)
Import - gets full command arguments.
Definition: CbcSolver.hpp:326
virtual void fillInformation(CbcSolver *, CbcSolverUsefulData &)
Get useful stuff.
Definition: CbcSolver.hpp:345
std::string name() const
Name.
Definition: CbcSolver.hpp:362
CoinModel * coinModel() const
CoinModel if valid.
Definition: CbcSolver.hpp:352
std::string userName_
Name of user function.
Definition: CbcSolver.hpp:398
CbcUser & operator=(const CbcUser &rhs)
Assignment operator.
CbcUser()
Default Constructor.
virtual bool canDo(const char *options)=0
Returns true if function knows about option.
CbcUser(const CbcUser &rhs)
Copy constructor.
virtual ~CbcUser()
Destructor.
virtual void exportData(CbcSolver *)
Export Data (i.e. at very end)
Definition: CbcSolver.hpp:342
virtual void * stuff()
Other info - needs expanding.
Definition: CbcSolver.hpp:357
CoinModel * coinModel_
CoinModel.
Definition: CbcSolver.hpp:395
virtual void exportSolution(CbcSolver *, int, const char *=NULL)
Export.
Definition: CbcSolver.hpp:338
virtual CbcUser * clone() const =0
Clone.
Structure to hold useful arrays.
Definition: CbcSolver.hpp:248
double * primalSolution_
Definition: CbcSolver.hpp:256