diff --git a/include/gp_system.h b/include/gp_system.h index 29da9fe..c471186 100644 --- a/include/gp_system.h +++ b/include/gp_system.h @@ -19,6 +19,7 @@ #ifndef GP_SYSTEM_H #define GP_SYSTEM_H #include +#include #include void setup_gp_system(blt::size_t population_size); @@ -47,4 +48,6 @@ std::array to_gl_image(c std::tuple&, const std::vector&, const std::vector&, const std::vector&> get_fitness_history(); +std::array get_populations(); + #endif //GP_SYSTEM_H diff --git a/sad cannon2.png b/sad cannon2.png new file mode 100644 index 0000000..f4f3fd4 Binary files /dev/null and b/sad cannon2.png differ diff --git a/src/gp_system.cpp b/src/gp_system.cpp index d01fd55..5641114 100644 --- a/src/gp_system.cpp +++ b/src/gp_system.cpp @@ -214,44 +214,14 @@ void setup_operations(gp_program* program) return ret; }, "lt_image"); static operation_t op_image_grad([](const image_t a, const image_t b) { - image_t out{}; // storage for the result - const auto& inA = a.get_data().data; - const auto& inB = b.get_data().data; - auto& dst = out.get_data().data; + image_t out{}; - constexpr std::size_t W = IMAGE_DIMENSIONS; - constexpr std::size_t H = IMAGE_DIMENSIONS; - - if (true) + for (const auto& [i, av, bv] : blt::in_pairs(std::as_const(a.get_data().data), std::as_const(b.get_data().data)).enumerate().flatten()) { - for (std::size_t y = 0; y < H; ++y) - { - for (std::size_t x = 0; x < W; ++x) - { - const double t = static_cast(x) / static_cast(W - 1); - const std::size_t idx = y * W + x; + const auto p = static_cast(i) / static_cast(IMAGE_SIZE); + const auto pi = 1 - p; - const double a = static_cast(inA[idx]); - const double b = static_cast(inB[idx]); - - dst[idx] = static_cast((1.0 - t) * a + t * b); - } - } - } else // vertical gradient - { - for (std::size_t y = 0; y < H; ++y) - { - const double t = static_cast(y) / static_cast(H - 1); - for (std::size_t x = 0; x < W; ++x) - { - const std::size_t idx = y * W + x; - - const double a = static_cast(inA[idx]); - const double b = static_cast(inB[idx]); - - dst[idx] = static_cast((1.0 - t) * a + t * b); - } - } + out.get_data().data[i] = static_cast(av * p + bv * pi); } return out; }, "grad_image"); @@ -341,10 +311,11 @@ void setup_operations(gp_program* program) // }, "erode_image"); operator_builder builder{}; - // builder.build(op_image_ephemeral, make_add(), make_sub(), make_mul(), make_div(), op_image_x, op_image_y, - // op_image_sin, op_image_gt, op_image_lt, op_image_cos, op_image_log, op_image_exp, op_image_or, op_image_and, op_image_xor, op_image_cos_off, op_image_sin_off op_image_perlinm - // op_image_2d_ifs_eph, op_image_noise, op_image_random, op_image_2d_perlin_eph, op_image_not, op_image_2d_perlin_oct); - builder.build(op_image_grad, op_image_x, op_image_y); + builder.build(op_image_ephemeral, make_add(), make_sub(), make_mul(), make_div(), op_image_x, op_image_y, + op_image_sin, op_image_gt, op_image_lt, op_image_cos, op_image_log, op_image_exp, op_image_or, op_image_and, op_image_xor, + op_image_cos_off, op_image_sin_off, op_image_perlin, op_image_noise, op_image_random, op_image_2d_perlin_eph, op_image_not, op_image_grad, + op_image_2d_perlin_oct); + // builder.build(op_image_grad, op_image_x, op_image_y); program->set_operations(builder.grab()); } @@ -491,3 +462,8 @@ std::tuple&, const std::vector&, const std::vect { return {average_fitness, best_fitness, worst_fitness, overall_fitness}; } + +std::array get_populations() +{ + return {&programs[0]->get_current_pop(), &programs[1]->get_current_pop(), &programs[2]->get_current_pop()}; +} diff --git a/src/main.cpp b/src/main.cpp index 32f0e7f..2c1c36b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -190,6 +190,28 @@ void update(const blt::gfx::window_data& data) if (ImGui::BeginTabItem("Statistics")) { ImGui::Text("Here you can view statistics."); + + auto pops = get_populations(); + + const std::array labels = {"Red", "Green", "Blue"}; + + for (const auto& [i, label, pop] : blt::in_pairs(labels, pops).enumerate().flatten()) + { + if (i > 0) + ImGui::SameLine(); + ImGui::BeginGroup(); + ImGui::Text("Population (%s)", label.c_str()); + if (ImGui::BeginChild(label.c_str(), ImVec2(250, 0), true)) + { + for (const auto& [i, ind] : blt::enumerate(*pop)) + { + ImGui::Text("Tree (%ld) -> Fitness: %lf", i, ind.fitness.adjusted_fitness); + } + } + ImGui::EndChild(); + ImGui::EndGroup(); + } + // Additional UI for statistical data ImGui::EndTabItem(); }