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);
71 core_solver = nlopt_create(NLOPT_GN_ORIG_DIRECT, m_x);
75 core_solver = nlopt_create(NLOPT_GN_ORIG_DIRECT_L, m_x);
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);
100 core_solver = nlopt_create(NLOPT_GN_DIRECT_L, m_x);
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;
double ObjectiveFunctionCost()
評価関数の和を計算する
int(* f)(double *, double *)
unsigned int n_df
評価関数の勾配の計算回数
void InequalityConstraintGradient(double *dh)
不等式制約条件の勾配
unsigned int m_g
等式制約条件の次元
int(*)(*) df(double *, double *)
unsigned int n_g
等式制約条件の計算回数
static void InequalityConstraintWrapper(unsigned int m, double *h, unsigned int n, const double *x, double *dh, void *self)
不等式制約条件のラッパー
Algorithm
NLoptに実装されているアルゴリズム
void InequalityConstraintCost(double *h)
不等式制約条件
static void EqualityConstraintWrapper(unsigned int m, double *g, unsigned int n, const double *x, double *dg, void *self)
等式制約条件のラッパー
unsigned int n_f
評価関数の計算回数
void ObjectiveFunctionGradient(double *df)
評価関数の和の勾配を計算する
int(* h)(double *, double *)
不等式制約条件
void EqualityConstraintCost(double *g)
等式制約条件
int(* g)(double *, double *)
等式制約条件
unsigned int iteration
最適化計算のイテレーション数
static void my_copy(double *in, double *out, int size)
unsigned int n_dh
不等式制約条件の勾配の計算回数
void EqualityConstraintGradient(double *dg)
等式制約条件の勾配
unsigned int n_dg
等式制約条件の勾配の計算回数
int f(double *x, double *ret)
unsigned int n_h
不等式制約条件の計算回数
unsigned int m_h
不等式制約条件の次元
NLoptSolver(double *x, const double *x_min, const double *x_max, int(*f)(double *, double *), int(*df)(double *, double *), int(*g)(double *, double *), int(*dg)(double *, double *), int(*h)(double *, double *), int(*dh)(double *, double *), int m_x, int m_g, int m_h, double ftol, double xtol, double eqthre, int max_eval, double max_time, Optimization::NLopt::Algorithm algorithm)
static double ObjectiveFunctionWrapper(unsigned int n, const double *x, double *df, void *self)
評価関数のラッパー
int(*)(*) dh(double *, double *)
int(*)(*) dg(double *, double *)
int df(double *x, double *grad)