Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix of best_value computation on the constrained linear functions #2091

Merged
merged 6 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions code-experiments/build/python/example_experiment2.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading