CbcSolver.hpp

Go to the documentation of this file.
00001 /* $Id: CbcSolver.hpp 2004 2014-01-14 14:50:43Z forrest $ */
00002 // Copyright (C) 2007, International Business Machines
00003 // Corporation and others.  All Rights Reserved.
00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
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     // analyze model
00115     int * analyze(OsiClpSolverInterface * solverMod, int & numberChanged, double & increment,
00116                   bool changeInt,  CoinMessageHandler * generalMessageHandler);
00122     //int doHeuristics(CbcModel * model, int type);
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 
00244 class CbcSolverUsefulData {
00245 
00246 public:
00248 
00249 
00250     CbcSolverUsefulData();
00251 
00254     CbcSolverUsefulData(const CbcSolverUsefulData & rhs);
00255 
00257     CbcSolverUsefulData & operator=(const CbcSolverUsefulData& rhs);
00258 
00260     ~CbcSolverUsefulData ();
00262 
00264 
00265     // For time
00266     double totalTime_;
00267     // Parameters
00268     CbcOrClpParam parameters_[CBCMAXPARAMETERS];
00269     // Printing
00270     bool noPrinting_;
00271     // Whether to use signal handler
00272     bool useSignalHandler_;
00273     // Number of Parameters
00274     int numberParameters_;
00275     // Default pump tuning
00276     int initialPumpTune_;
00278 };
00280 // When we want to load up CbcModel with options first
00281 void CbcMain0 (CbcModel & babSolver,CbcSolverUsefulData & solverData);
00282 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom),CbcSolverUsefulData & solverData);
00283 
00284 //#############################################################################
00285 
00290 class CbcUser {
00291 
00292 public:
00294 
00295 
00302     virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
00303         return -1;
00304     }
00305 
00313     virtual void exportSolution(CbcSolver * /*model*/,
00314                                 int /*mode*/, const char * /*message*/ = NULL) {}
00315 
00317     virtual void exportData(CbcSolver * /*model*/) {}
00318 
00320     virtual void fillInformation(CbcSolver * /*model*/,
00321                                  CbcSolverUsefulData & /*info*/) {}
00323 
00325 
00326 
00327     inline CoinModel *coinModel() const {
00328         return coinModel_;
00329     }
00331     virtual void * stuff() {
00332         return NULL;
00333     }
00335     inline std::string name() const {
00336         return userName_;
00337     }
00339     virtual void solve(CbcSolver * model, const char * options) = 0;
00341     virtual bool canDo(const char * options) = 0;
00343 
00345 
00346 
00347     CbcUser();
00348 
00350     CbcUser(const CbcUser & rhs);
00351 
00353     CbcUser & operator=(const CbcUser& rhs);
00354 
00356     virtual CbcUser * clone() const = 0;
00357 
00359     virtual ~CbcUser ();
00361 
00362 protected:
00364 
00365 
00367     CoinModel * coinModel_;
00368 
00370     std::string userName_;
00371 
00373 };
00374 //#############################################################################
00375 
00381 class CbcStopNow {
00382 
00383 public:
00385 
00386 
00399     virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/) {
00400         return 0;
00401     }
00403 
00405 
00406 
00407     CbcStopNow();
00408 
00411     CbcStopNow(const CbcStopNow & rhs);
00412 
00414     CbcStopNow & operator=(const CbcStopNow& rhs);
00415 
00417     virtual CbcStopNow * clone() const;
00418 
00420     virtual ~CbcStopNow ();
00422 
00423 private:
00425 
00426 
00427 };
00428 #endif
00429 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 25 Aug 2014 for Cbc by  doxygen 1.6.1