Cbc  2.10.5
 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 2479 2019-02-07 19:50:37Z unxusr $ */
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"
24 
25 #if CBC_OTHER_SOLVER == 1
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 
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  {
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  }
164  {
165  return originalSolver_;
166  }
168  inline CoinModel *originalCoinModel() const
169  {
170  return originalCoinModel_;
171  }
177  inline int numberCutGenerators() const
178  {
179  return numberCutGenerators_;
180  }
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 
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 
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 
443  CbcStopNow &operator=(const CbcStopNow &rhs);
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 */
CoinModel * coinModel() const
CoinModel if valid.
Definition: CbcSolver.hpp:352
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:357
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:338
CbcModel * model()
Return original Cbc model.
Definition: CbcSolver.hpp:143
~CbcSolverUsefulData()
Destructor.
void setOriginalCoinModel(CoinModel *originalCoinModel)
Copy of model on initial load.
int numberUserFunctions_
Number of user functions.
Definition: CbcSolver.hpp:228
CbcUser()
Default Constructor.
double startTime() const
Start time.
Definition: CbcSolver.hpp:187
OsiClpSolverInterface * originalSolver_
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:222
CbcStopNow * callBack_
Stop now stuff.
Definition: CbcSolver.hpp:232
OsiClpSolverInterface * originalSolver() const
Copy of model on initial load (will contain output solutions)
Definition: CbcSolver.hpp:163
std::vector< CbcOrClpParam > parameters_
Parameters and values.
Definition: CbcSolver.hpp:236
int numberCutGenerators_
Number of cut generators.
Definition: CbcSolver.hpp:230
std::string userName_
Name of user function.
Definition: CbcSolver.hpp:398
This is a simple minded model which is stored in a format which makes it easier to construct and modi...
Definition: CoinModel.hpp:181
int readMode_
Where to start reading commands.
Definition: CbcSolver.hpp:242
Clp Solver Interface.
CglCutGenerator ** cutGeneratorArray() const
Cut generator array.
Definition: CbcSolver.hpp:182
virtual void exportData(CbcSolver *)
Export Data (i.e. at very end)
Definition: CbcSolver.hpp:342
void setReadMode(int value)
Where to start reading commands.
Definition: CbcSolver.hpp:197
CbcUser ** userFunction_
User functions.
Definition: CbcSolver.hpp:213
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:314
Support the use of a call back class to decide whether to stop.
Definition: CbcSolver.hpp:409
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:55
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:106
virtual ~CbcStopNow()
Destructor.
virtual CbcUser * clone() const =0
Clone.
virtual void fillInformation(CbcSolver *, CbcSolverUsefulData &)
Get useful stuff.
Definition: CbcSolver.hpp:345
CbcModel * babModel()
Return updated Cbc model.
Definition: CbcSolver.hpp:148
Cut Generator Base Class.
CbcModel * babModel_
Updated model.
Definition: CbcSolver.hpp:210
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.
std::vector< CbcOrClpParam > parameters_
Definition: CbcSolver.hpp:294
void setDoubleValue(CbcOrClpParameterType type, double value)
Set double value.
CoinModel * originalCoinModel() const
Copy of model on initial load.
Definition: CbcSolver.hpp:168
double * primalSolution_
Definition: CbcSolver.hpp:256
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
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:326
CglCutGenerator ** cutGenerator_
Cut generators.
Definition: CbcSolver.hpp:226
The CbcSolver class was taken out at a 9/12/09 meeting This is a feeble replacement.
Definition: CbcSolver.hpp:270
virtual ~CbcUser()
Destructor.
virtual int callBack(CbcModel *, int)
Import.
Definition: CbcSolver.hpp:427
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:234
CoinModel * originalCoinModel_
Copy of model on initial load.
Definition: CbcSolver.hpp:224
void addUserFunction(CbcUser *function)
Add user function.
CbcStopNow()
Default Constructor.
CbcUser ** userFunctionArray() const
User function array.
Definition: CbcSolver.hpp:158
int numberUserFunctions() const
Number of userFunctions.
Definition: CbcSolver.hpp:153
bool doMiplib_
Whether to do miplib test.
Definition: CbcSolver.hpp:238
CbcOrClpParameterType
Parameter codes.
int CbcMain1(int argc, const char *argv[], CbcModel &babSolver)
std::string name() const
Name.
Definition: CbcSolver.hpp:362
CoinModel * coinModel_
CoinModel.
Definition: CbcSolver.hpp:395
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:192
bool noPrinting_
Whether to print to std::cout.
Definition: CbcSolver.hpp:240
int numberCutGenerators() const
Number of cutgenerators.
Definition: CbcSolver.hpp:177
Simple Branch and bound class.
Definition: CbcModel.hpp:100
Structure to hold useful arrays.
Definition: CbcSolver.hpp:248
CbcModel model_
Reference model.
Definition: CbcSolver.hpp:207
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.
void setUserCallBack(CbcStopNow *function)
Set user call back.
CbcSolver()
Default Constructor.