| 1 |
// (C) Copyright Carnegie Mellon University 2005, 2006 |
| 2 |
// All Rights Reserved. |
| 3 |
// This code is published under the Eclipse Public License. |
| 4 |
// |
| 5 |
// Authors : |
| 6 |
// P. Bonami, Carnegie Mellon University |
| 7 |
// |
| 8 |
// Date : 05/26/2005 |
| 9 |
|
| 10 |
#ifndef BonOaNlpOptim_HPP |
| 11 |
#define BonOaNlpOptim_HPP |
| 12 |
#include "CglCutGenerator.hpp" |
| 13 |
#include "BonOsiTMINLPInterface.hpp" |
| 14 |
#include "BonOAMessages.hpp" |
| 15 |
#include "BonBabSetupBase.hpp" |
| 16 |
namespace Bonmin |
| 17 |
{ |
| 18 |
/** Generate cuts for the nlp corresponding to continuous relaxation at a node.*/ |
| 19 |
class OaNlpOptim : public CglCutGenerator |
| 20 |
{ |
| 21 |
public: |
| 22 |
/// Default constructor |
| 23 |
OaNlpOptim(OsiTMINLPInterface * si = NULL, |
| 24 |
int maxDepth = 10, bool addOnlyViolated = false, |
| 25 |
bool globalCuts = true); |
| 26 |
|
| 27 |
/// Constructor with basic setup |
| 28 |
OaNlpOptim(BabSetupBase &b); |
| 29 |
/// Copy constructor |
| 30 |
OaNlpOptim(const OaNlpOptim ©) |
| 31 |
: |
| 32 |
CglCutGenerator(copy), |
| 33 |
nlp_(copy.nlp_), |
| 34 |
maxDepth_(copy.maxDepth_), |
| 35 |
nSolve_(0), |
| 36 |
addOnlyViolated_(copy.addOnlyViolated_), |
| 37 |
global_(copy.global_), |
| 38 |
solves_per_level_(copy.solves_per_level_) |
| 39 |
{ |
| 40 |
handler_ = new CoinMessageHandler(); |
| 41 |
handler_ -> setLogLevel(copy.handler_->logLevel()); |
| 42 |
messages_ = OaMessages(); |
| 43 |
} |
| 44 |
void passInMessageHandler(const CoinMessageHandler * handler) |
| 45 |
{ |
| 46 |
delete handler_; |
| 47 |
handler_ = handler->clone(); |
| 48 |
} |
| 49 |
///Abstract constructor |
| 50 |
virtual CglCutGenerator * clone() const |
| 51 |
{ |
| 52 |
return new OaNlpOptim(*this); |
| 53 |
} |
| 54 |
|
| 55 |
/** Desctructor */ |
| 56 |
virtual ~OaNlpOptim() |
| 57 |
{ |
| 58 |
if (handler_) |
| 59 |
delete handler_; |
| 60 |
} |
| 61 |
|
| 62 |
/// Assign an OsiTMINLPInterface |
| 63 |
void assignInterface(OsiTMINLPInterface * si); |
| 64 |
/// cut generation method |
| 65 |
virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs, |
| 66 |
const CglTreeInfo info); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
inline void setMaxDepth(int value) |
| 71 |
{ |
| 72 |
maxDepth_ = value; |
| 73 |
} |
| 74 |
inline void setAddOnlyViolated(bool yesno) |
| 75 |
{ |
| 76 |
addOnlyViolated_ = yesno; |
| 77 |
} |
| 78 |
inline void setGlobalCuts(bool yesno) |
| 79 |
{ |
| 80 |
global_ = yesno; |
| 81 |
} |
| 82 |
inline int getNSolve() |
| 83 |
{ |
| 84 |
return nSolve_; |
| 85 |
} |
| 86 |
/**set log level */ |
| 87 |
void setLogLevel(int value) |
| 88 |
{ |
| 89 |
handler_->setLogLevel(value); |
| 90 |
} |
| 91 |
|
| 92 |
/** Register OaNlpOptim options.*/ |
| 93 |
static void registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions); |
| 94 |
|
| 95 |
private: |
| 96 |
/// Pointer to the Ipopt interface |
| 97 |
OsiTMINLPInterface * nlp_; |
| 98 |
|
| 99 |
/** maximum depth at which generate cuts*/ |
| 100 |
int maxDepth_; |
| 101 |
|
| 102 |
///Number of NLP resolution done |
| 103 |
mutable int nSolve_; |
| 104 |
/** messages handler. */ |
| 105 |
CoinMessageHandler * handler_; |
| 106 |
/** handler */ |
| 107 |
CoinMessages messages_; |
| 108 |
/** Add only violated cuts?*/ |
| 109 |
bool addOnlyViolated_; |
| 110 |
/** Add cuts as global?*/ |
| 111 |
bool global_; |
| 112 |
/** Average number of nodes per level in tree */ |
| 113 |
double solves_per_level_; |
| 114 |
}; |
| 115 |
} |
| 116 |
#endif |