Skip to content

Commit fb7d313

Browse files
committed
Make CEC2013 fully compliant with the oracle
1 parent 0232c6b commit fb7d313

File tree

4 files changed

+49
-50
lines changed

4 files changed

+49
-50
lines changed

include/cecxx/benchmark/cec_2013/basic_problems.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static constexpr auto basic_6
7575
{.rot = do_affine_trans::yes, .shift = do_affine_trans::yes},
7676
std::tuple{
7777
cecxx::benchmark::detail::shift{},
78-
cecxx::benchmark::detail::scale{2.048 / 100},
78+
cecxx::benchmark::detail::scale{2.048, 100},
7979
cecxx::benchmark::detail::rotation{},
8080
cecxx::benchmark::detail::shift_by_scalar{1},
8181
}
@@ -128,7 +128,7 @@ static constexpr auto basic_11 = detail::basic_problem_invoker{
128128
},
129129
std::tuple{
130130
cecxx::benchmark::detail::shift{},
131-
cecxx::benchmark::detail::scale{5.12 / 100.0},
131+
cecxx::benchmark::detail::scale{5.12, 100.0},
132132
cecxx::benchmark::detail::rotation{},
133133
cecxx::benchmark::detail::orthosymmetric_trans{},
134134
cecxx::benchmark::detail::asymmetric_trans<cecxx::benchmark::detail::scale>{0.2},
@@ -145,7 +145,7 @@ static constexpr auto basic_12 = detail::basic_problem_invoker{
145145
},
146146
std::tuple{
147147
cecxx::benchmark::detail::shift{},
148-
cecxx::benchmark::detail::scale{5.12 / 100.0},
148+
cecxx::benchmark::detail::scale{5.12, 100.0},
149149
cecxx::benchmark::detail::rotation{},
150150
cecxx::benchmark::detail::orthosymmetric_trans{},
151151
cecxx::benchmark::detail::asymmetric_trans<cecxx::benchmark::detail::rotation>{0.2},
@@ -159,7 +159,7 @@ static constexpr auto basic_13 = detail::basic_problem_invoker{
159159
{.rot = do_affine_trans::yes, .shift = do_affine_trans::yes},
160160
std::tuple{
161161
cecxx::benchmark::detail::shift{},
162-
cecxx::benchmark::detail::scale{5.12 / 100},
162+
cecxx::benchmark::detail::scale{5.12, 100},
163163
cecxx::benchmark::detail::rotation{},
164164
cecxx::benchmark::detail::power_scale3{},
165165
cecxx::benchmark::detail::orthosymmetric_trans{},
@@ -172,7 +172,7 @@ static constexpr auto basic_13 = detail::basic_problem_invoker{
172172
static constexpr auto basic_14 = detail::basic_problem_invoker{
173173
cecxx::functions::multimodal::schwefel,
174174
{.rot = do_affine_trans::no, .shift = do_affine_trans::yes},
175-
std::tuple{cecxx::benchmark::detail::shift{}, cecxx::benchmark::detail::scale{10},
175+
std::tuple{cecxx::benchmark::detail::shift{}, cecxx::benchmark::detail::scale{1000, 100},
176176
cecxx::benchmark::detail::rotation{}, cecxx::benchmark::detail::power_scale2{},
177177
cecxx::benchmark::detail::shift_by_scalar{4.209687462275036e+002}},
178178

@@ -181,7 +181,7 @@ static constexpr auto basic_14 = detail::basic_problem_invoker{
181181
static constexpr auto basic_15 = detail::basic_problem_invoker{
182182
cecxx::functions::multimodal::schwefel,
183183
{.rot = do_affine_trans::yes, .shift = do_affine_trans::yes},
184-
std::tuple{cecxx::benchmark::detail::shift{}, cecxx::benchmark::detail::scale{10},
184+
std::tuple{cecxx::benchmark::detail::shift{}, cecxx::benchmark::detail::scale{1000, 100},
185185
cecxx::benchmark::detail::rotation{}, cecxx::benchmark::detail::power_scale2{},
186186
cecxx::benchmark::detail::shift_by_scalar{4.209687462275036e+002}},
187187

@@ -192,7 +192,7 @@ static constexpr auto basic_16 = detail::basic_problem_invoker{
192192
{.rot = do_affine_trans::yes, .shift = do_affine_trans::yes},
193193
std::tuple{
194194
cecxx::benchmark::detail::shift{},
195-
cecxx::benchmark::detail::scale{0.05},
195+
cecxx::benchmark::detail::scale{5.0, 100.0},
196196
cecxx::benchmark::detail::rotation{},
197197
cecxx::benchmark::detail::power_scale2{10.0},
198198
cecxx::benchmark::detail::rotation{.do_stride = true},
@@ -217,7 +217,7 @@ static constexpr auto basic_19 = detail::basic_problem_invoker{
217217
{.rot = do_affine_trans::yes, .shift = do_affine_trans::yes},
218218
std::tuple{
219219
cecxx::benchmark::detail::shift{},
220-
cecxx::benchmark::detail::scale{0.05},
220+
cecxx::benchmark::detail::scale{5, 100},
221221
cecxx::benchmark::detail::rotation{},
222222
cecxx::benchmark::detail::shift_by_scalar<cecxx::benchmark::detail::scale>{1},
223223
},

include/cecxx/benchmark/cec_2013/complex_problems.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ const auto complex_1 = detail::complex_problem_invoker{std::tuple{basic_6, basic
1616
{.rot = do_affine_trans::no, .shift = do_affine_trans::yes},
1717
},
1818
.scales = {
19-
{0, 1.0},
20-
{1, 0.000001},
21-
{2, 10000.0 / 1e+30},
22-
{3, 0.000001},
23-
{4, 10000 / 1e+5},
19+
{0, {1.0, 1.0}},
20+
{1, {0.000001, 1.0}},
21+
{2, {10000.0, 1e+30}},
22+
{3, {0.000001, 1.0}},
23+
{4, {10000, 1e+5}},
2424
}}};
2525

2626
const auto complex_2 = detail::complex_problem_invoker{std::tuple{basic_15, basic_15, basic_15},
@@ -35,9 +35,9 @@ const auto complex_2 = detail::complex_problem_invoker{std::tuple{basic_15, basi
3535
do_affine_trans::yes},
3636
},
3737
.scales = {
38-
{0, 1.0},
39-
{1, 1.0},
40-
{2, 1.0},
38+
{0, {1.0, 1.0}},
39+
{1, {1.0, 1.0}},
40+
{2, {1.0, 1.0}},
4141
}}};
4242

4343
const auto complex_3 = detail::complex_problem_invoker{std::tuple{basic_15, basic_15, basic_15},
@@ -52,9 +52,9 @@ const auto complex_3 = detail::complex_problem_invoker{std::tuple{basic_15, basi
5252
do_affine_trans::yes},
5353
},
5454
.scales = {
55-
{0, 1.0},
56-
{1, 1.0},
57-
{2, 1.0},
55+
{0, {1.0, 1.0}},
56+
{1, {1.0, 1.0}},
57+
{2, {1.0, 1.0}},
5858
}}};
5959

6060
const auto complex_4 = detail::complex_problem_invoker{std::tuple{basic_15, basic_12, basic_9},
@@ -69,9 +69,9 @@ const auto complex_4 = detail::complex_problem_invoker{std::tuple{basic_15, basi
6969
do_affine_trans::yes},
7070
},
7171
.scales = {
72-
{0, 1000.0 / 4e+3},
73-
{1, 1000.0 / 1e+3},
74-
{2, 1000.0 / 400.0},
72+
{0, {1000.0 , 4e+3}},
73+
{1, {1000.0 , 1e+3}},
74+
{2, {1000.0 , 400.0}},
7575
}}};
7676

7777
const auto complex_5 = detail::complex_problem_invoker{std::tuple{basic_15, basic_12, basic_9},
@@ -86,9 +86,9 @@ const auto complex_5 = detail::complex_problem_invoker{std::tuple{basic_15, basi
8686
do_affine_trans::yes},
8787
},
8888
.scales = {
89-
{0, 1000 / 4e+3},
90-
{1, 1000 / 1e+3},
91-
{2, 1000.0 / 400.0},
89+
{0, {1000, 4e+3}},
90+
{1, {1000, 1e+3}},
91+
{2, {1000.0 , 400.0}},
9292
}}};
9393

9494
const auto complex_6 = detail::complex_problem_invoker{std::tuple{basic_15, basic_12, basic_2, basic_9, basic_10},
@@ -107,11 +107,11 @@ const auto complex_6 = detail::complex_problem_invoker{std::tuple{basic_15, basi
107107
do_affine_trans::yes},
108108
},
109109
.scales = {
110-
{0, 1000.0 / 4e+3},
111-
{1, 1000.0 / 1000.0},
112-
{2, 1000.0 / 1e+10},
113-
{3, 1000.0 / 400.0},
114-
{4, 10.0},
110+
{0, {1000.0 , 4e+3}},
111+
{1, {1000.0 , 1000.0}},
112+
{2, {1000.0 , 1e+10}},
113+
{3, {1000.0 , 400.0}},
114+
{4, {10.0, 1.0}},
115115
}}};
116116

117117
const auto complex_7 = detail::complex_problem_invoker{std::tuple{basic_10, basic_12, basic_15, basic_9, basic_1},
@@ -130,11 +130,11 @@ const auto complex_7 = detail::complex_problem_invoker{std::tuple{basic_10, basi
130130
do_affine_trans::yes},
131131
},
132132
.scales = {
133-
{0, 10000.0 / 100.0},
134-
{1, 10000.0 / 1e+3},
135-
{2, 10000.0 / 4e+3},
136-
{3, 10000.0 / 400.0},
137-
{4, 10000.0 / 1e+5},
133+
{0, {10000.0, 100.0}},
134+
{1, {10000.0, 1e+3}},
135+
{2, {10000.0, 4e+3}},
136+
{3, {10000.0, 400.0}},
137+
{4, {10000.0, 1e+5}},
138138
}}};
139139

140140
const auto complex_8 = detail::complex_problem_invoker{std::tuple{basic_19, basic_7, basic_15, basic_20, basic_1},
@@ -153,11 +153,11 @@ const auto complex_8 = detail::complex_problem_invoker{std::tuple{basic_19, basi
153153
do_affine_trans::yes},
154154
},
155155
.scales = {
156-
{0, 10000.0 / 4e+3},
157-
{1, 10000.0 / 4e+6},
158-
{2, 10000.0 / 4e+3},
159-
{3, 10000.0 / 2e+7},
160-
{4, 10000.0 / 1e+5},
156+
{0, {10000.0, 4e+3}},
157+
{1, {10000.0, 4e+6}},
158+
{2, {10000.0, 4e+3}},
159+
{3, {10000.0, 2e+7}},
160+
{4, {10000.0, 1e+5}},
161161
}}};
162162

163163
} // namespace cecxx::benchmark::cec_2013

include/cecxx/benchmark/detail/problem_invokers/basic_problem_invoker.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,16 @@ struct shift {
6262

6363
struct scale {
6464
static constexpr auto name{"scale"};
65-
constexpr scale(double coeff = 1.0) : coeff_{coeff} {}
65+
constexpr scale(double numerator = 1.0, double denominator = 1.0) : num_{numerator}, denom_{denominator} {}
6666

67-
auto operator()(std::span<double> input, problem_context_view_t ctx, affine_mask_t mask, partial_result_t partial)
68-
-> void {
69-
std::ignore = ctx;
70-
std::ignore = partial;
71-
std::ignore = mask;
67+
auto operator()(std::span<double> input, problem_context_view_t, affine_mask_t, partial_result_t) -> void {
7268
for (auto i = 0u; i < input.size(); i++) {
73-
input[i] = input[i] * coeff_;
69+
input[i] = input[i] * num_ / denom_;
7470
}
7571
}
7672

77-
double coeff_{};
73+
double num_{};
74+
double denom_{};
7875
};
7976

8077
struct orthosymmetric_trans {
@@ -233,6 +230,7 @@ struct basic_problem_invoker {
233230
std::optional<affine_mask_t> mask = {}) const -> double {
234231
const auto used_mask = mask.has_value() ? mask.value() : mask_;
235232
if constexpr (std::is_same_v<EvaluationFunction, contextless_eval_func>) {
233+
236234
return fn(apply_geom_fns(input, ctx, used_mask, trans_));
237235
} else if constexpr (std::is_same_v<EvaluationFunction, contextful_eval_func>) {
238236
return fn(input, ctx, used_mask);

include/cecxx/benchmark/detail/problem_invokers/complex_problem_invoker.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct complex_problem_params {
1010
std::vector<double> deltas{};
1111
std::vector<double> biases{};
1212
std::vector<affine_mask_t> masks{};
13-
std::unordered_map<std::size_t, double> scales{};
13+
std::unordered_map<std::size_t, std::pair<double, double>> scales{};
1414
};
1515

1616
template <typename... F>
@@ -44,7 +44,8 @@ class complex_problem_invoker {
4444
.shuffle = ctx.shuffle.subspan(nrow * CompoundIndex)};
4545
const auto mask = masks[CompoundIndex];
4646
auto comp_fn = std::get<CompoundIndex>(compounds);
47-
partial_eval[CompoundIndex] = params.scales.at(CompoundIndex) * comp_fn(input, sub_ctx, mask);
47+
const auto [num, denom] = params.scales.at(CompoundIndex);
48+
partial_eval[CompoundIndex] = num * comp_fn(input, sub_ctx, mask) / denom;
4849
}(CompoundIndex),
4950
...);
5051
return partial_eval;

0 commit comments

Comments
 (0)