11 int (*
f)(
double*,
double*),
int (*
df)(
double*,
double*),
12 int (*g)(
double*,
double*),
int (*dg)(
double*,
double*),
13 int (*h)(
double*,
double*),
int (*dh)(
double*,
double*),
14 int m_x,
int m_g,
int m_h,
15 double ftol,
double xtol,
double eqthre,
int max_eval,
double max_time,
18 x(x), m_x(m_x), m_g(m_g), m_h(m_h), iteration(0), n_f(0), n_df(0), n_g(0), n_dg(0), n_h(0), n_dh(0) {
26 this->
fbuf = (
double*)malloc(
sizeof(
double)*1) ;
28 this->
dfbuf = (
double*)malloc(
sizeof(
double)*1*
m_x) ;
29 for ( uint i=0 ; i<1*
m_x ; i++ ) this->
dfbuf[i] = 0 ;
30 this->
gbuf = (
double*)malloc(
sizeof(
double)*
m_g) ;
31 for ( uint i=0 ; i<
m_g ; i++ ) this->
gbuf[i] = 0 ;
32 this->
dgbuf = (
double*)malloc(
sizeof(
double)*
m_g*
m_x) ;
33 for ( uint i=0 ; i<
m_x*
m_g ; i++ ) this->
dgbuf[i] = 0 ;
34 this->
hbuf = (
double*)malloc(
sizeof(
double)*
m_h) ;
35 for ( uint i=0 ; i<
m_h ; i++ ) this->
hbuf[i] = 0 ;
36 this->
dhbuf = (
double*)malloc(
sizeof(
double)*
m_h*
m_x) ;
37 for ( uint i=0 ; i<
m_x*
m_h ; i++ ) this->
dhbuf[i] = 0 ;
45 solver = nlopt_create(NLOPT_GN_ISRES,
m_x);
46 nlopt_set_maxeval(
solver, 1e6);
47 nlopt_set_maxtime(
solver, 24*60*60);
51 solver = nlopt_create(NLOPT_LD_SLSQP,
m_x);
52 nlopt_set_ftol_rel(
solver, ftol);
53 nlopt_set_xtol_rel(
solver, xtol);
82 solver = nlopt_create(NLOPT_AUGLAG_EQ,
m_x);
84 nlopt_set_ftol_rel(
solver, ftol);
85 nlopt_set_xtol_rel(
solver, xtol);
86 nlopt_set_maxeval(
solver, 1e6);
123 core_solver = nlopt_create(NLOPT_LD_TNEWTON_PRECOND_RESTART,
m_x);
133 solver = nlopt_create(NLOPT_AUGLAG,
m_x);
135 nlopt_set_ftol_rel(
solver, ftol);
136 nlopt_set_xtol_rel(
solver, xtol);
148 solver = nlopt_create(NLOPT_LN_COBYLA,
m_x);
149 nlopt_set_ftol_rel(
solver, ftol);
150 nlopt_set_xtol_rel(
solver, xtol);
154 solver = nlopt_create(NLOPT_LN_BOBYQA,
m_x);
155 nlopt_set_ftol_rel(
solver, ftol);
156 nlopt_set_xtol_rel(
solver, xtol);
160 solver = nlopt_create(NLOPT_LN_NEWUOA,
m_x);
161 nlopt_set_ftol_rel(
solver, ftol);
162 nlopt_set_xtol_rel(
solver, xtol);
166 solver = nlopt_create(NLOPT_LN_PRAXIS,
m_x);
167 nlopt_set_ftol_rel(
solver, ftol);
168 nlopt_set_xtol_rel(
solver, xtol);
172 solver = nlopt_create( NLOPT_LN_NELDERMEAD,
m_x);
173 nlopt_set_ftol_rel(
solver, ftol);
174 nlopt_set_xtol_rel(
solver, xtol);
178 solver = nlopt_create(NLOPT_LN_SBPLX,
m_x);
179 nlopt_set_ftol_rel(
solver, ftol);
180 nlopt_set_xtol_rel(
solver, xtol);
184 if ( max_eval > 0 ) nlopt_set_maxeval(
solver,max_eval) ;
185 if ( max_time > 0 ) nlopt_set_maxtime(
solver,max_time) ;
187 nlopt_set_lower_bounds(
solver, x_min);
188 nlopt_set_upper_bounds(
solver, x_max);
193 double equality_constraint_tolerance[
m_g];
194 std::fill(equality_constraint_tolerance, equality_constraint_tolerance +
m_g, eqthre);
198 double inequality_constraint_tolerance[
m_h];
199 std::fill(inequality_constraint_tolerance, inequality_constraint_tolerance +
m_h, eqthre);
201 int major, minor, bugfix;
202 nlopt_version(&major, &minor, &bugfix);
247 if ( this->
f ) (*(this->
f))(this->
x,this->
fbuf) ;
248 return this->
fbuf[0];
258 if ( this->
df ) (*(this->
df))(this->
x,
dfbuf) ;
284 if ( this->
g && this->
m_g>0 ) (*(this->
g))(this->
x,
gbuf) ;
293 if ( this->
dg && this->
m_g>0 ) (*(this->
dg))(this->
x,
dgbuf) ;
320 if ( this->
h && this->
m_h>0 ) (*(this->
h))(this->
x,
hbuf) ;
336 nlopt_result
result=nlopt_optimize(this->
solver, this->x, &cost);
338 this->
fbuf[0] = cost;