diff --git a/.gitignore b/.gitignore index d0aa963..26f0e97 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ node_modules .output/* dist .nuxt/* +.cache/* diff --git a/resistor-optimization/include/combinations_with_replacement.hpp b/resistor-optimization/include/combinations_with_replacement.hpp index d9d236b..8a53f77 100755 --- a/resistor-optimization/include/combinations_with_replacement.hpp +++ b/resistor-optimization/include/combinations_with_replacement.hpp @@ -12,20 +12,20 @@ #include "__generator.hpp" #endif -std::generator&> gen_indicies(const size_t n, +std::generator&> gen_indices(const size_t n, const size_t r); template std::generator&&> combinations_with_replacement( const std::vector& pool, const size_t r) { - for (const auto& indicies : gen_indicies(pool.size(), r)) { + for (const auto& indices : gen_indices(pool.size(), r)) { auto combination = std::vector(r); auto transform_view = std::views::iota((size_t)0, r) | std::views::transform( - [&indicies, &pool](const size_t i) { return pool[indicies[i]]; }); + [&indices, &pool](const size_t i) { return pool[indices[i]]; }); std::ranges::copy(transform_view, combination.begin()); co_yield std::move(combination); diff --git a/resistor-optimization/src/Main.cpp b/resistor-optimization/src/Main.cpp index 498ed19..c67d6ba 100755 --- a/resistor-optimization/src/Main.cpp +++ b/resistor-optimization/src/Main.cpp @@ -4,11 +4,11 @@ int main() { #if !__has_include() // some tests - int r = 5; - std::vector resistors{17.56}; + int r = 3; + std::vector resistors{1.0, 1.7, 7.5, 3.6, 9};; const auto ro = ResistanceOptimizer(resistors); - const auto [svg, resistance] = ro.optimize(17.56, r); + const auto [svg, resistance] = ro.optimize(1.7, r); std::cout << resistance << std::endl; std::cout << svg << std::endl; #endif diff --git a/resistor-optimization/src/ResistanceOptimizer.cpp b/resistor-optimization/src/ResistanceOptimizer.cpp index af59c58..3adbb72 100755 --- a/resistor-optimization/src/ResistanceOptimizer.cpp +++ b/resistor-optimization/src/ResistanceOptimizer.cpp @@ -23,6 +23,12 @@ ResistanceOptimizer::generateCombinations( const auto c = std::ranges::subrange(begin, end); if (base == nullptr) { + for (const auto& resistor : c) { + const auto base = std::make_shared(); + base->add(resistor); + co_yield base; + } + const auto base1 = std::make_shared(); for (const auto& res : generateCombinations( begin, end, base1)) { @@ -61,6 +67,7 @@ ResistanceOptimizer::generateCombinations( } } else { auto pcont = std::dynamic_pointer_cast(container); + assert(pcont); const auto new_scont = std::make_shared(); new_scont->add(c[0]); diff --git a/resistor-optimization/src/combinations_with_replacement.cpp b/resistor-optimization/src/combinations_with_replacement.cpp index 8f34a53..7867c9b 100755 --- a/resistor-optimization/src/combinations_with_replacement.cpp +++ b/resistor-optimization/src/combinations_with_replacement.cpp @@ -1,10 +1,10 @@ #include "combinations_with_replacement.hpp" -std::generator&> gen_indicies(const size_t n, +std::generator&> gen_indices(const size_t n, const size_t r) { - std::vector indicies(r); - co_yield indicies; - const auto rev = indicies | std::views::reverse; + std::vector indices(r); + co_yield indices; + const auto rev = indices | std::views::reverse; while (true) { const auto found = std::ranges::find_if( @@ -19,6 +19,6 @@ std::generator&> gen_indicies(const size_t n, el = fill; } - co_yield indicies; + co_yield indices; } }