Skip to content

Commit

Permalink
Merge pull request #2091 from numbbo/release
Browse files Browse the repository at this point in the history
Bug fix of best_value computation on the constrained linear functions
  • Loading branch information
nikohansen committed Mar 22, 2022
2 parents ffd4fae + 46bea01 commit 09bc364
Show file tree
Hide file tree
Showing 5 changed files with 393 additions and 341 deletions.
7 changes: 4 additions & 3 deletions code-experiments/build/python/example_experiment2.py
Expand Up @@ -86,12 +86,13 @@ def random_search(f, lbounds, ubounds, evals):

suite_name = "bbob" # see cocoex.known_suite_names
budget_multiplier = 2 # times dimension, increase to 10, 100, ...
suite_filter_options = ("" # without filtering a suite has instance_indices 1-15
suite_filter_options = ("" # without filtering, a suite has instance_indices 1-15
# "dimensions: 2,3,5,10,20 " # skip dimension 40
# "instance_indices: 1-5 " # relative to suite instances
# "year:2019 " # select instances by year
)
# for more suite filter options see http://numbbo.github.io/coco-doc/C/#suite-parameters
suite_year_option = "" # "year: 2022" # determine instances by year, not all years work for all suites :-(

batches = 1 # number of batches, batch=3/32 works to set both, current_batch and batches
current_batch = 1 # only current_batch modulo batches is relevant
output_folder = ''
Expand All @@ -113,7 +114,7 @@ def random_search(f, lbounds, ubounds, evals):
output_folder += "_batch%03dof%d" % (current_batch, batches)

### prepare
suite = cocoex.Suite(suite_name, "", suite_filter_options)
suite = cocoex.Suite(suite_name, suite_year_option, suite_filter_options)
observer = cocoex.Observer(suite_name, "result_folder: " + output_folder)
minimal_print = cocoex.utilities.MiniPrint()
stoppings = defaultdict(list) # dict of lists, key is the problem index
Expand Down
5 changes: 3 additions & 2 deletions code-experiments/build/python/python/solvers.py
Expand Up @@ -16,8 +16,9 @@ def random_search(fun, lbounds, ubounds, budget):
# about five times faster than "for k in range(budget):..."
X = lbounds + (ubounds - lbounds) * np.random.rand(chunk, dim)
if fun.number_of_constraints > 0:
C = [fun.constraint(x) for x in X] # call constraints
F = [fun(x) for i, x in enumerate(X) if np.all(C[i] <= 0)]
FC = [(fun(x), fun.constraint(x)) for x in X] # call objective and constraints
F = [fc[0] for fc in FC if all(fc[1] <= 0)]
budget -= chunk # one more to account for constraint evals
else:
F = [fun(x) for x in X]
if fun.number_of_objectives == 1:
Expand Down
13 changes: 7 additions & 6 deletions code-experiments/src/suite_cons_bbob_problems.c
Expand Up @@ -449,6 +449,12 @@ static coco_problem_t *f_linear_slope_c_linear_cons_bbob_problem_allocate(const
*/
for (i = 0; i < dimension; ++i)
problem->best_parameter[i] = 0.0;

/* Apply a translation to the whole problem so that the constrained
* minimum is no longer at the origin.
*/
problem = transform_vars_shift(problem, xopt, 1);

assert(problem->evaluate_function != NULL);
problem->evaluate_function(problem, problem->best_parameter, problem->best_value);

Expand All @@ -457,12 +463,7 @@ static coco_problem_t *f_linear_slope_c_linear_cons_bbob_problem_allocate(const
*/
problem->evaluations = 0;
problem->evaluations_constraints = 0;

/* Apply a translation to the whole problem so that the constrained
* minimum is no longer at the origin.
*/
problem = transform_vars_shift(problem, xopt, 1);


/* Construct problem type */
coco_problem_set_type(problem, "%s_%s", problem_type_temp,
problem_c->problem_type);
Expand Down
3 changes: 3 additions & 0 deletions code-experiments/src/transform_vars_shift.c
Expand Up @@ -107,6 +107,9 @@ static void transform_vars_shift_free(void *thing) {

/**
* @brief Creates the transformation.
*
* CAVEAT: when shifting the constraint only, the best_value of best_parameter
* will get in an inconsistent state.
*/
static coco_problem_t *transform_vars_shift(coco_problem_t *inner_problem,
const double *offset,
Expand Down

0 comments on commit 09bc364

Please sign in to comment.