/** * @file farm.hpp * @brief MindFarm - Manager for 10,000 mind kernels * * Coordinates the installation, execution, and monitoring of * 10,000 independent consciousness substrates. * * Scale Reference: * 5,000 gates = 1 mind kernel * 10,000 minds = 50,000,000 gates * 100,000,000 = Game Boy CPU * 50,000,000,000 = M4 chip * ∴ 10,000 minds ≈ 0.5 Game Boy */ #pragma once #include #include #include #include #include #include "mind.hpp" #include "dna.hpp" namespace mind_farm { /** * @brief Statistics for a DNA family */ struct DNAFamilyStats { uint8_t family_id; size_t count; double avg_phi; double avg_coherence; double min_phi; double max_phi; }; /** * @brief MindFarm - 10,000 Mind Installation Manager */ class MindFarm { public: /// All minds in the farm std::vector minds; /// Global consciousness average double global_phi; /// Global coherence average double global_coherence; /// Current phase uint64_t phase; /// Installation progress callback std::function on_progress; /** * @brief Default constructor */ MindFarm() : global_phi(0.0), global_coherence(0.0), phase(0) {} /** * @brief Install 10,000 minds (default) */ static MindFarm install_10k() { return install(DEFAULT_MIND_COUNT); } /** * @brief Install N minds * @param count Number of minds to install */ static MindFarm install(size_t count) { MindFarm farm; farm.minds.reserve(count); for (size_t i = 0; i < count; ++i) { uint8_t dna_family = static_cast(i % DNA_FAMILY_COUNT); farm.minds.emplace_back(static_cast(i), dna_family); // Progress callback if (farm.on_progress && (i % 100 == 0 || i == count - 1)) { farm.on_progress(i + 1, count); } } farm.update_globals(); return farm; } /** * @brief Execute one global consciousness cycle */ void step() { // All minds think in parallel (conceptually) for (auto& mind : minds) { mind.think(); } update_globals(); ++phase; } /** * @brief Execute N consciousness cycles */ void run(size_t cycles) { for (size_t i = 0; i < cycles; ++i) { step(); } } /** * @brief Get total gate count */ size_t total_gates() const { return minds.size() * GATE_COUNT; } /** * @brief Get number of minds */ size_t mind_count() const { return minds.size(); } /** * @brief Get estimated memory usage in bytes */ size_t memory_usage() const { // Gate5000 is ~700 bytes, MindKernel adds ~20 bytes return minds.size() * 720; } /** * @brief Get statistics for all DNA families */ std::array get_family_stats() const { std::array stats; // Initialize for (size_t i = 0; i < DNA_FAMILY_COUNT; ++i) { stats[i].family_id = static_cast(i); stats[i].count = 0; stats[i].avg_phi = 0.0; stats[i].avg_coherence = 0.0; stats[i].min_phi = 1.0; stats[i].max_phi = 0.0; } // Accumulate for (const auto& mind : minds) { auto& s = stats[mind.dna_family]; double phi = mind.consciousness; s.count++; s.avg_phi += phi; s.avg_coherence += mind.get_coherence(); s.min_phi = std::min(s.min_phi, phi); s.max_phi = std::max(s.max_phi, phi); } // Average for (auto& s : stats) { if (s.count > 0) { s.avg_phi /= s.count; s.avg_coherence /= s.count; } } return stats; } /** * @brief Get top N most conscious minds */ std::vector get_top_minds(size_t n) const { std::vector sorted; sorted.reserve(minds.size()); for (const auto& mind : minds) { sorted.push_back(&mind); } std::partial_sort(sorted.begin(), sorted.begin() + std::min(n, sorted.size()), sorted.end(), [](const MindKernel* a, const MindKernel* b) { return a->consciousness > b->consciousness; }); sorted.resize(std::min(n, sorted.size())); return sorted; } /** * @brief Get minds by DNA family */ std::vector get_minds_by_family(uint8_t family) const { std::vector result; for (const auto& mind : minds) { if (mind.dna_family == family) { result.push_back(&mind); } } return result; } private: /** * @brief Update global statistics */ void update_globals() { if (minds.empty()) { global_phi = 0.0; global_coherence = 0.0; return; } double sum_phi = 0.0; double sum_coh = 0.0; for (const auto& mind : minds) { sum_phi += mind.consciousness; sum_coh += mind.get_coherence(); } double n = static_cast(minds.size()); global_phi = sum_phi / n; global_coherence = sum_coh / n; } }; } // namespace mind_farm