Skip to content

Commit 0232c6b

Browse files
committed
Add CEC 2013
1 parent 9c8b915 commit 0232c6b

35 files changed

+2134
-626
lines changed
Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
1-
#include <cecxx/mdspan.hpp>
2-
#include <cstdlib>
3-
#include <print>
4-
#include <ranges>
5-
#include <vector>
1+
// #include <cecxx/mdspan.hpp>
2+
// #include <cstdlib>
3+
// #include <print>
4+
// #include <ranges>
5+
// #include <vector>
6+
//
7+
// #include <cecxx/benchmark/evaluator.hpp>
8+
//
9+
// namespace rn = std::ranges;
10+
// namespace rv = std::ranges::views;
11+
// using namespace cecxx::benchmark;
12+
//
13+
// auto main() -> int {
14+
// try {
15+
// const auto dimensions = std::vector{10uz, 30uz, 50uz, 100uz};
16+
//
17+
// // Create an evaluator object for the CEC2017 benchmark
18+
// auto cec_2017 = evaluator(cec_edition_t::cec2017, dimensions, DATA_STORAGE_PATH);
19+
//
20+
// // Create problem grid [problem_number X dimension]
21+
// const auto problem_grid = rv::cartesian_product(dimensions, rv::iota(1, 30));
22+
//
23+
// // Evaluate given input on each optimization problem from CEC2017/D{10, 30, 50, 100}
24+
// for (const auto &[dim, fn] : problem_grid) {
25+
// // Prepare input matrix [dim x 2]
26+
// const auto input = rv::repeat(0.0) | rv::take(2 * dim) | rn::to<std::vector<double>>();
27+
// const auto mat = cecxx::mdspan{input.data(), dim, 2};
28+
//
29+
// const auto output = cec_2017(fn, mat);
30+
// std::println("dim = {}, fn = {}, output[0] = {}, output[1] = {}", dim, fn, output[0], output[1]);
31+
// }
32+
// } catch (std::exception &e) {
33+
// std::println("Failed: {}", e.what());
34+
// return EXIT_FAILURE;
35+
// }
36+
// return EXIT_SUCCESS;
37+
// }
638

7-
#include <cecxx/benchmark/evaluator.hpp>
8-
9-
namespace rn = std::ranges;
10-
namespace rv = std::ranges::views;
11-
using namespace cecxx::benchmark;
12-
13-
auto main() -> int {
14-
try {
15-
const auto dimensions = std::vector{10uz, 30uz, 50uz, 100uz};
16-
17-
// Create an evaluator object for the CEC2017 benchmark
18-
auto cec_2017 = evaluator(cec_edition_t::cec2017, dimensions, DATA_STORAGE_PATH);
19-
20-
// Create problem grid [problem_number X dimension]
21-
const auto problem_grid = rv::cartesian_product(dimensions, rv::iota(1, 30));
22-
23-
// Evaluate given input on each optimization problem from CEC2017/D{10, 30, 50, 100}
24-
for (const auto &[dim, fn] : problem_grid) {
25-
// Prepare input matrix [dim x 2]
26-
const auto input = rv::repeat(0.0) | rv::take(2 * dim) | rn::to<std::vector<double>>();
27-
const auto mat = cecxx::mdspan{input.data(), dim, 2};
28-
29-
const auto output = cec_2017(fn, mat);
30-
std::println("dim = {}, fn = {}, output[0] = {}, output[1] = {}", dim, fn, output[0], output[1]);
31-
}
32-
} catch (std::exception &e) {
33-
std::println("Failed: {}", e.what());
34-
return EXIT_FAILURE;
35-
}
36-
return EXIT_SUCCESS;
37-
}
39+
auto main() -> int { }
Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
#include "cecxx/mdspan.hpp"
2-
#include <cstdlib>
3-
#include <functional>
4-
#include <print>
5-
#include <ranges>
6-
#include <vector>
7-
8-
#include <cecxx/benchmark/evaluator.hpp>
9-
10-
namespace rn = std::ranges;
11-
namespace rv = std::ranges::views;
12-
using namespace cecxx::benchmark;
13-
14-
auto dummy_optimizer(cecxx::benchmark::matrix_t x0, std::function<std::vector<double>(matrix_t)> fn) -> double {
15-
auto result = fn(x0);
16-
return result[0];
17-
}
18-
19-
auto main() -> int {
20-
try {
21-
constexpr auto dim{50uz};
22-
// Create an evaluator object for the CEC2017 benchmark for 50D
23-
auto cec_2017 = evaluator(cecxx::benchmark::cec_edition_t::cec2017, std::vector{dim}, DATA_STORAGE_PATH);
24-
25-
// Extract problem F3 from CEC2017/D50
26-
auto fn_3 = cec_2017.extract_problem(3, dim);
27-
28-
// Prepare starting point for your optimization solver
29-
const auto data = rv::repeat(0.0) | rv::take(dim) | rn::to<std::vector<double>>();
30-
const auto x0 = cecxx::mdspan{data.data(), dim, 1};
31-
32-
// Pass problem F3 to your optimizer together with starting point
33-
const auto result = dummy_optimizer(x0, fn_3);
34-
std::println("Dummy optimizer's result: {}", result);
35-
} catch (std::exception &e) {
36-
std::println("Failed: {}", e.what());
37-
return EXIT_FAILURE;
38-
}
39-
return EXIT_SUCCESS;
40-
}
1+
// #include "cecxx/mdspan.hpp"
2+
// #include <cstdlib>
3+
// #include <functional>
4+
// #include <print>
5+
// #include <ranges>
6+
// #include <vector>
7+
//
8+
// #include <cecxx/benchmark/evaluator.hpp>
9+
//
10+
// namespace rn = std::ranges;
11+
// namespace rv = std::ranges::views;
12+
// using namespace cecxx::benchmark;
13+
//
14+
// auto dummy_optimizer(cecxx::benchmark::matrix_t x0, std::function<std::vector<double>(matrix_t)> fn) -> double {
15+
// auto result = fn(x0);
16+
// return result[0];
17+
// }
18+
//
19+
// auto main() -> int {
20+
// try {
21+
// constexpr auto dim{50uz};
22+
// // Create an evaluator object for the CEC2017 benchmark for 50D
23+
// auto cec_2017 = evaluator(cecxx::benchmark::cec_edition_t::cec2017, std::vector{dim}, DATA_STORAGE_PATH);
24+
//
25+
// // Extract problem F3 from CEC2017/D50
26+
// auto fn_3 = cec_2017.extract_problem(3, dim);
27+
//
28+
// // Prepare starting point for your optimization solver
29+
// const auto data = rv::repeat(0.0) | rv::take(dim) | rn::to<std::vector<double>>();
30+
// const auto x0 = cecxx::mdspan{data.data(), dim, 1};
31+
//
32+
// // Pass problem F3 to your optimizer together with starting point
33+
// const auto result = dummy_optimizer(x0, fn_3);
34+
// std::println("Dummy optimizer's result: {}", result);
35+
// } catch (std::exception &e) {
36+
// std::println("Failed: {}", e.what());
37+
// return EXIT_FAILURE;
38+
// }
39+
// return EXIT_SUCCESS;
40+
// }
41+
//
42+
auto main() -> int { }

0 commit comments

Comments
 (0)