+/* Copyright (c) 2007-2014 Massachusetts Institute of Technology
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
#include <stdlib.h>
#include <string.h>
do {
d->p[0] = d->f(n, d->p + 1, NULL, d->f_data);
d->stop->nevals++;
+ if (nlopt_stop_forced(d->stop)) return NLOPT_FORCED_STOP;
if (d->p[0] < worst->k[0]) break;
if (nlopt_stop_evals(d->stop)) return NLOPT_MAXEVAL_REACHED;
if (nlopt_stop_time(d->stop)) return NLOPT_MAXTIME_REACHED;
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 */
+ nlopt_stop_msg(stop, "population %d should be >= dimension + 1 = %d",
+ d->N, n+1);
+ 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);