nlopt_algorithm nonderiv = (nlopt_algorithm) *inonderiv;
nlopt_set_local_search_algorithm(deriv, nonderiv, *maxeval);
}
+
+void F77(nlogsp,NLOGSP)(int *pop)
+{
+ *pop = nlopt_get_stochastic_population();
+}
+void F77(nlossp,NLOSSP)(const int *pop)
+{
+ nlopt_set_stochastic_population(*pop);
+}
/*************************************************************************/
+/* For stochastic algorithms, there is often an initial "population"
+ size to seed the search. Like above, we let the user
+ call nlopt_{set/get}_stochastic_population in order to get/set the
+ defaults. The special stochastic population size of "0" means
+ that the optimization algorithm should pick its default population. */
+
+static int stochastic_population = 0;
+
+int nlopt_get_stochastic_population(void) { return stochastic_population; }
+void nlopt_set_stochastic_population(int pop) { stochastic_population = pop; }
+
+/*************************************************************************/
+
/* same as nlopt_minimize_econstrained,
but xtol_abs is required to be non-NULL */
static nlopt_result nlopt_minimize_(
1 + (algorithm - NLOPT_LD_TNEWTON) / 2);
case NLOPT_GN_CRS2_LM:
- return crs_minimize(n, f, f_data, lb, ub, x, minf, &stop, 0);
+ return crs_minimize(n, f, f_data, lb, ub, x, minf, &stop,
+ stochastic_population, 0);
case NLOPT_GN_MLSL:
case NLOPT_GD_MLSL:
? local_search_alg_nonderiv
: local_search_alg_deriv,
local_search_maxeval,
+ stochastic_population,
algorithm >= NLOPT_GN_MLSL_LDS);
case NLOPT_LD_MMA:
m, fc, fc_data, fc_datum_size,
p, h, h_data, h_datum_size,
lb, ub, x, minf, &stop,
- 0);
+ stochastic_population);
default:
return NLOPT_INVALID_ARGS;
nlopt_algorithm nonderiv,
int maxeval);
+NLOPT_EXTERN int nlopt_get_stochastic_population(void);
+NLOPT_EXTERN void nlopt_set_stochastic_population(int pop);
+
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
static nlopt_result crs_init(crs_data *d, int n, const double *x,
const double *lb, const double *ub,
nlopt_stopping *stop, nlopt_func f, void *f_data,
- int lds)
+ int population, int lds)
{
int i;
- /* TODO: how should we set the initial population size?
- the Kaelo and Ali paper suggests 10*(n+1), but should
- we add more random points if maxeval is large, or... ? */
- d->N = 10 * (n + 1); /* heuristic initial population size */
+ if (!population) {
+ /* TODO: how should we set the default population size?
+ the Kaelo and Ali paper suggests 10*(n+1), but should
+ we add more random points if maxeval is large, or... ? */
+ d->N = 10 * (n + 1); /* heuristic initial population size */
+ }
+ else
+ d->N = population;
+ if (d->N < n + 1) /* population must be big enough for a simplex */
+ return NLOPT_INVALID_ARGS;
d->n = n;
d->stop = stop;
double *x, /* in: initial guess, out: minimizer */
double *minf,
nlopt_stopping *stop,
+ int population, /* initial population (0=default) */
int lds) /* random or low-discrepancy seq. (lds) */
{
nlopt_result ret;
crs_data d;
rb_node *best;
- ret = crs_init(&d, n, x, lb, ub, stop, f, f_data, lds);
+ ret = crs_init(&d, n, x, lb, ub, stop, f, f_data, population, lds);
if (ret < 0) return ret;
best = rb_tree_min(&d.t);
double *x, /* in: initial guess, out: minimizer */
double *minf,
nlopt_stopping *stop,
+ int population, /* initial population (0=default) */
int random); /* random or low-discrepancy seq. */
#ifdef __cplusplus
nlopt_stopping *stop,
nlopt_algorithm local_alg,
int local_maxeval,
+ int Nsamples, /* #samples/iteration (0=default) */
int lds) /* random or low-discrepancy seq. (lds) */
{
nlopt_result ret = NLOPT_SUCCESS;
int i;
pt *p;
+ if (!Nsamples)
+ d.N = 4; /* FIXME: what is good number of samples per iteration? */
+ else
+ d.N = Nsamples;
+ if (d.N < 1) return NLOPT_INVALID_ARGS;
+
d.n = n;
d.lb = lb; d.ub = ub;
d.stop = stop;
d.local_alg = local_alg; d.local_maxeval = local_maxeval;
d.gamma = MLSL_GAMMA;
- d.N = 4; /* FIXME: what is good number of samples per iteration? */
d.R_prefactor = sqrt(2./K2PI) * pow(gam(n) * MLSL_SIGMA, 1.0/n);
for (i = 0; i < n; ++i)
if (!p) { ret = NLOPT_OUT_OF_MEMORY; goto done; }
/* FIXME: how many sobol points to skip, if any? */
- nlopt_sobol_skip(d.s, (unsigned) (10*n+1), p->x);
+ nlopt_sobol_skip(d.s, (unsigned) (10*n+d.N), p->x);
memcpy(p->x, x, n * sizeof(double));
p->f = f(n, x, NULL, f_data);
nlopt_stopping *stop,
nlopt_algorithm local_alg,
int local_maxeval,
+ int Nsamples, /* #samples/iteration (0=default) */
int lds);
#ifdef __cplusplus