source: branches/devel/Bonmin/src/OaInterface/BonOACutGenerator2.hpp @ 62

Last change on this file since 62 was 62, checked in by pbonami, 13 years ago

astyled the devel branch

  • Property svn:eol-style set to native
  • Property svn:keywords set to "Author Date Id Revision"
File size: 5.4 KB
Line 
1// (C) Copyright Carnegie Mellon University 2005
2// All Rights Reserved.
3// This code is published under the Common Public License.
4//
5// Authors :
6// P. Bonami, Carnegie Mellon University
7//
8// Date :  05/26/2005
9
10
11#ifndef BonOACutGenerator2_HPP
12#define BonOACutGenerator2_HPP
13#include "CglCutGenerator.hpp"
14#include "BonOsiTMINLPInterface.hpp"
15#include "BonOAMessages.hpp"
16#include "CbcModel.hpp"
17
18#include "CbcStrategy.hpp"
19
20#include "CoinTime.hpp"
21
22namespace Bonmin
23{
24  class OACutGenerator2 : public CglCutGenerator
25  {
26  public:
27    typedef enum subSolver {Clp, Cbc, Cplex, Other};
28    /// Default constructor
29    OACutGenerator2();
30    /// Usefull constructor
31    OACutGenerator2(OsiTMINLPInterface * nlp = NULL,
32        OsiSolverInterface * si = NULL,
33        CbcStrategy * strategy = NULL,
34        double cbcCutoffIncrement_=1e-07,
35        double cbcIntegerTolerance = 1e-05,
36        bool solveAuxiliaryProblem = 1,
37        bool leaveSiUnchanged = 0
38                   );
39
40    /// Copy constructor
41    OACutGenerator2(const OACutGenerator2 &copy)
42        :nlp_(copy.nlp_),
43        si_(copy.si_),
44        cbcCutoffIncrement_(copy.cbcCutoffIncrement_),
45        cbcIntegerTolerance_(copy.cbcIntegerTolerance_),
46        localSearchNodeLimit_(copy.localSearchNodeLimit_),
47        maxLocalSearchPerNode_(copy.maxLocalSearchPerNode_),
48        maxLocalSearch_(copy.maxLocalSearch_),
49        maxLocalSearchTime_(copy.maxLocalSearchTime_),
50        nLocalSearch_(copy.nLocalSearch_),
51        solveAuxiliaryProblem_(copy.solveAuxiliaryProblem_),
52        handler_(NULL), messages_(copy.messages_),
53        subMilpLogLevel_(copy.subMilpLogLevel_),
54        leaveSiUnchanged_(copy.leaveSiUnchanged_),
55        strategy_(NULL),
56        timeBegin_(0.),
57        logFrequency_(copy.logFrequency_)
58    {
59      handler_ = new CoinMessageHandler();
60      handler_->setLogLevel(copy.handler_->logLevel());
61      if (copy.strategy_)
62        strategy_ = copy.strategy_->clone();
63      timeBegin_ = CoinCpuTime();
64    }
65    /// Destructor
66    ~OACutGenerator2();
67
68    /// Assign an OsiTMINLPInterface
69    void assignNlpInterface(OsiTMINLPInterface * nlp);
70
71    /// Assign an OsiTMINLPInterface
72    void assignLpInterface(OsiSolverInterface * si);
73
74    void setStrategy(const CbcStrategy & strategy)
75    {
76      if (strategy_)
77        delete strategy_;
78      strategy_ = strategy.clone();
79    }
80    /// cut generation method
81    virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
82        const CglTreeInfo info = CglTreeInfo()) const;
83
84    virtual CglCutGenerator * clone() const
85    {
86      return new OACutGenerator2(*this);
87    }
88
89    inline int getNSolve()
90    {
91      return nSolve_;
92    }
93    /// Set value for cutoff increment
94    void setcbcCutoffIncrement (double value)
95    {
96      cbcCutoffIncrement_ = value;
97    }
98    /// Set value for integer tolerance
99    void setcbcIntegerTolerance (double value)
100    {
101      cbcIntegerTolerance_ = value;
102    }
103    ///set max number of nodes for local search
104    void setLocalSearchNodeLimit(int value)
105    {
106      localSearchNodeLimit_ = value;
107      if (si_)
108        setTheNodeLimit();
109    }
110    ///set max number of local searches per node
111    void setMaxLocalSearchPerNode(int value)
112    {
113      maxLocalSearchPerNode_ = value;
114    }
115    ///set total max number of local searches
116    void setMaxLocalSearch(int value)
117    {
118      maxLocalSearch_ = value;
119    }
120
121    void setMaxLocalSearchTime(double time)
122    {
123      maxLocalSearchTime_ = time;
124    }
125    /**set log level */
126    void setLogLevel(int value)
127    {
128      handler_->setLogLevel(value);
129    }
130    /** Set log frequency.*/
131    void setLogFrequency(double value)
132    {
133      logFrequency_ = value;
134    }
135    /**set log level */
136    void setSubMilpLogLevel(int value)
137    {
138      subMilpLogLevel_ = value;
139    }
140  private:
141    /// Set the node limit to the interface
142    void setTheNodeLimit();
143    /// Set the time limit for b&b
144    void setTimeLimit(double time) const;
145    /// Set the cutoff for b&b
146    void setCutoff(double cutoff) const;
147    /// Get bound on the solution value after doing partial local search
148    double siBestObj(CbcModel * model=NULL) const;
149    /// Pointer to the Ipopt interface
150    OsiTMINLPInterface * nlp_;
151    ///Number of NLP resolution done
152    mutable int nSolve_;
153    /// A linear solver
154    mutable OsiSolverInterface * si_;
155    /// cutoff min increase (has to be intialized trhough Cbc)
156    double cbcCutoffIncrement_;
157    /// integer tolerance (has to be the same as Cbc's)
158    double cbcIntegerTolerance_;
159    ///Max number of nodes for local search
160    int localSearchNodeLimit_;
161    ///Max number of local searches per node
162    int maxLocalSearchPerNode_;
163    ///Total max number of local searches
164    int maxLocalSearch_;
165    /// maximum time for local searches
166    double maxLocalSearchTime_;
167    ///number of local searches performed
168    mutable int nLocalSearch_;
169    ///set to 1 to solve  an auxiliary NLP when infeasible assignment is encountered
170    bool solveAuxiliaryProblem_;
171    /** messages handler. */
172    CoinMessageHandler * handler_;
173    /** handler */
174    CoinMessages messages_;
175    /** sub milp log level.*/
176    int subMilpLogLevel_;
177    /** Wether or not we should remove cuts at the end of the procedure */
178    bool leaveSiUnchanged_;
179    /** Strategy to apply when using Cbc as MILP sub-solver.*/
180    CbcStrategy * strategy_;
181    /** time of construction*/
182    double timeBegin_;
183    /** Frequency of log. */
184    double logFrequency_;
185  };
186}
187#endif
Note: See TracBrowser for help on using the repository browser.