Cbc  2.8.7
 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 1902 2013-04-10 16:58:16Z stefan $ */
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 
260 class CbcUser {
261 
262 public:
264 
265 
272  virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
273  return -1;
274  }
275 
283  virtual void exportSolution(CbcSolver * /*model*/,
284  int /*mode*/, const char * /*message*/ = NULL) {}
285 
287  virtual void exportData(CbcSolver * /*model*/) {}
288 
290  virtual void fillInformation(CbcSolver * /*model*/,
291  CbcSolverUsefulData & /*info*/) {}
293 
295 
296  inline CoinModel *coinModel() const {
298  return coinModel_;
299  }
301  virtual void * stuff() {
302  return NULL;
303  }
305  inline std::string name() const {
306  return userName_;
307  }
309  virtual void solve(CbcSolver * model, const char * options) = 0;
311  virtual bool canDo(const char * options) = 0;
313 
315 
316  CbcUser();
318 
320  CbcUser(const CbcUser & rhs);
321 
323  CbcUser & operator=(const CbcUser& rhs);
324 
326  virtual CbcUser * clone() const = 0;
327 
329  virtual ~CbcUser ();
331 
332 protected:
334 
335 
337  CoinModel * coinModel_;
338 
340  std::string userName_;
341 
343 };
344 //#############################################################################
345 
351 class CbcStopNow {
352 
353 public:
355 
356 
369  virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/) {
370  return 0;
371  }
373 
375 
376  CbcStopNow();
378 
381  CbcStopNow(const CbcStopNow & rhs);
382 
384  CbcStopNow & operator=(const CbcStopNow& rhs);
385 
387  virtual CbcStopNow * clone() const;
388 
390  virtual ~CbcStopNow ();
392 
393 private:
395 
396 
397 };
398 #endif
399 
CoinModel * coinModel() const
CoinModel if valid.
Definition: CbcSolver.hpp:297
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:301
double * primalSolution_
Definition: CbcSolver.hpp:248
CbcUser * userFunction(const char *name) const
User function (NULL if no match)
virtual void exportSolution(CbcSolver *, int, const char *=NULL)
Export.
Definition: CbcSolver.hpp:283
CbcModel * model()
Return original Cbc model.
Definition: CbcSolver.hpp:144
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:340
CglCutGenerator ** cutGeneratorArray() const
Cut generator array.
Definition: CbcSolver.hpp:176
virtual void exportData(CbcSolver *)
Export Data (i.e. at very end)
Definition: CbcSolver.hpp:287
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.
A class to allow the use of unknown user functionality.
Definition: CbcSolver.hpp:260
Support the use of a call back class to decide whether to stop.
Definition: CbcSolver.hpp:351
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:290
CbcModel * babModel()
Return updated Cbc model.
Definition: CbcSolver.hpp:148
void fillParameters()
Fill with standard parameters.
~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.
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 &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:272
virtual ~CbcUser()
Destructor.
virtual int callBack(CbcModel *, int)
Import.
Definition: CbcSolver.hpp:369
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:305
CoinModel * coinModel_
CoinModel.
Definition: CbcSolver.hpp:337
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)
Structure to hold useful arrays.
Definition: CbcSolver.hpp:240
CbcSolver & operator=(const CbcSolver &rhs)
Assignment operator.
void setUserCallBack(CbcStopNow *function)
Set user call back.
CbcSolver()
Default Constructor.