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 
77  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 
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  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  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  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  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 
virtual void exportSolution(CbcSolver *, int, const char *=NULL)
Export.
Definition: CbcSolver.hpp:282
CbcStopNow()
Default Constructor.
CbcModel * babModel_
Updated model.
Definition: CbcSolver.hpp:199
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 * primalSolution_
Definition: CbcSolver.hpp:247
CbcUser & operator=(const CbcUser &rhs)
Assignment operator.
void setDoubleValue(CbcOrClpParameterType type, double value)
Set double value.
CbcModel * babModel()
Return updated Cbc model.
Definition: CbcSolver.hpp:147
int numberParameters_
Number of parameters.
Definition: CbcSolver.hpp:227
A class to allow the use of unknown user functionality.
Definition: CbcSolver.hpp:259
CoinModel * coinModel() const
CoinModel if valid.
Definition: CbcSolver.hpp:296
CbcModel model_
Reference model.
Definition: CbcSolver.hpp:196
std::string name() const
Name.
Definition: CbcSolver.hpp:304
OsiClpSolverInterface * originalSolver() const
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:159
int intValue(CbcOrClpParameterType type) const
Get int value.
std::string userName_
Name of user function.
Definition: CbcSolver.hpp:339
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...
CoinModel * originalCoinModel_
Copy of model on initial load.
Definition: CbcSolver.hpp:213
virtual CbcStopNow * clone() const
Clone.
CbcUser * userFunction(const char *name) const
User function (NULL if no match)
double startTime_
Cpu time at instantiation.
Definition: CbcSolver.hpp:223
CbcSolver & operator=(const CbcSolver &rhs)
Assignment operator.
void addCutGenerator(CglCutGenerator *generator)
Add cut generator.
CoinModel * coinModel_
CoinModel.
Definition: CbcSolver.hpp:336
virtual void fillInformation(CbcSolver *, CbcSolverUsefulData &)
Get useful stuff.
Definition: CbcSolver.hpp:289
CbcUser()
Default Constructor.
CbcUser ** userFunctionArray() const
User function array.
Definition: CbcSolver.hpp:155
void setOriginalCoinModel(CoinModel *originalCoinModel)
Copy of model on initial load.
void fillParameters()
Fill with standard parameters.
This allows the use of the standalone solver in a flexible manner.
Definition: CbcSolver.hpp:55
virtual int callBack(CbcModel *, int)
Import.
Definition: CbcSolver.hpp:368
CbcStopNow & operator=(const CbcStopNow &rhs)
Assignment operator.
int readMode_
Where to start reading commands.
Definition: CbcSolver.hpp:233
int numberUserFunctions() const
Number of userFunctions.
Definition: CbcSolver.hpp:151
~CbcSolver()
Destructor.
CglCutGenerator ** cutGenerator_
Cut generators.
Definition: CbcSolver.hpp:215
virtual ~CbcStopNow()
Destructor.
virtual int importData(CbcSolver *, int &, char **)
Import - gets full command arguments.
Definition: CbcSolver.hpp:271
int numberUserFunctions_
Number of user functions.
Definition: CbcSolver.hpp:217
void setPrinting(bool onOff)
Whether to print to std::cout.
Definition: CbcSolver.hpp:183
void setOriginalSolver(OsiClpSolverInterface *originalSolver)
Copy of model on initial load (will contain output solutions)
int * analyze(OsiClpSolverInterface *solverMod, int &numberChanged, double &increment, bool changeInt, CoinMessageHandler *generalMessageHandler)
1 - add heuristics to model 2 - do heuristics (and set cutoff and best solution) 3 - for miplib test ...
virtual CbcUser * clone() const =0
Clone.
CglCutGenerator ** cutGeneratorArray() const
Cut generator array.
Definition: CbcSolver.hpp:175
Support the use of a call back class to decide whether to stop.
Definition: CbcSolver.hpp:350
void setUserCallBack(CbcStopNow *function)
Set user call back.
OsiClpSolverInterface * originalSolver_
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:211
double doubleValue(CbcOrClpParameterType type) const
Get double value.
int * statusUserFunction_
Status of user functions 0 - not used 1 - needs cbc_load 2 - available - data in coinModel 3 - data l...
Definition: CbcSolver.hpp:209
int numberCutGenerators() const
Number of cutgenerators.
Definition: CbcSolver.hpp:171
int numberCutGenerators_
Number of cut generators.
Definition: CbcSolver.hpp:219
bool noPrinting_
Whether to print to std::cout.
Definition: CbcSolver.hpp:231
virtual void * stuff()
Other info - needs expanding.
Definition: CbcSolver.hpp:300
virtual bool canDo(const char *options)=0
Returns true if function knows about option.
CbcUser ** userFunction_
User functions.
Definition: CbcSolver.hpp:202
virtual void solve(CbcSolver *model, const char *options)=0
Solve (whatever that means)
double startTime() const
Start time.
Definition: CbcSolver.hpp:179
virtual void exportData(CbcSolver *)
Export Data (i.e. at very end)
Definition: CbcSolver.hpp:286
Structure to hold useful arrays.
Definition: CbcSolver.hpp:239
void addUserFunction(CbcUser *function)
Add user function.
CbcModel * model()
Return original Cbc model.
Definition: CbcSolver.hpp:143
CbcSolver()
Default Constructor.
virtual ~CbcUser()
Destructor.
bool doMiplib_
Whether to do miplib test.
Definition: CbcSolver.hpp:229
Simple Branch and bound class.
Definition: CbcModel.hpp:98
void setReadMode(int value)
Where to start reading commands.
Definition: CbcSolver.hpp:187
CbcOrClpParam * parameters_
Parameters and values.
Definition: CbcSolver.hpp:225
CbcStopNow * callBack_
Stop now stuff.
Definition: CbcSolver.hpp:221
void setIntValue(CbcOrClpParameterType type, int value)
Set int value.
void fillValuesInSolver()
Set default values in solvers from parameters.
CoinModel * originalCoinModel() const
Copy of model on initial load.
Definition: CbcSolver.hpp:163