1
// Copyright (C) 2007, International Business Machines
2
// Corporation and others. All Rights Reserved.
7
#include "CoinFinite.hpp"
8
#include "CoinMessageHandler.hpp"
9
#include "OsiClpSolverInterface.hpp"
10
#if CBC_OTHER_SOLVER==1
11
#include "OsiCpxSolverInterface.hpp"
12
//typedef OsiCpxSolverInterface OsiClpSolverInterface;
14
#include "CbcModel.hpp"
15
#include "CbcOrClpParam.hpp"
18
class CglCutGenerator;
20
//#############################################################################
22
/** This allows the use of the standalone solver in a flexible manner
23
It has an original OsiClpSolverInterface and CbcModel which
24
it can use repeatedly e.g. get a heuristic solution and then start again
26
So I will need a primitive scripting language which can then call solve
27
and manipulate solution value and solution arrays.
36
/** This takes a list of commands, does "stuff" and returns
38
0 model and solver untouched - babModel updated
39
1 model updated - just with solution basis etc
40
2 model updated i.e. as babModel (babModel NULL) (only use without preprocessing)
42
int solve(int argc, const char * argv[], int returnMode);
43
/** This takes a list of commands, does "stuff" and returns
45
0 model and solver untouched - babModel updated
46
1 model updated - just with solution basis etc
47
2 model updated i.e. as babModel (babModel NULL) (only use without preprocessing)
49
int solve(const char * input, int returnMode);
51
///@name Constructors and destructors etc
53
/// Default Constructor
56
/// Constructor from solver
57
CbcSolver(const OsiClpSolverInterface &);
59
/// Constructor from model
60
CbcSolver(const CbcModel &);
62
/** Copy constructor .
64
CbcSolver(const CbcSolver & rhs);
66
/// Assignment operator
67
CbcSolver & operator=(const CbcSolver& rhs);
71
/// Fill with standard parameters
72
void fillParameters();
73
/// Set default values in solvers from parameters
74
void fillValuesInSolver();
76
void addUserFunction(CbcUser * function);
77
/// Set user call back
78
void setUserCallBack(CbcStopNow * function);
80
void addCutGenerator(CglCutGenerator * generator);
82
///@name miscellaneous methods to line up with old
85
int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
86
bool changeInt, CoinMessageHandler * generalMessageHandler);
87
/** 1 - add heuristics to model
88
2 - do heuristics (and set cutoff and best solution)
89
3 - for miplib test so skip some
92
int doHeuristics(CbcModel * model, int type);
93
/** Updates model_ from babModel_ according to returnMode
95
0 model and solver untouched - babModel updated
96
1 model updated - just with solution basis etc
97
2 model updated i.e. as babModel (babModel NULL) (only use without preprocessing)
99
void updateModel(ClpSimplex * model2, int returnMode);
101
///@name useful stuff
104
int intValue(CbcOrClpParameterType type) const;
106
void setIntValue(CbcOrClpParameterType type,int value);
108
double doubleValue(CbcOrClpParameterType type) const;
110
void setDoubleValue(CbcOrClpParameterType type,double value);
111
/// User function (NULL if no match)
112
CbcUser * userFunction(const char * name) const;
113
/// Return original Cbc model
114
inline CbcModel * model()
116
/// Return updated Cbc model
117
inline CbcModel * babModel()
119
/// Number of userFunctions
120
inline int numberUserFunctions() const
121
{ return numberUserFunctions_;}
122
/// User function array
123
inline CbcUser ** userFunctionArray() const
124
{ return userFunction_;}
125
/// Copy of model on initial load (will contain output solutions)
126
inline OsiClpSolverInterface * originalSolver() const
127
{ return originalSolver_;}
128
/// Copy of model on initial load
129
inline CoinModel * originalCoinModel() const
130
{ return originalCoinModel_;}
131
/// Copy of model on initial load (will contain output solutions)
132
void setOriginalSolver(OsiClpSolverInterface * originalSolver);
133
/// Copy of model on initial load
134
void setOriginalCoinModel(CoinModel * originalCoinModel);
135
/// Number of cutgenerators
136
inline int numberCutGenerators() const
137
{ return numberCutGenerators_;}
138
/// Cut generator array
139
inline CglCutGenerator ** cutGeneratorArray() const
140
{ return cutGenerator_;}
142
inline double startTime() const
143
{ return startTime_;}
144
/// Whether to print to std::cout
145
inline void setPrinting(bool onOff)
146
{ noPrinting_= !onOff;}
147
/// Where to start reading commands
148
inline void setReadMode(int value)
149
{ readMode_ = value;}
152
///@name Private member data
159
CbcModel * babModel_;
162
CbcUser ** userFunction_;
163
/** Status of user functions
166
2 - available - data in coinModel
167
3 - data loaded - can do cbc_save
169
int * statusUserFunction_;
170
/// Copy of model on initial load (will contain output solutions)
171
OsiClpSolverInterface * originalSolver_;
172
/// Copy of model on initial load
173
CoinModel * originalCoinModel_;
175
CglCutGenerator ** cutGenerator_;
176
/// Number of user functions
177
int numberUserFunctions_;
178
/// Number of cut generators
179
int numberCutGenerators_;
181
CbcStopNow * callBack_;
182
/// Cpu time at instantiation
184
/// Parameters and values
185
CbcOrClpParam * parameters_;
186
/// Number of parameters
187
int numberParameters_ ;
188
/// Whether to do miplib test
190
/// Whether to print to std::cout
192
/// Where to start reading commands
196
//#############################################################################
197
/// Structure to hold useful arrays
203
// Direction to branch first
204
int * branchDirection_;
206
double * primalSolution_;
208
double * pseudoDown_;
211
} CbcSolverUsefulData;
212
/** This allows the use of an unknown user stuff including modeling languages
218
///@name import/export methods
220
/** Import - gets full command arguments
221
Returns -1 - no action
222
0 - data read in without error
225
virtual int importData(CbcSolver * model, int & argc, char * argv[]) {return -1;}
226
/// Export 1 OsiClpSolver, 2 CbcModel - add 10 if infeasible from odd situation
227
virtual void exportSolution(CbcSolver * model, int mode,const char * message=NULL) {}
228
/// Export Data (i.e. at very end)
229
virtual void exportData(CbcSolver * model) {}
231
virtual void fillInformation(CbcSolver * model,
232
CbcSolverUsefulData & info) {}
235
///@name usage methods
237
/// CoinModel if valid
238
inline CoinModel * coinModel() const
239
{ return coinModel_;}
240
/// Other info - needs expanding
241
virtual void * stuff() {return NULL;}
243
inline std::string name() const
245
/// Solve (whatever that means)
246
virtual void solve(CbcSolver * model, const char * options) = 0;
247
/// Returns true if function knows about option
248
virtual bool canDo(const char * options) = 0;
250
///@name Constructors and destructors etc
252
/// Default Constructor
255
/** Copy constructor .
257
CbcUser(const CbcUser & rhs);
259
/// Assignment operator
260
CbcUser & operator=(const CbcUser& rhs);
263
virtual CbcUser * clone() const = 0;
270
///@name Private member data
274
CoinModel * coinModel_;
276
/// Name of user function
277
std::string userName_;
281
//#############################################################################
283
/** This allows the use of a call back class to decide whether to stop
289
///@name Decision methods
291
/// Import - 0 if good
292
/** Meaning of whereFrom:
293
1 after initial solve by dualsimplex etc
294
2 after preprocessing
295
3 just before branchAndBound (so user can override)
296
4 just after branchAndBound (before postprocessing)
297
5 after postprocessing
298
6 after a user called heuristic phase
299
nonzero return code to stop
301
virtual int callBack(CbcModel * currentSolver, int whereFrom) {return 0;}
303
///@name Constructors and destructors etc
305
/// Default Constructor
308
/** Copy constructor .
310
CbcStopNow(const CbcStopNow & rhs);
312
/// Assignment operator
313
CbcStopNow & operator=(const CbcStopNow& rhs);
316
virtual CbcStopNow * clone() const;
319
virtual ~CbcStopNow ();
323
///@name Private member data