source: branches/sandbox/Cbc/src/CbcSolver_stro.hpp @ 1286

Last change on this file since 1286 was 1286, checked in by EdwinStraver, 10 years ago

Changed formatting using AStyle -A4 -p

File size: 9.9 KB
Line 
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#ifndef CbcSolver_H
5#define CbcSolver_H
6#include <string>
7#include <vector>
8#include "CoinFinite.hpp"
9#include "CoinMessageHandler.hpp"
10#include "OsiClpSolverInterface.hpp"
11#if CBC_OTHER_SOLVER==1
12#include "OsiCpxSolverInterface.hpp"
13//typedef OsiCpxSolverInterface OsiClpSolverInterface;
14#endif
15#include "CbcModel.hpp"
16#include "CbcOrClpParam.hpp"
17class CbcUser;
18class CbcStopNow;
19class CglCutGenerator;
20
21//#############################################################################
22
23/** This allows the use of the standalone solver in a flexible manner
24    It has an original OsiClpSolverInterface and CbcModel which
25    it can use repeatedly e.g. get a heuristic solution and then start again
26
27    So I will need a primitive scripting language which can then call solve
28    and manipulate solution value and solution arrays.
29
30*/
31
32class CbcSolver  {
33
34public:
35    ///@name Solve method
36    //@{
37    /** This takes a list of commands, does "stuff" and returns
38        returnMode -
39        0 model and solver untouched - babModel updated
40        1 model updated - just with solution basis etc
41        2 model updated i.e. as babModel (babModel NULL) (only use without preprocessing)
42    */
43    int solve(int argc, const char * argv[], int returnMode);
44    /** This takes a list of commands, does "stuff" and returns
45        returnMode -
46        0 model and solver untouched - babModel updated
47        1 model updated - just with solution basis etc
48        2 model updated i.e. as babModel (babModel NULL) (only use without preprocessing)
49    */
50    int solve(const char * input, int returnMode);
51    //@}
52    ///@name Constructors and destructors etc
53    //@{
54    /// Default Constructor
55    CbcSolver();
56
57    /// Constructor from solver
58    CbcSolver(const OsiClpSolverInterface &);
59
60    /// Constructor from model
61    CbcSolver(const CbcModel &);
62
63    /** Copy constructor .
64     */
65    CbcSolver(const CbcSolver & rhs);
66
67    /// Assignment operator
68    CbcSolver & operator=(const CbcSolver& rhs);
69
70    /// Destructor
71    ~CbcSolver ();
72    /// Fill with standard parameters
73    void fillParameters();
74    /// Set default values in solvers from parameters
75    void fillValuesInSolver();
76    /// Add user function
77    void addUserFunction(CbcUser * function);
78    /// Set user call back
79    void setUserCallBack(CbcStopNow * function);
80    /// Add cut generator
81    void addCutGenerator(CglCutGenerator * generator);
82    //@}
83    ///@name miscellaneous methods to line up with old
84    //@{
85    // analyze model
86    int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
87                  bool changeInt,  CoinMessageHandler * generalMessageHandler);
88    /** 1 - add heuristics to model
89        2 - do heuristics (and set cutoff and best solution)
90        3 - for miplib test so skip some
91        (out model later)
92    */
93    int doHeuristics(CbcModel * model, int type);
94    /** Updates model_ from babModel_ according to returnMode
95        returnMode -
96        0 model and solver untouched - babModel updated
97        1 model updated - just with solution basis etc
98        2 model updated i.e. as babModel (babModel NULL) (only use without preprocessing)
99    */
100    void updateModel(ClpSimplex * model2, int returnMode);
101    //@}
102    ///@name useful stuff
103    //@{
104    /// Get int value
105    int intValue(CbcOrClpParameterType type) const;
106    /// Set int value
107    void setIntValue(CbcOrClpParameterType type, int value);
108    /// Get double value
109    double doubleValue(CbcOrClpParameterType type) const;
110    /// Set double value
111    void setDoubleValue(CbcOrClpParameterType type, double value);
112    /// User function (NULL if no match)
113    CbcUser * userFunction(const char * name) const;
114    /// Return original Cbc model
115    inline CbcModel * model() {
116        return &model_;
117    }
118    /// Return updated Cbc model
119    inline CbcModel * babModel() {
120        return babModel_;
121    }
122    /// Number of userFunctions
123    inline int numberUserFunctions() const {
124        return numberUserFunctions_;
125    }
126    /// User function array
127    inline CbcUser ** userFunctionArray() const {
128        return userFunction_;
129    }
130    /// Copy of model on initial load (will contain output solutions)
131    inline OsiClpSolverInterface * originalSolver() const {
132        return originalSolver_;
133    }
134    /// Copy of model on initial load
135    inline CoinModel * originalCoinModel() const {
136        return originalCoinModel_;
137    }
138    /// Copy of model on initial load (will contain output solutions)
139    void setOriginalSolver(OsiClpSolverInterface * originalSolver);
140    /// Copy of model on initial load
141    void setOriginalCoinModel(CoinModel * originalCoinModel);
142    /// Number of cutgenerators
143    inline int numberCutGenerators() const {
144        return numberCutGenerators_;
145    }
146    /// Cut generator array
147    inline CglCutGenerator ** cutGeneratorArray() const {
148        return cutGenerator_;
149    }
150    /// Start time
151    inline double startTime() const {
152        return startTime_;
153    }
154    /// Whether to print to std::cout
155    inline void setPrinting(bool onOff) {
156        noPrinting_ = !onOff;
157    }
158    /// Where to start reading commands
159    inline void setReadMode(int value) {
160        readMode_ = value;
161    }
162    //@}
163private:
164    ///@name Private member data
165    //@{
166
167    /// Reference model
168    CbcModel model_;
169
170    /// Updated model
171    CbcModel * babModel_;
172
173    /// User functions
174    CbcUser ** userFunction_;
175    /** Status of user functions
176        0 - not used
177        1 - needs cbc_load
178        2 - available - data in coinModel
179        3 - data loaded - can do cbc_save
180    */
181    int * statusUserFunction_;
182    /// Copy of model on initial load (will contain output solutions)
183    OsiClpSolverInterface * originalSolver_;
184    /// Copy of model on initial load
185    CoinModel * originalCoinModel_;
186    /// Cut generators
187    CglCutGenerator ** cutGenerator_;
188    /// Number of user functions
189    int numberUserFunctions_;
190    /// Number of cut generators
191    int numberCutGenerators_;
192    /// Stop now stuff
193    CbcStopNow * callBack_;
194    /// Cpu time at instantiation
195    double startTime_;
196    /// Parameters and values
197    CbcOrClpParam * parameters_;
198    /// Number of parameters
199    int numberParameters_ ;
200    /// Whether to do miplib test
201    bool doMiplib_;
202    /// Whether to print to std::cout
203    bool noPrinting_;
204    /// Where to start reading commands
205    int readMode_;
206    //@}
207};
208//#############################################################################
209/// Structure to hold useful arrays
210typedef struct {
211    // Priorities
212    int * priorities_;
213    // SOS priorities
214    int * sosPriority_;
215    // Direction to branch first
216    int * branchDirection_;
217    // Input solution
218    double * primalSolution_;
219    // Down pseudo costs
220    double * pseudoDown_;
221    // Up pseudo costs
222    double * pseudoUp_;
223} CbcSolverUsefulData;
224/** This allows the use of an unknown user stuff including modeling languages
225 */
226
227class CbcUser  {
228
229public:
230    ///@name import/export methods
231    //@{
232    /** Import - gets full command arguments
233        Returns -1 - no action
234                 0 - data read in without error
235             1 - errors
236    */
237    virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
238        return -1;
239    }
240    /// Export 1 OsiClpSolver, 2 CbcModel - add 10 if infeasible from odd situation
241    virtual void exportSolution(CbcSolver * /*model*/,
242                                int /*mode*/, const char * /*message*/ = NULL) {}
243    /// Export Data (i.e. at very end)
244    virtual void exportData(CbcSolver * /*model*/) {}
245    /// Get useful stuff
246    virtual void fillInformation(CbcSolver * /*model*/,
247                                 CbcSolverUsefulData & /*info*/) {}
248
249    //@}
250    ///@name usage methods
251    //@{
252    /// CoinModel if valid
253    inline CoinModel * coinModel() const {
254        return coinModel_;
255    }
256    /// Other info - needs expanding
257    virtual void * stuff() {
258        return NULL;
259    }
260    /// Name
261    inline std::string name() const {
262        return userName_;
263    }
264    /// Solve (whatever that means)
265    virtual void solve(CbcSolver * model, const char * options) = 0;
266    /// Returns true if function knows about option
267    virtual bool canDo(const char * options) = 0;
268    //@}
269    ///@name Constructors and destructors etc
270    //@{
271    /// Default Constructor
272    CbcUser();
273
274    /** Copy constructor .
275     */
276    CbcUser(const CbcUser & rhs);
277
278    /// Assignment operator
279    CbcUser & operator=(const CbcUser& rhs);
280
281    /// Clone
282    virtual CbcUser * clone() const = 0;
283
284    /// Destructor
285    virtual ~CbcUser ();
286    //@}
287
288protected:
289    ///@name Private member data
290    //@{
291
292    /// CoinModel
293    CoinModel * coinModel_;
294
295    /// Name of user function
296    std::string userName_;
297
298//@}
299};
300//#############################################################################
301
302/** This allows the use of a call back class to decide whether to stop
303 */
304
305class CbcStopNow  {
306
307public:
308    ///@name Decision methods
309    //@{
310    /// Import - 0 if good
311    /** Meaning of whereFrom:
312       1 after initial solve by dualsimplex etc
313       2 after preprocessing
314       3 just before branchAndBound (so user can override)
315       4 just after branchAndBound (before postprocessing)
316       5 after postprocessing
317       6 after a user called heuristic phase
318       nonzero return code to stop
319    */
320    virtual int callBack(CbcModel * /*currentSolver*/,
321                         int /*whereFrom*/) {
322        return 0;
323    }
324    //@}
325    ///@name Constructors and destructors etc
326    //@{
327    /// Default Constructor
328    CbcStopNow();
329
330    /** Copy constructor .
331     */
332    CbcStopNow(const CbcStopNow & rhs);
333
334    /// Assignment operator
335    CbcStopNow & operator=(const CbcStopNow& rhs);
336
337    /// Clone
338    virtual CbcStopNow * clone() const;
339
340    /// Destructor
341    virtual ~CbcStopNow ();
342    //@}
343
344private:
345    ///@name Private member data
346    //@{
347//@}
348};
349#endif
Note: See TracBrowser for help on using the repository browser.