本文整理汇总了C++中nlopt_opt类的典型用法代码示例。如果您正苦于以下问题:C++ nlopt_opt类的具体用法?C++ nlopt_opt怎么用?C++ nlopt_opt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了nlopt_opt类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: nlopt_add_inequality_mconstraint
nlopt_result
NLOPT_STDCALL nlopt_add_inequality_mconstraint(nlopt_opt opt, unsigned m,
nlopt_mfunc fc, void *fc_data,
const double *tol)
{
nlopt_result ret;
if (!m) { /* empty constraints are always ok */
if (opt && opt->munge_on_destroy) opt->munge_on_destroy(fc_data);
return NLOPT_SUCCESS;
}
if (!opt || !inequality_ok(opt->algorithm)) ret = NLOPT_INVALID_ARGS;
else ret = add_constraint(&opt->m, &opt->m_alloc, &opt->fc,
m, NULL, fc, NULL, fc_data, tol);
if (ret < 0 && opt && opt->munge_on_destroy)
opt->munge_on_destroy(fc_data);
return ret;
}
开发者ID:fw1121,项目名称:Pandoras-Toolbox-for-Bioinformatics,代码行数:17,代码来源:options.c
示例2: nlopt_add_inequality_constraint
nlopt_result
NLOPT_STDCALL nlopt_add_inequality_constraint(nlopt_opt opt,
nlopt_func fc, void *fc_data,
double tol)
{
nlopt_result ret;
if (!opt || !inequality_ok(opt->algorithm)) ret = NLOPT_INVALID_ARGS;
else ret = add_constraint(&opt->m, &opt->m_alloc, &opt->fc,
1, fc, NULL, fc_data, &tol);
if (ret < 0 && opt && opt->munge_on_destroy)
opt->munge_on_destroy(fc_data);
return ret;
}
开发者ID:NoviaDroid,项目名称:MarioDifficulty,代码行数:13,代码来源:options.c
示例3: nlopt_set_max_objective
nlopt_result NLOPT_STDCALL nlopt_set_max_objective(nlopt_opt opt,
nlopt_func f, void *f_data)
{
if (opt) {
if (opt->munge_on_destroy) opt->munge_on_destroy(opt->f_data);
opt->f = f; opt->f_data = f_data;
opt->maximize = 1;
if (nlopt_isinf(opt->stopval) && opt->stopval < 0)
opt->stopval = +HUGE_VAL; /* switch default from min to max */
return NLOPT_SUCCESS;
}
return NLOPT_INVALID_ARGS;
}
开发者ID:NoviaDroid,项目名称:MarioDifficulty,代码行数:13,代码来源:options.c
示例4: nlopt_set_precond_min_objective
nlopt_result NLOPT_STDCALL nlopt_set_precond_min_objective(nlopt_opt opt,
nlopt_func f,
nlopt_precond pre,
void *f_data)
{
if (opt) {
if (opt->munge_on_destroy) opt->munge_on_destroy(opt->f_data);
opt->f = f; opt->f_data = f_data; opt->pre = pre;
opt->maximize = 0;
if (nlopt_isinf(opt->stopval) && opt->stopval > 0)
opt->stopval = -HUGE_VAL; /* switch default from max to min */
return NLOPT_SUCCESS;
}
return NLOPT_INVALID_ARGS;
}
开发者ID:fw1121,项目名称:Pandoras-Toolbox-for-Bioinformatics,代码行数:15,代码来源:options.c
示例5: nlopt_add_precond_equality_constraint
nlopt_result
NLOPT_STDCALL nlopt_add_precond_equality_constraint(nlopt_opt opt,
nlopt_func fc,
nlopt_precond pre,
void *fc_data,
double tol)
{
nlopt_result ret;
if (!opt || !equality_ok(opt->algorithm)
|| nlopt_count_constraints(opt->p, opt->h) + 1 > opt->n)
ret = NLOPT_INVALID_ARGS;
else ret = add_constraint(&opt->p, &opt->p_alloc, &opt->h,
1, fc, NULL, pre, fc_data, &tol);
if (ret < 0 && opt && opt->munge_on_destroy)
opt->munge_on_destroy(fc_data);
return ret;
}
开发者ID:fw1121,项目名称:Pandoras-Toolbox-for-Bioinformatics,代码行数:17,代码来源:options.c
示例6: nlopt_optimize_
/* unlike nlopt_optimize() below, only handles minimization case */
static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf)
{
const double *lb, *ub;
nlopt_algorithm algorithm;
nlopt_func f; void *f_data;
unsigned n, i;
int ni;
nlopt_stopping stop;
if (!opt || !x || !minf || !opt->f
|| opt->maximize) return NLOPT_INVALID_ARGS;
/* reset stopping flag */
nlopt_set_force_stop(opt, 0);
opt->force_stop_child = NULL;
/* copy a few params to local vars for convenience */
n = opt->n;
ni = (int) n; /* most of the subroutines take "int" arg */
lb = opt->lb; ub = opt->ub;
algorithm = opt->algorithm;
f = opt->f; f_data = opt->f_data;
if (n == 0) { /* trivial case: no degrees of freedom */
*minf = opt->f(n, x, NULL, opt->f_data);
return NLOPT_SUCCESS;
}
*minf = HUGE_VAL;
/* make sure rand generator is inited */
nlopt_srand_time_default(); /* default is non-deterministic */
/* check bound constraints */
for (i = 0; i < n; ++i)
if (lb[i] > ub[i] || x[i] < lb[i] || x[i] > ub[i])
return NLOPT_INVALID_ARGS;
stop.n = n;
stop.minf_max = opt->stopval;
stop.ftol_rel = opt->ftol_rel;
stop.ftol_abs = opt->ftol_abs;
stop.xtol_rel = opt->xtol_rel;
stop.xtol_abs = opt->xtol_abs;
stop.nevals = 0;
stop.maxeval = opt->maxeval;
stop.maxtime = opt->maxtime;
stop.start = nlopt_seconds();
stop.force_stop = &(opt->force_stop);
switch (algorithm) {
case NLOPT_GN_DIRECT:
case NLOPT_GN_DIRECT_L:
case NLOPT_GN_DIRECT_L_RAND:
if (!finite_domain(n, lb, ub)) return NLOPT_INVALID_ARGS;
return cdirect(ni, f, f_data,
lb, ub, x, minf, &stop, 0.0,
(algorithm != NLOPT_GN_DIRECT)
+ 3 * (algorithm == NLOPT_GN_DIRECT_L_RAND
? 2 : (algorithm != NLOPT_GN_DIRECT))
+ 9 * (algorithm == NLOPT_GN_DIRECT_L_RAND
? 1 : (algorithm != NLOPT_GN_DIRECT)));
case NLOPT_GN_DIRECT_NOSCAL:
case NLOPT_GN_DIRECT_L_NOSCAL:
case NLOPT_GN_DIRECT_L_RAND_NOSCAL:
if (!finite_domain(n, lb, ub)) return NLOPT_INVALID_ARGS;
return cdirect_unscaled(ni, f, f_data, lb, ub, x, minf,
&stop, 0.0,
(algorithm != NLOPT_GN_DIRECT)
+ 3 * (algorithm == NLOPT_GN_DIRECT_L_RAND ? 2 : (algorithm != NLOPT_GN_DIRECT))
+ 9 * (algorithm == NLOPT_GN_DIRECT_L_RAND ? 1 : (algorithm != NLOPT_GN_DIRECT)));
case NLOPT_GN_ORIG_DIRECT:
case NLOPT_GN_ORIG_DIRECT_L: {
direct_return_code dret;
if (!finite_domain(n, lb, ub)) return NLOPT_INVALID_ARGS;
opt->work = malloc(sizeof(double) *
nlopt_max_constraint_dim(opt->m,
opt->fc));
if (!opt->work) return NLOPT_OUT_OF_MEMORY;
dret = direct_optimize(f_direct, opt, ni, lb, ub, x, minf,
stop.maxeval, -1,
stop.start, stop.maxtime,
0.0, 0.0,
pow(stop.xtol_rel, (double) n), -1.0,
stop.force_stop,
stop.minf_max, 0.0,
NULL,
algorithm == NLOPT_GN_ORIG_DIRECT
? DIRECT_ORIGINAL
: DIRECT_GABLONSKY);
free(opt->work); opt->work = NULL;
switch (dret) {
case DIRECT_INVALID_BOUNDS:
case DIRECT_MAXFEVAL_TOOBIG:
case DIRECT_INVALID_ARGS:
return NLOPT_INVALID_ARGS;
case DIRECT_INIT_FAILED:
//.........这里部分代码省略.........
开发者ID:tusharuiit,项目名称:2014-2015_HiwiMedicalXTTVisualization,代码行数:101,代码来源:optimize.c
示例7: nlopt_optimize_
/* unlike nlopt_optimize() below, only handles minimization case */
static nlopt_result nlopt_optimize_(nlopt_opt opt, double *x, double *minf)
{
const double *lb, *ub;
nlopt_algorithm algorithm;
nlopt_func f; void *f_data;
unsigned n, i;
int ni;
nlopt_stopping stop;
if (!opt || !x || !minf || !opt->f
|| opt->maximize) RETURN_ERR(NLOPT_INVALID_ARGS, opt,
"NULL args to nlopt_optimize_");
/* reset stopping flag */
nlopt_set_force_stop(opt, 0);
opt->force_stop_child = NULL;
/* copy a few params to local vars for convenience */
n = opt->n;
ni = (int) n; /* most of the subroutines take "int" arg */
lb = opt->lb; ub = opt->ub;
algorithm = opt->algorithm;
f = opt->f; f_data = opt->f_data;
if (n == 0) { /* trivial case: no degrees of freedom */
*minf = opt->f(n, x, NULL, opt->f_data);
return NLOPT_SUCCESS;
}
*minf = HUGE_VAL;
/* check bound constraints */
for (i = 0; i < n; ++i)
if (lb[i] > ub[i] || x[i] < lb[i] || x[i] > ub[i]) {
nlopt_set_errmsg(opt, "bounds %d fail %g <= %g <= %g",
i, lb[i], x[i], ub[i]);
return NLOPT_INVALID_ARGS;
}
stop.n = n;
stop.minf_max = opt->stopval;
stop.ftol_rel = opt->ftol_rel;
stop.ftol_abs = opt->ftol_abs;
stop.xtol_rel = opt->xtol_rel;
stop.xtol_abs = opt->xtol_abs;
stop.nevals = 0;
stop.maxeval = opt->maxeval;
stop.maxtime = opt->maxtime;
stop.force_stop = &(opt->force_stop);
stop.stop_msg = &(opt->errmsg);
switch (algorithm) {
case NLOPT_LD_SLSQP:
return nlopt_slsqp(n, f, f_data,
opt->m, opt->fc,
opt->p, opt->h,
lb, ub, x, minf, &stop);
default:
return NLOPT_INVALID_ARGS;
}
return NLOPT_SUCCESS; /* never reached */
}
开发者ID:falkcarl,项目名称:OpenMx,代码行数:65,代码来源:optimize.c
注:本文中的nlopt_opt类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论