/build/buildd/coinor-cbc-2.5.0/Cbc/src/CbcSolver.hpp
Go to the documentation of this file.
00001 /* $Id: CbcSolver.hpp 1212 2009-08-21 16:19:13Z forrest $ */
00002 // Copyright (C) 2007, International Business Machines
00003 // Corporation and others.  All Rights Reserved.
00004 
00016 #ifndef CbcSolver_H
00017 #define CbcSolver_H
00018 
00019 #include <string>
00020 #include <vector>
00021 #include "CoinFinite.hpp"
00022 #include "CoinMessageHandler.hpp"
00023 #include "OsiClpSolverInterface.hpp"
00024 
00025 #if CBC_OTHER_SOLVER==1
00026 #include "OsiCpxSolverInterface.hpp"
00027 #endif
00028 
00029 #include "CbcModel.hpp"
00030 #include "CbcOrClpParam.hpp"
00031 
00032 class CbcUser;
00033 class CbcStopNow;
00034 class CglCutGenerator;
00035 
00036 //#############################################################################
00037 
00055 class CbcSolver {
00056 
00057 public:
00059 
00060 
00066     int solve(int argc, const char * argv[], int returnMode);
00073     int solve(const char * input, int returnMode);
00075 
00076 
00077 
00078     CbcSolver();
00079 
00081     CbcSolver(const OsiClpSolverInterface &);
00082 
00084     CbcSolver(const CbcModel &);
00085 
00088     CbcSolver(const CbcSolver & rhs);
00089 
00091     CbcSolver & operator=(const CbcSolver& rhs);
00092 
00094     ~CbcSolver ();
00096     void fillParameters();
00103     void fillValuesInSolver();
00105     void addUserFunction(CbcUser * function);
00107     void setUserCallBack(CbcStopNow * function);
00109     void addCutGenerator(CglCutGenerator * generator);
00111 
00112 
00113     // analyze model
00114     int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
00115                   bool changeInt,  CoinMessageHandler * generalMessageHandler);
00121     //int doHeuristics(CbcModel * model, int type);
00128     void updateModel(ClpSimplex * model2, int returnMode);
00130 
00131 
00132 
00133     int intValue(CbcOrClpParameterType type) const;
00135     void setIntValue(CbcOrClpParameterType type, int value);
00137     double doubleValue(CbcOrClpParameterType type) const;
00139     void setDoubleValue(CbcOrClpParameterType type, double value);
00141     CbcUser * userFunction(const char * name) const;
00143     inline CbcModel * model() {
00144         return &model_;
00145     }
00147     inline CbcModel * babModel() {
00148         return babModel_;
00149     }
00151     inline int numberUserFunctions() const {
00152         return numberUserFunctions_;
00153     }
00155     inline CbcUser ** userFunctionArray() const {
00156         return userFunction_;
00157     }
00159     inline OsiClpSolverInterface * originalSolver() const {
00160         return originalSolver_;
00161     }
00163     inline CoinModel * originalCoinModel() const {
00164         return originalCoinModel_;
00165     }
00167     void setOriginalSolver(OsiClpSolverInterface * originalSolver);
00169     void setOriginalCoinModel(CoinModel * originalCoinModel);
00171     inline int numberCutGenerators() const {
00172         return numberCutGenerators_;
00173     }
00175     inline CglCutGenerator ** cutGeneratorArray() const {
00176         return cutGenerator_;
00177     }
00179     inline double startTime() const {
00180         return startTime_;
00181     }
00183     inline void setPrinting(bool onOff) {
00184         noPrinting_ = !onOff;
00185     }
00187     inline void setReadMode(int value) {
00188         readMode_ = value;
00189     }
00191 private:
00193 
00194 
00196     CbcModel model_;
00197 
00199     CbcModel * babModel_;
00200 
00202     CbcUser ** userFunction_;
00209     int * statusUserFunction_;
00211     OsiClpSolverInterface * originalSolver_;
00213     CoinModel * originalCoinModel_;
00215     CglCutGenerator ** cutGenerator_;
00217     int numberUserFunctions_;
00219     int numberCutGenerators_;
00221     CbcStopNow * callBack_;
00223     double startTime_;
00225     CbcOrClpParam * parameters_;
00227     int numberParameters_ ;
00229     bool doMiplib_;
00231     bool noPrinting_;
00233     int readMode_;
00235 };
00236 //#############################################################################
00237 
00239 typedef struct {
00240     // Priorities
00241     int * priorities_;
00242     // SOS priorities
00243     int * sosPriority_;
00244     // Direction to branch first
00245     int * branchDirection_;
00246     // Input solution
00247     double * primalSolution_;
00248     // Down pseudo costs
00249     double * pseudoDown_;
00250     // Up pseudo costs
00251     double * pseudoUp_;
00252 } CbcSolverUsefulData;
00253 
00254 
00259 class CbcUser {
00260 
00261 public:
00263 
00264 
00271     virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
00272         return -1;
00273     }
00274 
00282     virtual void exportSolution(CbcSolver * /*model*/,
00283                                 int /*mode*/, const char * /*message*/ = NULL) {}
00284 
00286     virtual void exportData(CbcSolver * /*model*/) {}
00287 
00289     virtual void fillInformation(CbcSolver * /*model*/,
00290                                  CbcSolverUsefulData & /*info*/) {}
00292 
00294 
00295 
00296     inline CoinModel *coinModel() const {
00297         return coinModel_;
00298     }
00300     virtual void * stuff() {
00301         return NULL;
00302     }
00304     inline std::string name() const {
00305         return userName_;
00306     }
00308     virtual void solve(CbcSolver * model, const char * options) = 0;
00310     virtual bool canDo(const char * options) = 0;
00312 
00314 
00315 
00316     CbcUser();
00317 
00319     CbcUser(const CbcUser & rhs);
00320 
00322     CbcUser & operator=(const CbcUser& rhs);
00323 
00325     virtual CbcUser * clone() const = 0;
00326 
00328     virtual ~CbcUser ();
00330 
00331 protected:
00333 
00334 
00336     CoinModel * coinModel_;
00337 
00339     std::string userName_;
00340 
00342 };
00343 //#############################################################################
00344 
00350 class CbcStopNow {
00351 
00352 public:
00354 
00355 
00368     virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/) {
00369         return 0;
00370     }
00372 
00374 
00375 
00376     CbcStopNow();
00377 
00380     CbcStopNow(const CbcStopNow & rhs);
00381 
00383     CbcStopNow & operator=(const CbcStopNow& rhs);
00384 
00386     virtual CbcStopNow * clone() const;
00387 
00389     virtual ~CbcStopNow ();
00391 
00392 private:
00394 
00395 
00396 };
00397 #endif
00398