Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ewarchul committed Jun 29, 2024
1 parent ce49dcf commit 449af0f
Show file tree
Hide file tree
Showing 46 changed files with 408 additions and 277 deletions.
5 changes: 3 additions & 2 deletions include/cecxx/benchmark/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ concept numeric = std::integral<T> or std::floating_point<T>;

// this shall be replaced with mdspan from c++23
template <class R, class T>
concept matrix = std::convertible_to<std::ranges::range_reference_t<std::ranges::range_reference_t<R>>, T>;
} // namespace cecxx
concept matrix = std::convertible_to<
std::ranges::range_reference_t<std::ranges::range_reference_t<R>>, T>;
} // namespace cecxx::benchmark
12 changes: 7 additions & 5 deletions include/cecxx/benchmark/detail/cec2017/consts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

namespace cecxx::benchmark::detail::cec2017 {
const auto CEC2017_OFFSET = std::unordered_map<detail::fn_num, f64>{
{1, 100.0}, {2, 200.0}, {3, 300.0}, {4, 400.0}, {5, 500.0}, {6, 600.0}, {7, 700.0}, {8, 800.0},
{9, 900.0}, {10, 1000.0}, {11, 1100.0}, {12, 1200.0}, {13, 1300.0}, {14, 1400.0}, {15, 1500.0}, {16, 1600.0},
{17, 1700.0}, {18, 1800.0}, {19, 1900.0}, {20, 2000.0}, {21, 2100.0}, {22, 2200.0}, {23, 2300.0}, {24, 2400.0},
{25, 2500.0}, {26, 2600.0}, {27, 2700.0}, {28, 2800.0}, {29, 2900.0}, {30, 3000.0},
{1, 100.0}, {2, 200.0}, {3, 300.0}, {4, 400.0}, {5, 500.0},
{6, 600.0}, {7, 700.0}, {8, 800.0}, {9, 900.0}, {10, 1000.0},
{11, 1100.0}, {12, 1200.0}, {13, 1300.0}, {14, 1400.0}, {15, 1500.0},
{16, 1600.0}, {17, 1700.0}, {18, 1800.0}, {19, 1900.0}, {20, 2000.0},
{21, 2100.0}, {22, 2200.0}, {23, 2300.0}, {24, 2400.0}, {25, 2500.0},
{26, 2600.0}, {27, 2700.0}, {28, 2800.0}, {29, 2900.0}, {30, 3000.0},
};

const auto VALID_DIMENSIONS = std::set{10, 30, 50, 100};

} // namespace cecxx::benchmark::detail::cec2017
} // namespace cecxx::benchmark::detail::cec2017
10 changes: 6 additions & 4 deletions include/cecxx/benchmark/detail/cec2017/evaluate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

