source: trunk/Cbc/src/CbcSolver.hpp @ 779

Last change on this file since 779 was 779, checked in by forrest, 12 years ago

on way to CbcSolver? class

File size: 5.7 KB
Line 
1// Copyright (C) 2007, International Business Machines
2// Corporation and others.  All Rights Reserved.
3#ifndef CbcSolver_H
4#define CbcSolver_H
5#include <string>
6#include <vector>
7#include "CoinFinite.hpp"
8#include "CoinMessageHandler.hpp"
9#include "OsiClpSolverInterface.hpp"
10#include "CbcModel.hpp"
11#include "CbcOrClpParam.hpp"
12class CbcUser;
13class CbcStopNow;
14
15//#############################################################################
16
17/** This allows the use of the standalone solver in a flexible manner
18    It has an original OsiClpSolverInterface and CbcModel which
19    it can use repeatedly e.g. get a heuristic solution and then start again
20
21    So I will need a primitive scripting language which can then call solve
22    and manipulate solution value and solution arrays.
23   
24*/
25
26class CbcSolver  {
27 
28public:
29  ///@name Solve method
30  //@{
31  /** This takes a list of commands, does "stuff" and returns
32      returnMode -
33      0 model and solver untouched - babModel updated
34      1 model updated - just with solution basis etc
35      2 model updated i.e. as babModel (babModel NULL)
36  */
37  int solve(int argc, const char * argv[], int returnMode); 
38  //@}
39  ///@name Constructors and destructors etc
40  //@{
41  /// Default Constructor
42  CbcSolver(); 
43 
44  /// Constructor from solver
45  CbcSolver(const OsiClpSolverInterface &);
46 
47  /// Constructor from model
48  CbcSolver(const CbcModel &);
49 
50  /** Copy constructor .
51   */ 
52  CbcSolver(const CbcSolver & rhs);
53 
54  /// Assignment operator
55  CbcSolver & operator=(const CbcSolver& rhs);
56 
57  /// Destructor
58  ~CbcSolver ();
59  /// Fill with standard parameters
60  void fillParameters();
61  /// Set default values in solvers from parameters
62  void fillValuesInSolver();
63  //@}
64  ///@name miscellaneous methods to line up with old
65  //@{
66  // analyze model
67  int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
68                bool changeInt,  CoinMessageHandler * generalMessageHandler);
69  /** 1 - add heuristics to model
70      2 - do heuristics (and set cutoff and best solution)
71      3 - for miplib test so skip some
72      (out model later)
73  */
74  int doHeuristics(CbcModel * model, int type);
75  /** Updates model_ from babModel_ according to returnMode
76      returnMode -
77      0 model and solver untouched - babModel updated
78      1 model updated - just with solution basis etc
79      2 model updated i.e. as babModel (babModel NULL)
80  */
81  void updateModel(ClpSimplex * model2, int returnMode);
82  //@}
83  ///@name useful stuff
84  //@{
85  /// Get int value
86  int intValue(CbcOrClpParameterType type) const;
87  /// Set int value
88  void setIntValue(CbcOrClpParameterType type,int value);
89  /// Get double value
90  double doubleValue(CbcOrClpParameterType type) const;
91  /// Set double value
92  void setDoubleValue(CbcOrClpParameterType type,double value);
93  /// User function (NULL if no match)
94  CbcUser * userFunction(const char * name) const;
95  inline CbcModel * model() 
96  { return &model_;}
97  //@}
98private:
99  ///@name Private member data
100  //@{
101 
102  /// Reference model
103  CbcModel model_;
104 
105  /// Updated model
106  CbcModel * babModel_;
107 
108  /// User functions
109  CbcUser ** userFunction_;
110  /// Number of user functions
111  int numberUserFunctions_;
112  /// Stop now stuff
113  CbcStopNow * callBack_;
114  /// Cpu time at instantiation
115  double startTime_;
116  /// Parameters and values
117  CbcOrClpParam * parameters_;
118  /// Number of parameters
119  int numberParameters_ ;
120  /// Whether to do miplib test
121  bool doMiplib_;
122  /// Whether to print to std::cout
123  bool noPrinting_;
124 
125  //@}
126};
127//#############################################################################
128
129/** This allows the use of an unknown user stuff including modeling languages
130 */
131
132class CbcUser  {
133 
134public:
135  ///@name import/export methods
136  //@{
137  /// Import - 0 if good
138  virtual int importData(std::string fileName) {return 0;}
139  /// Export
140  virtual void exportSolution() {}
141  //@}
142  ///@name usage methods
143  //@{
144  /// CoinModel if valid
145  inline CoinModel * coinModel() const
146  { return coinModel_;}
147  /// Other info - needs expanding
148  virtual void * stuff() {return NULL;}
149  /// Name
150  inline std::string name() const
151  { return userName_;}
152  /// Solve (whatever that means)
153  void solve(CbcSolver * model, const char * options) {}
154  //@}
155  ///@name Constructors and destructors etc
156  //@{
157  /// Default Constructor
158  CbcUser(); 
159 
160  /** Copy constructor .
161   */ 
162  CbcUser(const CbcUser & rhs);
163 
164  /// Assignment operator
165  CbcUser & operator=(const CbcUser& rhs);
166
167  /// Clone
168  CbcUser * clone() const;
169 
170  /// Destructor
171  virtual ~CbcUser ();
172  //@}
173 
174protected:
175  ///@name Private member data
176  //@{
177 
178  /// CoinModel
179  CoinModel * coinModel_;
180 
181  /// Name of user function
182  std::string userName_;
183
184 //@}
185};
186//#############################################################################
187
188/** This allows the use of a call back class to decide whether to stop
189 */
190
191class CbcStopNow  {
192 
193public:
194  ///@name Decision methods
195  //@{
196  /// Import - 0 if good
197  /** Meaning of whereFrom:
198     1 after initial solve by dualsimplex etc
199     2 after preprocessing
200     3 just before branchAndBound (so user can override)
201     4 just after branchAndBound (before postprocessing)
202     5 after postprocessing
203     6 after a user called heuristic phase
204     nonzero return code to stop
205  */
206  virtual int callBack(CbcModel * currentSolver, int whereFrom) {return 0;}
207  //@}
208  ///@name Constructors and destructors etc
209  //@{
210  /// Default Constructor
211  CbcStopNow(); 
212 
213  /** Copy constructor .
214   */ 
215  CbcStopNow(const CbcStopNow & rhs);
216 
217  /// Assignment operator
218  CbcStopNow & operator=(const CbcStopNow& rhs);
219
220  /// Clone
221  CbcStopNow * clone() const;
222 
223  /// Destructor
224  virtual ~CbcStopNow ();
225  //@}
226 
227private:
228  ///@name Private member data
229  //@{
230 //@}
231};
232#endif
Note: See TracBrowser for help on using the repository browser.