CbcSolver.hpp

Go to the documentation of this file.
00001 /* $Id: CbcSolver.hpp 1998 2013-12-19 18:11:05Z 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 
00240 typedef struct {
00241     // Priorities
00242     int * priorities_;
00243     // SOS priorities
00244     int * sosPriority_;
00245     // Direction to branch first
00246     int * branchDirection_;
00247     // Input solution
00248     double * primalSolution_;
00249     // Down pseudo costs
00250     double * pseudoDown_;
00251     // Up pseudo costs
00252     double * pseudoUp_;
00253 } CbcSolverUsefulData2;
00254 
00255 //#############################################################################
00256 
00262 class CbcSolverUsefulData {
00263 
00264 public:
00266 
00267 
00268     CbcSolverUsefulData();
00269 
00272     CbcSolverUsefulData(const CbcSolverUsefulData & rhs);
00273 
00275     CbcSolverUsefulData & operator=(const CbcSolverUsefulData& rhs);
00276 
00278     ~CbcSolverUsefulData ();
00280 
00282 
00283     // For time
00284     double totalTime_;
00285     // Parameters
00286     CbcOrClpParam parameters_[CBCMAXPARAMETERS];
00287     // Printing
00288     bool noPrinting_;
00289     // Whether to use signal handler
00290     bool useSignalHandler_;
00291     // Number of Parameters
00292     int numberParameters_;
00293     // Default pump tuning
00294     int initialPumpTune_;
00296 };
00298 // When we want to load up CbcModel with options first
00299 void CbcMain0 (CbcModel & babSolver,CbcSolverUsefulData & solverData);
00300 int CbcMain1 (int argc, const char *argv[], CbcModel & babSolver, int (CbcModel * currentSolver, int whereFrom),CbcSolverUsefulData & solverData);
00301 
00302 //#############################################################################
00303 
00308 class CbcUser {
00309 
00310 public:
00312 
00313 
00320     virtual int importData(CbcSolver * /*model*/, int & /*argc*/, char ** /*argv[]*/) {
00321         return -1;
00322     }
00323 
00331     virtual void exportSolution(CbcSolver * /*model*/,
00332                                 int /*mode*/, const char * /*message*/ = NULL) {}
00333 
00335     virtual void exportData(CbcSolver * /*model*/) {}
00336 
00338     virtual void fillInformation(CbcSolver * /*model*/,
00339                                  CbcSolverUsefulData & /*info*/) {}
00341 
00343 
00344 
00345     inline CoinModel *coinModel() const {
00346         return coinModel_;
00347     }
00349     virtual void * stuff() {
00350         return NULL;
00351     }
00353     inline std::string name() const {
00354         return userName_;
00355     }
00357     virtual void solve(CbcSolver * model, const char * options) = 0;
00359     virtual bool canDo(const char * options) = 0;
00361 
00363 
00364 
00365     CbcUser();
00366 
00368     CbcUser(const CbcUser & rhs);
00369 
00371     CbcUser & operator=(const CbcUser& rhs);
00372 
00374     virtual CbcUser * clone() const = 0;
00375 
00377     virtual ~CbcUser ();
00379 
00380 protected:
00382 
00383 
00385     CoinModel * coinModel_;
00386 
00388     std::string userName_;
00389 
00391 };
00392 //#############################################################################
00393 
00399 class CbcStopNow {
00400 
00401 public:
00403 
00404 
00417     virtual int callBack(CbcModel * /*currentSolver*/, int /*whereFrom*/) {
00418         return 0;
00419     }
00421 
00423 
00424 
00425     CbcStopNow();
00426 
00429     CbcStopNow(const CbcStopNow & rhs);
00430 
00432     CbcStopNow & operator=(const CbcStopNow& rhs);
00433 
00435     virtual CbcStopNow * clone() const;
00436 
00438     virtual ~CbcStopNow ();
00440 
00441 private:
00443 
00444 
00445 };
00446 #endif
00447 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 8 Mar 2015 for Cbc by  doxygen 1.6.1