Skip to content

Commit 09bc364

Browse files
authored
Merge pull request #2091 from numbbo/release
Bug fix of best_value computation on the constrained linear functions
2 parents ffd4fae + 46bea01 commit 09bc364

File tree

5 files changed

+393
-341
lines changed

5 files changed

+393
-341
lines changed

code-experiments/build/python/example_experiment2.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ def random_search(f, lbounds, ubounds, evals):
8686

8787
suite_name = "bbob" # see cocoex.known_suite_names
8888
budget_multiplier = 2 # times dimension, increase to 10, 100, ...
89-
suite_filter_options = ("" # without filtering a suite has instance_indices 1-15
89+
suite_filter_options = ("" # without filtering, a suite has instance_indices 1-15
9090
# "dimensions: 2,3,5,10,20 " # skip dimension 40
9191
# "instance_indices: 1-5 " # relative to suite instances
92-
# "year:2019 " # select instances by year
9392
)
9493
# for more suite filter options see http://numbbo.github.io/coco-doc/C/#suite-parameters
94+
suite_year_option = "" # "year: 2022" # determine instances by year, not all years work for all suites :-(
95+
9596
batches = 1 # number of batches, batch=3/32 works to set both, current_batch and batches
9697
current_batch = 1 # only current_batch modulo batches is relevant
9798
output_folder = ''
@@ -113,7 +114,7 @@ def random_search(f, lbounds, ubounds, evals):
113114
output_folder += "_batch%03dof%d" % (current_batch, batches)
114115

115116
### prepare
116-
suite = cocoex.Suite(suite_name, "", suite_filter_options)
117+
suite = cocoex.Suite(suite_name, suite_year_option, suite_filter_options)
117118
observer = cocoex.Observer(suite_name, "result_folder: " + output_folder)
118119
minimal_print = cocoex.utilities.MiniPrint()
119120
stoppings = defaultdict(list) # dict of lists, key is the problem index

code-experiments/build/python/python/solvers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ def random_search(fun, lbounds, ubounds, budget):
1616
# about five times faster than "for k in range(budget):..."
1717
X = lbounds + (ubounds - lbounds) * np.random.rand(chunk, dim)
1818
if fun.number_of_constraints > 0:
19-
C = [fun.constraint(x) for x in X] # call constraints
20-
F = [fun(x) for i, x in enumerate(X) if np.all(C[i] <= 0)]
19+
FC = [(fun(x), fun.constraint(x)) for x in X] # call objective and constraints
20+
F = [fc[0] for fc in FC if all(fc[1] <= 0)]
21+
budget -= chunk # one more to account for constraint evals
2122
else:
2223
F = [fun(x) for x in X]
2324
if fun.number_of_objectives == 1:

code-experiments/src/suite_cons_bbob_problems.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,12 @@ static coco_problem_t *f_linear_slope_c_linear_cons_bbob_problem_allocate(const
449449
*/
450450
for (i = 0; i < dimension; ++i)
451451
problem->best_parameter[i] = 0.0;
452+
453+
/* Apply a translation to the whole problem so that the constrained
454+
* minimum is no longer at the origin.
455+
*/
456+
problem = transform_vars_shift(problem, xopt, 1);
457+
452458
assert(problem->evaluate_function != NULL);
453459
problem->evaluate_function(problem, problem->best_parameter, problem->best_value);
454460

@@ -457,12 +463,7 @@ static coco_problem_t *f_linear_slope_c_linear_cons_bbob_problem_allocate(const
457463
*/
458464
problem->evaluations = 0;
459465
problem->evaluations_constraints = 0;
460-
461-
/* Apply a translation to the whole problem so that the constrained
462-
* minimum is no longer at the origin.
463-
*/
464-
problem = transform_vars_shift(problem, xopt, 1);
465-
466+
466467
/* Construct problem type */
467468
coco_problem_set_type(problem, "%s_%s", problem_type_temp,
468469
problem_c->problem_type);

code-experiments/src/transform_vars_shift.c

+3
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ static void transform_vars_shift_free(void *thing) {
107107

108108
/**
109109
* @brief Creates the transformation.
110+
*
111+
* CAVEAT: when shifting the constraint only, the best_value of best_parameter
112+
* will get in an inconsistent state.
110113
*/
111114
static coco_problem_t *transform_vars_shift(coco_problem_t *inner_problem,
112115
const double *offset,

0 commit comments

Comments
 (0)