00001
00002
00003
00004
00005
00006
00018 #ifndef CbcSolver_H
00019 #define CbcSolver_H
00020
00021 #include <string>
00022 #include <vector>
00023 #include "CoinMessageHandler.hpp"
00024 #include "OsiClpSolverInterface.hpp"
00025
00026 #if CBC_OTHER_SOLVER==1
00027 #include "OsiCpxSolverInterface.hpp"
00028 #endif
00029
00030 #include "CbcModel.hpp"
00031 #include "CbcOrClpParam.hpp"
00032
00033 class CbcUser;
00034 class CbcStopNow;
00035 class CglCutGenerator;
00036
00037
00038
00056 class CbcSolver {
00057
00058 public:
00060
00061
00067 int solve(int argc, const char * argv[], int returnMode);
00074 int solve(const char * input, int returnMode);
00076
00077
00078
00079 CbcSolver();
00080
00082 CbcSolver(const OsiClpSolverInterface &);
00083
00085 CbcSolver(const CbcModel &);
00086
00089 CbcSolver(const CbcSolver & rhs);
00090
00092 CbcSolver & operator=(const CbcSolver& rhs);
00093
00095 ~CbcSolver ();
00097 void fillParameters();
00104 void fillValuesInSolver();
00106 void addUserFunction(CbcUser * function);
00108 void setUserCallBack(CbcStopNow * function);
00110 void addCutGenerator(CglCutGenerator * generator);
00112
00113
00114
00115 int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
00116 bool changeInt, CoinMessageHandler * generalMessageHandler);
00122
00129 void updateModel(ClpSimplex * model2, int returnMode);
00131
00132
00133
00134 int intValue(CbcOrClpParameterType type) const;
00136 void setIntValue(CbcOrClpParameterType type, int value);
00138 double doubleValue(CbcOrClpParameterType type) const;
00140 void setDoubleValue(CbcOrClpParameterType type, double value);
00142 CbcUser * userFunction(const char * name) const;
00144 inline CbcModel * model() {
00145 return &model_;
00146 }
00148 inline CbcModel * babModel() {
00149 return babModel_;
00150 }
00152 inline int numberUserFunctions() const {
00153 return numberUserFunctions_;
00154 }
00156 inline CbcUser ** userFunctionArray() const {
00157 return userFunction_;
00158 }
00160 inline OsiClpSolverInterface * originalSolver() const {
00161 return originalSolver_;
00162 }
00164 inline CoinModel * originalCoinModel() const {
00165 return originalCoinModel_;
00166 }
00168 void setOriginalSolver(OsiClpSolverInterface * originalSolver);
00170 void setOriginalCoinModel(CoinModel * originalCoinModel);
00172 inline int numberCutGenerators() const {
00173 return numberCutGenerators_;
00174 }
00176 inline CglCutGenerator ** cutGeneratorArray() const {
00177 return cutGenerator_;
00178 }
00180 inline double startTime() const {
00181 return startTime_;
00182 }
00184 inline void setPrinting(bool onOff) {
00185 noPrinting_ = !onOff;
00186 }
00188 inline void setReadMode(int value) {
00189 readMode_ = value;
00190 }
00192 private:
00194
00195
00197 CbcModel model_;
00198
00200 CbcModel * babModel_;
00201
00203 CbcUser ** userFunction_;
00210 int * statusUserFunction_;
00212 OsiClpSolverInterface * originalSolver_;
00214 CoinModel * originalCoinModel_;
00216 CglCutGenerator ** cutGenerator_;
00218 int numberUserFunctions_;
00220 int numberCutGenerators_;
00222 CbcStopNow * callBack_;
00224 double startTime_;
00226 CbcOrClpParam * parameters_;
00228 int numberParameters_ ;
00230 bool doMiplib_;
00232 bool noPrinting_;
00234 int readMode_;
00236 };
00237
00238
00240 typedef struct {
00241
00242 int * priorities_;
00243
00244 int * sosPriority_;
00245
00246 int * branchDirection_;
00247
00248 double * primalSolution_;
00249
00250 double * pseudoDown_;
00251
00252 double * pseudoUp_;
00253 } CbcSolverUsefulData;
00254
00255
00260 class CbcUser {
00261
00262 public:
00264
00265
00272 virtual int importData(CbcSolver * , int & , char ** ) {
00273 return -1;
00274 }
00275
00283 virtual void exportSolution(CbcSolver * ,
00284 int , const char * = NULL) {}
00285
00287 virtual void exportData(CbcSolver * ) {}
00288
00290 virtual void fillInformation(CbcSolver * ,
00291 CbcSolverUsefulData & ) {}
00293
00295
00296
00297 inline CoinModel *coinModel() const {
00298 return coinModel_;
00299 }
00301 virtual void * stuff() {
00302 return NULL;
00303 }
00305 inline std::string name() const {
00306 return userName_;
00307 }
00309 virtual void solve(CbcSolver * model, const char * options) = 0;
00311 virtual bool canDo(const char * options) = 0;
00313
00315
00316
00317 CbcUser();
00318
00320 CbcUser(const CbcUser & rhs);
00321
00323 CbcUser & operator=(const CbcUser& rhs);
00324
00326 virtual CbcUser * clone() const = 0;
00327
00329 virtual ~CbcUser ();
00331
00332 protected:
00334
00335
00337 CoinModel * coinModel_;
00338
00340 std::string userName_;
00341
00343 };
00344
00345
00351 class CbcStopNow {
00352
00353 public:
00355
00356
00369 virtual int callBack(CbcModel * , int ) {
00370 return 0;
00371 }
00373
00375
00376
00377 CbcStopNow();
00378
00381 CbcStopNow(const CbcStopNow & rhs);
00382
00384 CbcStopNow & operator=(const CbcStopNow& rhs);
00385
00387 virtual CbcStopNow * clone() const;
00388
00390 virtual ~CbcStopNow ();
00392
00393 private:
00395
00396
00397 };
00398 #endif
00399