namespace cecxx::benchmark::detail::cec2017 {

auto dispatch_problem(problem_context_view ctx, const u8 fn, const auto& input) {
auto dispatch_problem(problem_context_view ctx, const u8 fn,
const auto &input) {
switch (fn) {
case 1:
return bent_cigar(input, ctx);
Expand Down Expand Up @@ -75,7 +76,7 @@ auto dispatch_problem(problem_context_view ctx, const u8 fn, const auto& input)
throw std::runtime_error{"Unknown CEC problem"};
}

auto evaluate(problem_context_view ctx, const u8 fn_num, const auto& input) {
auto evaluate(problem_context_view ctx, const u8 fn_num, const auto &input) {
const auto ncol = input.size();
const auto nrow = input.at(0).size();
if (not cec2017::VALID_DIMENSIONS.contains(nrow)) {
Expand All @@ -84,10 +85,11 @@ auto evaluate(problem_context_view ctx, const u8 fn_num, const auto& input) {

auto output = std::vector<f64>(ncol);
for (auto col{0u}; col < output.size(); ++col) {
output[col] = dispatch_problem(ctx, fn_num, input.at(col)) + cec2017::CEC2017_OFFSET.at(fn_num);
output[col] = dispatch_problem(ctx, fn_num, input.at(col)) +
cec2017::CEC2017_OFFSET.at(fn_num);
}

return output;
}

} // namespace cecxx::benchmark::detail::cec2017
} // namespace cecxx::benchmark::detail::cec2017
59 changes: 39 additions & 20 deletions include/cecxx/benchmark/detail/cec2017/problems/basic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,43 @@
#include "cecxx/functions/unimodal/sum_diff_pow.hpp"

namespace cecxx::benchmark::detail::cec2017 {
static constexpr auto sum_diff_pow = basic_problem{cecxx::functions::unimodal::sum_diff_pow};
static constexpr auto bent_cigar = basic_problem{cecxx::functions::unimodal::bent_cigar};
static constexpr auto ellips = basic_problem{cecxx::functions::unimodal::ellips};
static constexpr auto discus = basic_problem{cecxx::functions::multimodal::discus};
static constexpr auto zakharov = basic_problem{cecxx::functions::multimodal::zakharov};
static constexpr auto rosenbrock = basic_problem{cecxx::functions::multimodal::rosenbrock, 2.048 / 100.0};
static constexpr auto rastrigin = basic_problem{cecxx::functions::multimodal::rastrigin, 5.12 / 100.0};
static constexpr auto schaffer = basic_problem{cecxx::functions::multimodal::legacy::schaffer};
static constexpr auto bi_rastrigin = basic_problem{cecxx::functions::multimodal::legacy::bi_rastrigin};
static constexpr auto step_rastrigin = basic_problem{cecxx::functions::multimodal::step_rastrigin, 5.12 / 100.0};
static constexpr auto sum_diff_pow =
basic_problem{cecxx::functions::unimodal::sum_diff_pow};
static constexpr auto bent_cigar =
basic_problem{cecxx::functions::unimodal::bent_cigar};
static constexpr auto ellips =
basic_problem{cecxx::functions::unimodal::ellips};
static constexpr auto discus =
basic_problem{cecxx::functions::multimodal::discus};
static constexpr auto zakharov =
basic_problem{cecxx::functions::multimodal::zakharov};
static constexpr auto rosenbrock =
basic_problem{cecxx::functions::multimodal::rosenbrock, 2.048 / 100.0};
static constexpr auto rastrigin =
basic_problem{cecxx::functions::multimodal::rastrigin, 5.12 / 100.0};
static constexpr auto schaffer =
basic_problem{cecxx::functions::multimodal::legacy::schaffer};
static constexpr auto bi_rastrigin =
basic_problem{cecxx::functions::multimodal::legacy::bi_rastrigin};
static constexpr auto step_rastrigin =
basic_problem{cecxx::functions::multimodal::step_rastrigin, 5.12 / 100.0};
static constexpr auto levy = basic_problem{cecxx::functions::multimodal::levy};
static constexpr auto schwefel = basic_problem{cecxx::functions::multimodal::schwefel, 10.0};
static constexpr auto ackley = basic_problem{cecxx::functions::multimodal::ackley};
static constexpr auto hgbat = basic_problem{cecxx::functions::multimodal::hgbat, 5.0 / 100.0};
static constexpr auto happycat = basic_problem{cecxx::functions::multimodal::happycat, 5.0 / 100.0};
static constexpr auto escaffer = basic_problem{cecxx::functions::multimodal::escaffer};
static constexpr auto katsuura = basic_problem{cecxx::functions::multimodal::katsuura, 5.0 / 100.0};
static constexpr auto grie_rosen = basic_problem{cecxx::functions::multimodal::grie_rosen, 5.0 / 100.0};
static constexpr auto weierstrass = basic_problem{cecxx::functions::multimodal::weierstrass, 0.5 / 100.0};
static constexpr auto griewank = basic_problem{cecxx::functions::multimodal::griewank, 6.0};
} // namespace cecxx::benchmark::detail::cec2017
static constexpr auto schwefel =
basic_problem{cecxx::functions::multimodal::schwefel, 10.0};
static constexpr auto ackley =
basic_problem{cecxx::functions::multimodal::ackley};
static constexpr auto hgbat =
basic_problem{cecxx::functions::multimodal::hgbat, 5.0 / 100.0};
static constexpr auto happycat =
basic_problem{cecxx::functions::multimodal::happycat, 5.0 / 100.0};
static constexpr auto escaffer =
basic_problem{cecxx::functions::multimodal::escaffer};
static constexpr auto katsuura =
basic_problem{cecxx::functions::multimodal::katsuura, 5.0 / 100.0};
static constexpr auto grie_rosen =
basic_problem{cecxx::functions::multimodal::grie_rosen, 5.0 / 100.0};
static constexpr auto weierstrass =
basic_problem{cecxx::functions::multimodal::weierstrass, 0.5 / 100.0};
static constexpr auto griewank =
basic_problem{cecxx::functions::multimodal::griewank, 6.0};
} // namespace cecxx::benchmark::detail::cec2017
173 changes: 92 additions & 81 deletions include/cecxx/benchmark/detail/cec2017/problems/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,95 +6,106 @@

namespace cecxx::benchmark::detail::cec2017 {

const auto complex_1 = complex_problem{std::tuple{rosenbrock, ellips, rastrigin},
{.deltas = {10.0, 20.0, 30.0},
.biases = {0.0, 100.0, 200.0},
.scales = {
{0, 1},
{1, 10000 / 1e+10},
{2, 1},
}}};
const auto complex_1 =
complex_problem{std::tuple{rosenbrock, ellips, rastrigin},
{.deltas = {10.0, 20.0, 30.0},
.biases = {0.0, 100.0, 200.0},
.scales = {
{0, 1},
{1, 10000 / 1e+10},
{2, 1},
}}};

const auto complex_2 = complex_problem{std::tuple{rastrigin, griewank, schwefel},
{.deltas = {10.0, 20.0, 30.0},
.biases = {0.0, 100.0, 200.0},
.scales = {
{0, 1.0},
{1, 10.0},
{2, 1.0},
}}};
const auto complex_2 =
complex_problem{std::tuple{rastrigin, griewank, schwefel},
{.deltas = {10.0, 20.0, 30.0},
.biases = {0.0, 100.0, 200.0},
.scales = {
{0, 1.0},
{1, 10.0},
{2, 1.0},
}}};

const auto complex_3 = complex_problem{std::tuple{rosenbrock, ackley, schwefel, rastrigin},
{.deltas = {10.0, 20.0, 30.0, 40.0},
.biases = {0.0, 100.0, 200.0, 300.0},
.scales = {
{0, 1.0},
{1, 10.0},
{2, 1.0},
{3, 1.0},
}}};
const auto complex_3 =
complex_problem{std::tuple{rosenbrock, ackley, schwefel, rastrigin},
{.deltas = {10.0, 20.0, 30.0, 40.0},
.biases = {0.0, 100.0, 200.0, 300.0},
.scales = {
{0, 1.0},
{1, 10.0},
{2, 1.0},
{3, 1.0},
}}};

const auto complex_4 = complex_problem{std::tuple{ackley, ellips, griewank, rastrigin},
{.deltas = {10.0, 20.0, 30.0, 40.0},
.biases = {0.0, 100.0, 200.0, 300.0},
.scales = {
{0, 10.0},
{1, 1e-6},
{2, 10.0},
{3, 1.0},
}}};
const auto complex_4 =
complex_problem{std::tuple{ackley, ellips, griewank, rastrigin},
{.deltas = {10.0, 20.0, 30.0, 40.0},
.biases = {0.0, 100.0, 200.0, 300.0},
.scales = {
{0, 10.0},
{1, 1e-6},
{2, 10.0},
{3, 1.0},
}}};

const auto complex_5 = complex_problem{std::tuple{rastrigin, happycat, ackley, discus, rosenbrock},
{.deltas = {10.0, 20.0, 30.0, 40.0, 50.0},
.biases = {0.0, 100.0, 200.0, 300.0, 400.0},
.scales = {
{0, 10.0},
{1, 1.0},
{2, 10.0},
{3, 1e-6},
{4, 1.0},
}}};
const auto complex_5 =
complex_problem{std::tuple{rastrigin, happycat, ackley, discus, rosenbrock},
{.deltas = {10.0, 20.0, 30.0, 40.0, 50.0},
.biases = {0.0, 100.0, 200.0, 300.0, 400.0},
.scales = {
{0, 10.0},
{1, 1.0},
{2, 10.0},
{3, 1e-6},
{4, 1.0},
}}};

const auto complex_6 = complex_problem{std::tuple{escaffer, schwefel, griewank, rosenbrock, rastrigin},
{.deltas = {10.0, 20.0, 20.0, 30.0, 40.0},
.biases = {0.0, 100.0, 200.0, 300.0, 400.0},
.scales = {
{0, 1e4 / 2e+7},
{1, 1},
{2, 10},
{3, 1},
{4, 10},
}}};
const auto complex_6 = complex_problem{
std::tuple{escaffer, schwefel, griewank, rosenbrock, rastrigin},
{.deltas = {10.0, 20.0, 20.0, 30.0, 40.0},
.biases = {0.0, 100.0, 200.0, 300.0, 400.0},
.scales = {
{0, 1e4 / 2e+7},
{1, 1},
{2, 10},
{3, 1},
{4, 10},
}}};

const auto complex_7 = complex_problem{std::tuple{hgbat, rastrigin, schwefel, bent_cigar, ellips, escaffer},
{.deltas = {10.0, 20.0, 30.0, 40.0, 50.0, 60.0},
.biases = {0.0, 100.0, 200.0, 300.0, 400.0, 500.0},
.scales = {
{0, 10},
{1, 10},
{2, 1e4 / 4e3},
{3, 1e4 / 1e30},
{4, 1e4 / 1e10},
{5, 1e4 / 2e7},
}}};
const auto complex_7 = complex_problem{
std::tuple{hgbat, rastrigin, schwefel, bent_cigar, ellips, escaffer},
{.deltas = {10.0, 20.0, 30.0, 40.0, 50.0, 60.0},
.biases = {0.0, 100.0, 200.0, 300.0, 400.0, 500.0},
.scales = {
{0, 10},
{1, 10},
{2, 1e4 / 4e3},
{3, 1e4 / 1e30},
{4, 1e4 / 1e10},
{5, 1e4 / 2e7},
}}};

const auto complex_8 = complex_problem{std::tuple{ackley, griewank, discus, rosenbrock, happycat, escaffer},
{.deltas = {10.0, 20.0, 30.0, 40.0, 50.0, 60.0},
.biases = {0.0, 100.0, 200.0, 300.0, 400.0, 500.0},
.scales = {
{0, 10},
{1, 10},
{2, 1e4 / 1e10},
{3, 1},
{4, 1},
{5, 1e4 / 2e7},
}}};
const auto complex_8 = complex_problem{
std::tuple{ackley, griewank, discus, rosenbrock, happycat, escaffer},
{.deltas = {10.0, 20.0, 30.0, 40.0, 50.0, 60.0},
.biases = {0.0, 100.0, 200.0, 300.0, 400.0, 500.0},
.scales = {
{0, 10},
{1, 10},
{2, 1e4 / 1e10},
{3, 1},
{4, 1},
{5, 1e4 / 2e7},
}}};

const auto complex_9 =
complex_problem{std::tuple{hybrid_5, hybrid_6, hybrid_7},
{.deltas = {10.0, 30.0, 50.0}, .biases = {0.0, 100.0, 200.0}, .scales = {{0, 1}, {1, 1}, {2, 1}}}};
const auto complex_9 = complex_problem{std::tuple{hybrid_5, hybrid_6, hybrid_7},
{.deltas = {10.0, 30.0, 50.0},
.biases = {0.0, 100.0, 200.0},
.scales = {{0, 1}, {1, 1}, {2, 1}}}};

const auto complex_10 =
complex_problem{std::tuple{hybrid_5, hybrid_8, hybrid_9},
{.deltas = {10.0, 30.0, 50.0}, .biases = {0.0, 100.0, 200.0}, .scales = {{0, 1}, {1, 1}, {2, 1}}}};
} // namespace cecxx::benchmark::detail::cec2017
{.deltas = {10.0, 30.0, 50.0},
.biases = {0.0, 100.0, 200.0},
.scales = {{0, 1}, {1, 1}, {2, 1}}}};
} // namespace cecxx::benchmark::detail::cec2017
39 changes: 25 additions & 14 deletions include/cecxx/benchmark/detail/cec2017/problems/hybrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,28 @@
#include "cecxx/benchmark/detail/problem/hybrid.hpp"

namespace cecxx::benchmark::detail::cec2017 {
const auto hybrid_1 = hybrid_problem{std::tuple{zakharov, rosenbrock, rastrigin}, {0.2, 0.4, 0.4}};
const auto hybrid_2 = hybrid_problem{std::tuple{ellips, schwefel, bent_cigar}, {0.3, 0.3, 0.4}};
const auto hybrid_3 = hybrid_problem{std::tuple{bent_cigar, rosenbrock, bi_rastrigin}, {0.3, 0.3, 0.4}};
const auto hybrid_4 = hybrid_problem{std::tuple{ellips, ackley, schaffer, rastrigin}, {0.2, 0.2, 0.2, 0.4}};
const auto hybrid_5 = hybrid_problem{std::tuple{bent_cigar, hgbat, rastrigin, rosenbrock}, {0.2, 0.2, 0.3, 0.3}};
const auto hybrid_6 = hybrid_problem{std::tuple{escaffer, hgbat, rosenbrock, schwefel}, {0.2, 0.2, 0.3, 0.3}};
const auto hybrid_7 =
hybrid_problem{std::tuple{katsuura, ackley, grie_rosen, schwefel, rastrigin}, {0.1, 0.2, 0.2, 0.2, 0.3}};
const auto hybrid_8 = hybrid_problem{std::tuple{ellips, ackley, rastrigin, hgbat, discus}, {0.2, 0.2, 0.2, 0.2, 0.2}};
const auto hybrid_9 =
hybrid_problem{std::tuple{bent_cigar, rastrigin, grie_rosen, weierstrass, escaffer}, {0.2, 0.2, 0.2, 0.2, 0.2}};
const auto hybrid_10 =
hybrid_problem{std::tuple{hgbat, katsuura, ackley, rastrigin, schwefel, schaffer}, {0.1, 0.1, 0.2, 0.2, 0.2, 0.2}};
} // namespace cecxx::benchmark::detail::cec2017
const auto hybrid_1 = hybrid_problem{
std::tuple{zakharov, rosenbrock, rastrigin}, {0.2, 0.4, 0.4}};
const auto hybrid_2 =
hybrid_problem{std::tuple{ellips, schwefel, bent_cigar}, {0.3, 0.3, 0.4}};
const auto hybrid_3 = hybrid_problem{
std::tuple{bent_cigar, rosenbrock, bi_rastrigin}, {0.3, 0.3, 0.4}};
const auto hybrid_4 = hybrid_problem{
std::tuple{ellips, ackley, schaffer, rastrigin}, {0.2, 0.2, 0.2, 0.4}};
const auto hybrid_5 = hybrid_problem{
std::tuple{bent_cigar, hgbat, rastrigin, rosenbrock}, {0.2, 0.2, 0.3, 0.3}};
const auto hybrid_6 = hybrid_problem{
std::tuple{escaffer, hgbat, rosenbrock, schwefel}, {0.2, 0.2, 0.3, 0.3}};
const auto hybrid_7 = hybrid_problem{
std::tuple{katsuura, ackley, grie_rosen, schwefel, rastrigin},
{0.1, 0.2, 0.2, 0.2, 0.3}};
const auto hybrid_8 =
hybrid_problem{std::tuple{ellips, ackley, rastrigin, hgbat, discus},
{0.2, 0.2, 0.2, 0.2, 0.2}};
const auto hybrid_9 = hybrid_problem{
std::tuple{bent_cigar, rastrigin, grie_rosen, weierstrass, escaffer},
{0.2, 0.2, 0.2, 0.2, 0.2}};
const auto hybrid_10 = hybrid_problem{
std::tuple{hgbat, katsuura, ackley, rastrigin, schwefel, schaffer},
{0.1, 0.1, 0.2, 0.2, 0.2, 0.2}};
} // namespace cecxx::benchmark::detail::cec2017
12 changes: 7 additions & 5 deletions include/cecxx/benchmark/detail/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#include "cecxx/types.hpp"

namespace cecxx::benchmark::detail {
template <typename Number> using context_table_t = std::unordered_map<fn_num, table_data<Number>>;
template <typename Number>
using context_table_t = std::unordered_map<fn_num, table_data<Number>>;

struct problem_context_view {
std::span<const f64> shift{};
Expand All @@ -18,8 +19,9 @@ struct problem_context_view {
};

class context_t {
public:
context_t(const cec_edition_t edition, const std::filesystem::path& storage, const u8 dim);
public:
context_t(const cec_edition_t edition, const std::filesystem::path &storage,
const u8 dim);

auto shift(const u8 fn) const { return shift_.at(fn); }
auto rotate(const u8 fn) const { return rotate_.at(fn); }
Expand All @@ -28,10 +30,10 @@ class context_t {
return problem_context_view{shift_.at(fn), rotate_.at(fn), shuffle_.at(fn)};
}

private:
private:
context_table_t<f64> rotate_{};
context_table_t<i64> shuffle_{};
context_table_t<f64> shift_{};
};

} // namespace cecxx::benchmark::detail
} // namespace cecxx::benchmark::detail
Loading

0 comments on commit 449af0f

Please sign in to comment.