-
Notifications
You must be signed in to change notification settings - Fork 84
/
suite_cons_bbob.c
210 lines (169 loc) · 9.06 KB
/
suite_cons_bbob.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/**
* @file suite_cons_bbob.c
* @brief Implementation of the constrained bbob suite containing
* 54 constrained problems in 6 dimensions. See comments in
* "suite_cons_bbob_problems.c" for more details.
*/
#include "coco.h"
#include "suite_cons_bbob_problems.c"
#include "transform_obj_scale.c"
static coco_suite_t *coco_suite_allocate(const char *suite_name,
const size_t number_of_functions,
const size_t number_of_dimensions,
const size_t *dimensions,
const char *default_instances,
const int known_optima);
/**
* @brief Sets the dimensions and default instances for the bbob suite.
*/
static coco_suite_t *suite_cons_bbob_initialize(const char *suite_name) {
coco_suite_t *suite;
const size_t dimensions[] = { 2, 3, 5, 10, 20, 40 };
const size_t num_dimensions = sizeof(dimensions) / sizeof(dimensions[0]);
/* IMPORTANT: Make sure to change the default instance for every new workshop! */
suite = coco_suite_allocate(suite_name, 54, num_dimensions, dimensions, "year: 2022", 1);
return suite;
}
/**
* @brief Sets the instances associated with years for the constrained
* bbob suite.
*/
static const char *suite_cons_bbob_get_instances_by_year(const int year) {
if ((year >= 2022) || (year == 0)) {
return "1-15";
}
else if ((year >= 2009)) {
return "1-15";
}
else {
coco_error("suite_cons_bbob_get_instances_by_year(): year %d not defined for suite_cons_bbob", year);
return NULL;
}
}
/**
* @brief Creates and returns a constrained BBOB problem.
*/
static coco_problem_t *coco_get_cons_bbob_problem(const char *suite_name,
const size_t function,
const size_t dimension,
const size_t instance) {
size_t number_of_linear_constraints;
coco_problem_t *problem = NULL;
double *feasible_direction = coco_allocate_vector(dimension);
double *xopt = coco_allocate_vector(dimension);
long rseed = (long) (function + 10000 * instance);
const char *problem_id_template = "bbob-constrained_f%03lu_i%02lu_d%02lu";
const char *problem_name_template = "bbob-constrained suite problem f%lu instance %lu in %luD";
if (strcmp(suite_name, "bbob-constrained-active-only") == 0) {
/* CAVEAT: the first 28 chars of this ID are used in c_linear_cons_bbob_problem_allocate()
* in c_linear.c to make the decision whether inactive constraints are added */
problem_id_template = "bbob-constrained-active-only_f%03lu_i%02lu_d%02lu";
problem_name_template = "bbob-constrained-active-only suite problem f%lu instance %lu in %luD";
}
if (strcmp(suite_name, "bbob-constrained-no-disguise") == 0) {
/* First trick as above, by chance same number of characters
* Both options at the same time not supported */
problem_id_template = "bbob-constrained-no-disguise_f%03lu_i%02lu_d%02lu";
problem_name_template = "bbob-constrained-no-disguise suite problem f%lu instance %lu in %luD";
}
/* Seed value used for shifting the whole constrained problem */
bbob2009_compute_xopt(xopt, rseed, dimension);
/* Choose a different seed value for building the objective function */
rseed = (long) (function + 20000 * instance);
number_of_linear_constraints = nb_of_linear_constraints(function, dimension);
if (obj_function_type(function) == 1) {
problem = f_sphere_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 10.); /* move initial feasible point to a delta-f between 100 and 10000 */
} else if (obj_function_type(function) == 2) {
problem = f_ellipsoid_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 1e-4); /* move initial feasible point to a delta-f between 100 and 10000 */
} else if (obj_function_type(function) == 3) {
problem = f_linear_slope_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 10.); /* move initial feasible point to a delta-f between 100 and 10000 */
} else if (obj_function_type(function) == 4) {
problem = f_ellipsoid_rotated_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 1e-4); /* move initial feasible point to a delta-f between 100 and 10000 */
} else if (obj_function_type(function) == 5) {
problem = f_discus_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 1e-4); /* move initial feasible point to a delta-f between 100 and 10000 */
} else if (obj_function_type(function) == 6) {
problem = f_bent_cigar_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 1e-4); /* move initial feasible point to a delta-f between 100 and 100,000 */
} else if (obj_function_type(function) == 7) {
problem = f_different_powers_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 1e2); /* move initial feasible point to a delta-f between 100 and 1000 */
} else if (obj_function_type(function) == 8) {
problem = f_rastrigin_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 10.); /* move initial feasible point to a delta-f between 100 and 10000 */
} else if (obj_function_type(function) == 9) {
problem = f_rastrigin_rotated_c_linear_cons_bbob_problem_allocate(function,
dimension, instance, number_of_linear_constraints, rseed,
feasible_direction, xopt, problem_id_template,
problem_name_template);
problem = transform_obj_scale(problem, 10.); /* move initial feasible point to a delta-f between 100 and 10000 */
} else {
coco_free_memory(xopt);
coco_free_memory(feasible_direction);
coco_error("get_cons_bbob_problem(): cannot retrieve problem f%lu instance %lu in %luD",
function, instance, dimension);
return NULL; /* Never reached */
}
coco_free_memory(xopt);
coco_free_memory(feasible_direction);
return problem;
}
/**
* @brief Returns the problem from the constrained bbob suite that
* corresponds to the given parameters.
*
* @param suite The COCO suite.
* @param function_idx Index of the function (starting from 0).
* @param dimension_idx Index of the dimension (starting from 0).
* @param instance_idx Index of the instance (starting from 0).
* @return The problem that corresponds to the given parameters.
*/
static coco_problem_t *suite_cons_bbob_get_problem(coco_suite_t *suite,
const size_t function_idx,
const size_t dimension_idx,
const size_t instance_idx) {
coco_problem_t *problem = NULL;
const size_t function = suite->functions[function_idx];
const size_t dimension = suite->dimensions[dimension_idx];
const size_t instance = suite->instances[instance_idx];
problem = coco_get_cons_bbob_problem(suite->suite_name, function, dimension, instance);
problem->suite_dep_function = function;
problem->suite_dep_instance = instance;
problem->suite_dep_index = coco_suite_encode_problem_index(suite, function_idx, dimension_idx, instance_idx);
/* Use the standard stacked problem_id as problem_name and
* construct a new suite-specific problem_id
*/
coco_problem_set_id(problem, "%s_f%03lu_i%02lu_d%02lu",
suite->suite_name, (unsigned long)function, (unsigned long)instance, (unsigned long)dimension);
coco_problem_set_name(problem, "%s suite problem f%lu instance %lu in %luD",
suite->suite_name, (unsigned long)function, (unsigned long)instance, (unsigned long)dimension);
return problem;
}