11 #include "OsiAuxInfo.hpp"
12 #include "CbcModel.hpp"
18 static const char *
txt_id =
"NLP relax. for OA";
22 int maxDepth,
bool addOnlyViolated,
bool global)
28 addOnlyViolated_(addOnlyViolated),
38 nlp_(b.nonlinearSolver()),
43 b.
options()->GetEnumValue(
"add_only_violated_oa", ivalue,b.
prefix());
45 b.
options()->GetEnumValue(
"oa_cuts_scope", ivalue,b.
prefix());
64 const CglTreeInfo
info) {
66 CoinError(
"Error in cut generator for outer approximation no ipopt NLP assigned",
"generateCuts",
"OaNlpOptim");
74 if(!info.inTree || info.pass > 0)
return;
76 BabInfo * babInfo =
dynamic_cast<BabInfo *
> (si.getAuxiliaryInfo());
79 const CbcNode * node = babInfo->
babPtr()->
model().currentNode();
80 int level = (node == NULL) ? 0 : babInfo->
babPtr()->
model().currentNode()->depth();
84 double rand = CoinDrand48();
92 double * saveColLb =
new double[numcols];
93 double * saveColUb =
new double[numcols];
96 for (
int i = 0; i < numcols ; i++) {
98 nlp_->setColBounds(i,si.getColLower()[i],si.getColUpper()[i]);
115 for (
int i = 0 ; i < numcols && feasible; i++) {
117 if (fabs(colsol2[i] - floor(colsol2[i] + 0.5) ) > 1
e-07)
124 OsiAuxInfo * auxInfo = si.getAuxiliaryInfo();
125 OsiBabSolver * auxiliaryInfo =
dynamic_cast<OsiBabSolver *
> (auxInfo);
127 double * lpSolution =
new double[numcols + 1];
128 CoinCopyN(colsol2, numcols, lpSolution);
130 auxiliaryInfo->setSolution(lpSolution, numcols + 1, lpSolution[numcols]);
131 delete [] lpSolution;
134 fprintf(stderr,
"No auxiliary info in nlp solve!\n");
140 throw CoinError(
"Unsolved NLP ... exit",
"generateCuts",
"OaNlpOptim");
163 for (
int i = 0; i < numcols ; i++) {
165 nlp_->setColBounds(i,saveColLb[i],saveColUb[i]);
169 nlp_->deleteLastRows(numberCuts);
179 roptions->AddLowerBoundedIntegerOption(
"nlp_solve_frequency",
180 "Specify the frequency (in terms of nodes) at which NLP relaxations are solved in B-Hyb.",
182 "A frequency of 0 amounts to to never solve the NLP relaxation.");
183 roptions->setOptionExtraInfo(
"nlp_solve_frequency",1);
184 roptions->AddLowerBoundedIntegerOption(
"nlp_solve_max_depth",
185 "Set maximum depth in the tree at which NLP relaxations are solved in B-Hyb.",
187 "A depth of 0 amounts to to never solve the NLP relaxation.");
188 roptions->setOptionExtraInfo(
"nlp_solve_max_depth",1);
189 roptions->AddLowerBoundedNumberOption(
"nlp_solves_per_depth",
190 "Set average number of nodes in the tree at which NLP relaxations are solved in B-Hyb for each depth.",
192 roptions->setOptionExtraInfo(
"nlp_solves_per_depth",1);
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register OaNlpOptim options.
bool addOnlyViolated_
Add only violated cuts?
virtual bool isAbandoned() const
Are there a numerical difficulties?
void getOuterApproximation(OsiCuts &cs, int getObj, const double *x2, bool global)
Get the outer approximation constraints at the current optimal point.
void assignInterface(OsiTMINLPInterface *si)
Assign an OsiTMINLPInterface.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
virtual bool isInteger(int columnNumber) const
Return true if column is integer.
void setLogLevel(int value)
set log level
virtual int getNumCols() const
Get number of columns.
virtual bool isProvenOptimal() const
Is optimality proven?
double solves_per_level_
Average number of nodes per level in tree.
virtual double getObjValue() const
Get objective function value (can't use default)
OsiTMINLPInterface * nlp_
Pointer to the Ipopt interface.
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
void fint fint fint real fint real real real real real real real real real * e
A class to have all elements necessary to setup a branch-and-bound.
bool global_
Add cuts as global?
CoinMessageHandler * handler_
messages handler.
virtual void resolve()
Resolve the continuous relaxation after problem modification.
virtual bool isIterationLimitReached() const
Iteration limit reached?
CoinMessages messages_
handler
Bab * babPtr()
Pointer to the branch-and-bound algorithm (to access CbcModel).
int nSolve_
Number of NLP resolution done.
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
int maxDepth_
maximum depth at which generate cuts
Output messages for Outer approximation cutting planes.
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
static const char * txt_id
OaNlpOptim(OsiTMINLPInterface *si=NULL, int maxDepth=10, bool addOnlyViolated=false, bool globalCuts=true)
Default constructor.
const char * prefix() const
Get prefix to use for options.
const CbcModel & model() const
Get cbc model used to solve.
Bonmin class for passing info between components of branch-and-cuts.
virtual void generateCuts(const OsiSolverInterface &si, OsiCuts &cs, const CglTreeInfo info)
cut generation method