00001
00002
00003
00004 #ifndef CbcSolver_H
00005 #define CbcSolver_H
00006 #include <string>
00007 #include <vector>
00008 #include "CoinFinite.hpp"
00009 #include "CoinMessageHandler.hpp"
00010 #include "OsiClpSolverInterface.hpp"
00011 #if CBC_OTHER_SOLVER==1
00012 #include "OsiCpxSolverInterface.hpp"
00013
00014 #endif
00015 #include "CbcModel.hpp"
00016 #include "CbcOrClpParam.hpp"
00017 class CbcUser;
00018 class CbcStopNow;
00019 class CglCutGenerator;
00020
00021
00022
00032 class CbcSolver {
00033
00034 public:
00036
00037
00043 int solve(int argc, const char * argv[], int returnMode);
00050 int solve(const char * input, int returnMode);
00052
00053
00054
00055 CbcSolver();
00056
00058 CbcSolver(const OsiClpSolverInterface &);
00059
00061 CbcSolver(const CbcModel &);
00062
00065 CbcSolver(const CbcSolver & rhs);
00066
00068 CbcSolver & operator=(const CbcSolver& rhs);
00069
00071 ~CbcSolver ();
00073 void fillParameters();
00075 void fillValuesInSolver();
00077 void addUserFunction(CbcUser * function);
00079 void setUserCallBack(CbcStopNow * function);
00081 void addCutGenerator(CglCutGenerator * generator);
00083
00084
00085
00086 int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
00087 bool changeInt, CoinMessageHandler * generalMessageHandler);
00093 int doHeuristics(CbcModel * model, int type);
00100 void updateModel(ClpSimplex * model2, int returnMode);
00102
00103
00104
00105 int intValue(CbcOrClpParameterType type) const;
00107 void setIntValue(CbcOrClpParameterType type,int value);
00109 double doubleValue(CbcOrClpParameterType type) const;
00111 void setDoubleValue(CbcOrClpParameterType type,double value);
00113 CbcUser * userFunction(const char * name) const;
00115 inline CbcModel * model()
00116 { return &model_;}
00118 inline CbcModel * babModel()
00119 { return babModel_;}
00121 inline int numberUserFunctions() const
00122 { return numberUserFunctions_;}
00124 inline CbcUser ** userFunctionArray() const
00125 { return userFunction_;}
00127 inline OsiClpSolverInterface * originalSolver() const
00128 { return originalSolver_;}
00130 inline CoinModel * originalCoinModel() const
00131 { return originalCoinModel_;}
00133 void setOriginalSolver(OsiClpSolverInterface * originalSolver);
00135 void setOriginalCoinModel(CoinModel * originalCoinModel);
00137 inline int numberCutGenerators() const
00138 { return numberCutGenerators_;}
00140 inline CglCutGenerator ** cutGeneratorArray() const
00141 { return cutGenerator_;}
00143 inline double startTime() const
00144 { return startTime_;}
00146 inline void setPrinting(bool onOff)
00147 { noPrinting_= !onOff;}
00149 inline void setReadMode(int value)
00150 { readMode_ = value;}
00152 private:
00154
00155
00157 CbcModel model_;
00158
00160 CbcModel * babModel_;
00161
00163 CbcUser ** userFunction_;
00170 int * statusUserFunction_;
00172 OsiClpSolverInterface * originalSolver_;
00174 CoinModel * originalCoinModel_;
00176 CglCutGenerator ** cutGenerator_;
00178 int numberUserFunctions_;
00180 int numberCutGenerators_;
00182 CbcStopNow * callBack_;
00184 double startTime_;
00186 CbcOrClpParam * parameters_;
00188 int numberParameters_ ;
00190 bool doMiplib_;
00192 bool noPrinting_;
00194 int readMode_;
00196 };
00197
00199 typedef struct {
00200
00201 int * priorities_;
00202
00203 int * sosPriority_;
00204
00205 int * branchDirection_;
00206
00207 double * primalSolution_;
00208
00209 double * pseudoDown_;
00210
00211 double * pseudoUp_;
00212 } CbcSolverUsefulData;
00216 class CbcUser {
00217
00218 public:
00220
00221
00226 virtual int importData(CbcSolver * , int & , char ** ) {return -1;}
00228 virtual void exportSolution(CbcSolver * ,
00229 int ,const char * =NULL) {}
00231 virtual void exportData(CbcSolver * ) {}
00233 virtual void fillInformation(CbcSolver * ,
00234 CbcSolverUsefulData & ) {}
00235
00237
00238
00239
00240 inline CoinModel * coinModel() const
00241 { return coinModel_;}
00243 virtual void * stuff() {return NULL;}
00245 inline std::string name() const
00246 { return userName_;}
00248 virtual void solve(CbcSolver * model, const char * options) = 0;
00250 virtual bool canDo(const char * options) = 0;
00252
00253
00254
00255 CbcUser();
00256
00259 CbcUser(const CbcUser & rhs);
00260
00262 CbcUser & operator=(const CbcUser& rhs);
00263
00265 virtual CbcUser * clone() const = 0;
00266
00268 virtual ~CbcUser ();
00270
00271 protected:
00273
00274
00276 CoinModel * coinModel_;
00277
00279 std::string userName_;
00280
00282 };
00283
00284
00288 class CbcStopNow {
00289
00290 public:
00292
00293
00294
00303 virtual int callBack(CbcModel * ,
00304 int ) {return 0;}
00306
00307
00308
00309 CbcStopNow();
00310
00313 CbcStopNow(const CbcStopNow & rhs);
00314
00316 CbcStopNow & operator=(const CbcStopNow& rhs);
00317
00319 virtual CbcStopNow * clone() const;
00320
00322 virtual ~CbcStopNow ();
00324
00325 private:
00327
00328
00329 };
00330 #endif