提交 d003061a 编写于 作者: S Steven G. Johnson

rm obsolete #ifdef NLOPT_UTIL_H in stogo code

上级 99ec04d9
......@@ -35,35 +35,13 @@ Global::Global(RTBox D, Pobj o, Pgrad g, GlobalParams P): Domain(D) {
Gradient=g;
// Initialize parameters
#ifdef NLOPT_UTIL_H
stop = P.stop;
#else
maxtime=P.maxtime;
maxeval = P.maxeval;
#endif
numeval = 0;
eps_cl=P.eps_cl; mu=P.mu; rshift=P.rshift;
det_pnts=P.det_pnts; rnd_pnts=P.rnd_pnts;
fbound=DBL_MAX;
}
#if 0 // not necessary; default copy is sufficient
Global& Global::operator=(const Global &G) {
// Copy the problem info and parameter settings
Domain=G.Domain; Objective=G.Objective; Gradient=G.Gradient;
#ifdef NLOPT_UTIL_H
stop = G.stop;
#else
maxtime=G.maxtime;
maxeval = G.maxeval;
#endif
numeval = G.numeval;
eps_cl=G.eps_cl; mu=G.mu; rshift=G.rshift;
det_pnts=G.det_pnts; rnd_pnts=G.rnd_pnts;
return *this;
}
#endif
void Global::FillRegular(RTBox SampleBox, RTBox box) {
// Generation of regular sampling points
double w;
......@@ -76,11 +54,11 @@ void Global::FillRegular(RTBox SampleBox, RTBox box) {
tmpTrial.objval=DBL_MAX ;
// Add the rest
i=1 ; flag=1 ; dir=0 ;
x=m ;
x=m ;
while (i<det_pnts) {
w=box.Width(dir) ;
x(dir)=m(dir)+flag*rshift*w ;
tmpTrial.xvals=x ;
tmpTrial.xvals=x ;
SampleBox.AddTrial(tmpTrial) ;
flag=-flag;
if (flag==1 && dir<dim) {
......@@ -90,7 +68,7 @@ void Global::FillRegular(RTBox SampleBox, RTBox box) {
i++ ;
}
// Add midpoint
tmpTrial.xvals=m ;
tmpTrial.xvals=m ;
SampleBox.AddTrial(tmpTrial) ;
}
}
......@@ -123,11 +101,7 @@ double Global::NewtonTest(RTBox box, int axis, RCRVector x_av, int *noutside) {
while ( !SampleBox.EmptyBox() ) {
SampleBox.RemoveTrial(tmpTrial) ;
info = local(tmpTrial, box, Domain, eps_cl, &maxgrad, *this,
axis, x_av
#ifdef NLOPT_UTIL_H
, stop
#endif
) ;
axis, x_av, stop) ;
// What should we do when info=LS_Unstable?
if (info == LS_Out)
nout++;
......@@ -135,15 +109,13 @@ double Global::NewtonTest(RTBox box, int axis, RCRVector x_av, int *noutside) {
box.AddTrial(tmpTrial) ;
if (tmpTrial.objval<=fbound+mu && tmpTrial.objval<=box.minf+mu) {
if (stogo_verbose) {
cout << "Found a candidate, x=" << tmpTrial.xvals;
cout << " F=" <<tmpTrial.objval << " FC=" << FC << endl;
}
SolSet.push_back(tmpTrial);
#ifdef NLOPT_UTIL_H
if (tmpTrial.objval < stop->minf_max)
break;
#endif
if (stogo_verbose) {
cout << "Found a candidate, x=" << tmpTrial.xvals;
cout << " F=" <<tmpTrial.objval << " FC=" << FC << endl;
}
SolSet.push_back(tmpTrial);
if (tmpTrial.objval < stop->minf_max)
break;
}
#ifdef GS_DEBUG
cout << "Found a stationary point, X= " << tmpTrial.xvals;
......@@ -240,12 +212,10 @@ void Global::Search(int axis, RCRVector x_av){
#endif
ReduceOrSubdivide(box, axis, x_av);
#ifdef NLOPT_UTIL_H
if (!NoMinimizers() && OneMinimizer(x) < stop->minf_max) {
done = TRUE;
break;
done = TRUE;
break;
}
#endif
if (!InTime()) {
done=TRUE;
if (stogo_verbose)
......@@ -256,7 +226,7 @@ void Global::Search(int axis, RCRVector x_av){
} // inner while-loop
if (stogo_verbose)
cout << endl << "*** Inner loop completed ***" << endl ;
// Reduce SolSet if necessary
SolSet.erase(remove_if(SolSet.begin(), SolSet.end(),
TrialGT(fbound+mu)),SolSet.end());
......@@ -302,11 +272,7 @@ double Global::GetTime()
bool Global::InTime()
{
#ifdef NLOPT_UTIL_H
return !nlopt_stop_evalstime(stop);
#else
return (maxtime <= 0.0 || GetTime()<maxtime) && (!maxeval || numeval<maxeval);
#endif
}
double Global::GetMinValue() {
......
......@@ -26,12 +26,7 @@ typedef objgrad* Pobjgrad ;
class GlobalParams {
public:
#ifdef NLOPT_UTIL_H
nlopt_stopping *stop;
#else
double maxtime;
long int maxeval;
#endif
double eps_cl, mu, rshift;
int det_pnts, rnd_pnts;
};
......@@ -57,9 +52,9 @@ public:
}
return 0.0;
}
Global(RTBox, Pobj, Pgrad, GlobalParams);
virtual ~Global(){};
// Global& operator=(const Global &);
......
......@@ -11,14 +11,6 @@
#include "local.h"
#include "tools.h"
#ifdef NLOPT_UTIL_H
# define IF_NLOPT_CHECK_EVALS ++ *(stop->nevals_p); \
if (nlopt_stop_evalstime(stop)) \
return LS_MaxEvalTime
#else
# define IF_NLOPT_CHECK_EVALS
#endif
////////////////////////////////////////////////////////////////////////
// SGJ, 2007: allow local to use local optimizers in NLopt, to compare
// to the BFGS code below
......@@ -80,7 +72,7 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
#endif
T.objval=tmp;
return LS_Old ;
}
}
#if 0
......@@ -94,7 +86,7 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
data.stop = stop;
nlopt_result ret = nlopt_minimize(NLOPT_LOCAL_LBFGS, n, f_local, &data,
box.lb.raw_data(), box.ub.raw_data(),
x.raw_data(), &f,
x.raw_data(), &f,
stop->minf_max,
stop->ftol_rel, stop->ftol_abs,
stop->xtol_rel, stop->xtol_abs,
......@@ -108,7 +100,7 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
return LS_New;
else
return LS_Out; // failure
#else /* not using NLopt local optimizer ... use original STOgo BFGS code */
int k_max, info, outside = 0;
......@@ -139,7 +131,9 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
f=glob.ObjectiveGradient(x_av,g_av,OBJECTIVE_AND_GRADIENT);
g(0)=g_av(axis);
}
IF_NLOPT_CHECK_EVALS;
++ *(stop->nevals_p);
if (nlopt_stop_evalstime(stop))
return LS_MaxEvalTime;
FC++;GC++;
if (axis == -1) {
......@@ -237,8 +231,8 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
}
else {
// Combination of Newton and SD steps
d2 = delta*delta ;
copy(h_sd,s) ;
d2 = delta*delta ;
copy(h_sd,s) ;
s2=nrm_sd*nrm_sd ;
nom = d2 - s2 ;
snrm_hn=nrm_hn*nrm_hn ;
......@@ -249,7 +243,7 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
break ;
}
// Normalization (N38, eq. 3.31)
beta = nom/den ;
beta = nom/den ;
copy(h_n,h_dl) ;
scal(beta,h_dl) ;
axpy((1-beta),h_sd,h_dl) ;
......@@ -284,7 +278,7 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
break ;
}
else {
outside=0 ;
outside=0 ;
}
// Compute the gain
......@@ -294,7 +288,9 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
x_av(axis)=x_new(0);
f_new=glob.ObjectiveGradient(x_av,g_av,OBJECTIVE_AND_GRADIENT);
}
IF_NLOPT_CHECK_EVALS;
++ *(stop->nevals_p);
if (nlopt_stop_evalstime(stop))
return LS_MaxEvalTime;
FC++; GC++;
gemv('N',0.5,B,h_dl,0.0,z);
ro = (f_new-f) / (dot(g,h_dl) + dot(h_dl,z)); // Quadratic model
......@@ -306,20 +302,8 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
}
if (ro > 0) {
// Update the Hessian and it's inverse using the BFGS formula
#if 0 // changed by SGJ to compute OBJECTIVE_AND_GRADIENT above
if (axis==-1)
glob.ObjectiveGradient(x_new,g_new,GRADIENT_ONLY);
else {
x_av(axis)=x_new(0);
glob.ObjectiveGradient(x_av,g_av,GRADIENT_ONLY);
g_new(0)=g_av(axis);
}
GC++;
IF_NLOPT_CHECK_EVALS;
#else
if (axis != -1)
g_new(0)=g_av(axis);
#endif
g_new(0)=g_av(axis);
// y=g_new-g
copy(g_new,y);
......@@ -383,7 +367,7 @@ int local(Trial &T, TBox &box, TBox &domain, double eps_cl, double *mgr,
cout << "Step is no good, ro=" << ro << " delta=" << delta << endl ;
#endif
}
} // wend
// Make sure the routine returns correctly...
......
......@@ -20,10 +20,6 @@ const int max_iter=50 ; // Max iterations = max_iter*dim. of problem
extern double MacEpsilon ; // min {x >= 0 : 1 + x > 1}
int local(Trial &, TBox &, TBox &, double, double*, Global&, int, RCRVector
#ifdef NLOPT_UTIL_H
, nlopt_stopping *stop
#endif
);
int local(Trial &, TBox &, TBox &, double, double*, Global&, int, RCRVector, nlopt_stopping *stop);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册