Cbc  2.9.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
25 
26 #if CBC_OTHER_SOLVER==1
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 
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  }
161  return originalSolver_;
162  }
164  inline CoinModel * originalCoinModel() const {
165  return originalCoinModel_;
166  }
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 
198 
201 
224  double startTime_;
230  bool doMiplib_;
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
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 
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 
CoinModel * coinModel() const
CoinModel if valid.
Definition: CbcSolver.hpp:345
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:349
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:331
CbcModel * model()
Return original Cbc model.
Definition: CbcSolver.hpp:144
~CbcSolverUsefulData()
Destructor.
void setOriginalCoinModel(CoinModel *originalCoinModel)
Copy of model on initial load.
int numberUserFunctions_
Number of user functions.
Definition: CbcSolver.hpp:218
CbcUser()
Default Constructor.
double startTime() const
Start time.
Definition: CbcSolver.hpp:180
OsiClpSolverInterface * originalSolver_
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:212
CbcStopNow * callBack_
Stop now stuff.
Definition: CbcSolver.hpp:222
OsiClpSolverInterface * originalSolver() const
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:160
int numberCutGenerators_
Number of cut generators.
Definition: CbcSolver.hpp:220
std::string userName_
Name of user function.
Definition: CbcSolver.hpp:388
This is a simple minded model which is stored in a format which makes it easier to construct and modi...
Definition: CoinModel.hpp:161
int readMode_
Where to start reading commands.
Definition: CbcSolver.hpp:234
Clp Solver Interface.
CglCutGenerator ** cutGeneratorArray() const
Cut generator array.
Definition: CbcSolver.hpp:176
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
Very simple class for setting parameters.
CbcUser ** userFunction_
User functions.
Definition: CbcSolver.hpp:203
int intValue(CbcOrClpParameterType type) const
Get int value.
Base class for message handling.
double doubleValue(CbcOrClpParameterType type) const
Get double value.
void addCutGenerator(CglCutGenerator *generator)
Add cut generator.
A class to allow the use of unknown user functionality.
Definition: CbcSolver.hpp:308
CbcOrClpParam * parameters_
Parameters and values.
Definition: CbcSolver.hpp:226
Support the use of a call back class to decide whether to stop.
Definition: CbcSolver.hpp:399
CbcStopNow & operator=(const CbcStopNow &rhs)
Assignment operator.
This is a first attempt at a message handler.
This allows the use of the standalone solver in a flexible manner.
Definition: CbcSolver.hpp:56
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:70
virtual ~CbcStopNow()
Destructor.
virtual CbcUser * clone() const =0
Clone.
virtual void fillInformation(CbcSolver *, CbcSolverUsefulData &)
Get useful stuff.
Definition: CbcSolver.hpp:338
CbcModel * babModel()
Return updated Cbc model.
Definition: CbcSolver.hpp:148
Cut Generator Base Class.
CbcModel * babModel_
Updated model.
Definition: CbcSolver.hpp:200
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:286
void setDoubleValue(CbcOrClpParameterType type, double value)
Set double value.
CoinModel * originalCoinModel() const
Copy of model on initial load.
Definition: CbcSolver.hpp:164
double * primalSolution_
Definition: CbcSolver.hpp:248
int * statusUserFunction_
Status of user functions 0 - not used 1 - needs cbc_load 2 - available - data in coinModel 3 - data l...
Definition: CbcSolver.hpp:210
void CbcMain0(CbcModel &babSolver)
int solve(int argc, const char *argv[], int returnMode)
This takes a list of commands, does &quot;stuff&quot; and returns returnMode - 0 model and solver untouched - b...
virtual int importData(CbcSolver *, int &, char **)
Import - gets full command arguments.
Definition: CbcSolver.hpp:320
CglCutGenerator ** cutGenerator_
Cut generators.
Definition: CbcSolver.hpp:216
The CbcSolver class was taken out at a 9/12/09 meeting This is a feeble replacement.
Definition: CbcSolver.hpp:262
virtual ~CbcUser()
Destructor.
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 ...
double startTime_
Cpu time at instantiation.
Definition: CbcSolver.hpp:224
CoinModel * originalCoinModel_
Copy of model on initial load.
Definition: CbcSolver.hpp:214
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
bool doMiplib_
Whether to do miplib test.
Definition: CbcSolver.hpp:230
CbcOrClpParameterType
Parameter codes.
int CbcMain1(int argc, const char *argv[], CbcModel &babSolver)
std::string name() const
Name.
Definition: CbcSolver.hpp:353
CoinModel * coinModel_
CoinModel.
Definition: CbcSolver.hpp:385
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
#define CBCMAXPARAMETERS
bool noPrinting_
Whether to print to std::cout.
Definition: CbcSolver.hpp:232
int numberCutGenerators() const
Number of cutgenerators.
Definition: CbcSolver.hpp:172
Simple Branch and bound class.
Definition: CbcModel.hpp:101
Structure to hold useful arrays.
Definition: CbcSolver.hpp:240
CbcModel model_
Reference model.
Definition: CbcSolver.hpp:197
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.
int numberParameters_
Number of parameters.
Definition: CbcSolver.hpp:228
void setUserCallBack(CbcStopNow *function)
Set user call back.
CbcSolver()
Default Constructor.