Files
aevolution/include/evo/processes/ecosystem.hpp
T
dingoandClaude Opus 5 eaf58f2b85 Drive the energy cycle with measured ecosystem episodes
Close M2 with a deterministic driver that owns one community and one
seeded stream, holds no inventory and emits only the terminal, feeding
and reproduction intents the earlier increments already accept. No
simulation contract changed to make the cycle run unattended.

Two limits shaped the design. Identities are never reused and slots are
capped, so one community supports a bounded number of consumer lifetimes
and is not a population. No maintenance cost exists, so a consumer that
is never eaten never dies, and inventing a starvation rule here would
settle a question ENERGY_MODEL leaves open inside a measurement harness.
The harness therefore measures many bounded episodes, taking mortality
from predation and from a configured lifespan delivered as an ADR-0027
host terminal fact. Lifespan bounds an episode; it is not senescence.

The driver must never submit a batch the community rejects, so it probes
a discarded copy each tick to size bites against the state feeding will
actually see, claims each target for one feeder, and excludes a bitten
consumer from acting. A rejected tick is reported as a driver defect
rather than absorbed as ecology.

Across 64 seeds the suite steps tick by tick, requiring exact conserved
totals at every tick and an identical report on replay, and covers both
mortality paths, slot exhaustion, tick-limit termination, lineage
attribution, episode independence and configuration rejection.
evo-sim --ecosystem reports seeded ensembles: 3,000 episodes advanced
1,093,007 ticks, all reaching extinction, with deaths reconciling exactly
against founders plus births. That demonstrates arithmetic and turnover,
not ecological plausibility; strategy constants are chosen inputs.

Native Release, clang-tidy analysis, ASan and format checks pass 11/11;
golden d61ad5bf0c928c76 is unchanged. Linux CI has not run yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-22 17:38:34 -04:00

80 lines
2.9 KiB
C++

#pragma once
#include "evo/core/random.hpp"
#include "evo/processes/feeding.hpp"
namespace evo::processes {
// One founder strategy. ADR-0028 makes a child duplicate its parent, so a founder
// strategy identifies one lineage for the whole episode.
struct StrategyConfig {
accounting::Inventory opening;
accounting::Inventory intake_limit;
std::uint16_t assimilation_per_thousand;
accounting::Inventory reproduction_threshold;
accounting::Inventory investment;
// Ticks of life before a host terminal fact. Bounds the episode; not senescence.
std::uint32_t lifespan;
};
struct EcosystemConfig {
ProducerConfig producer;
accounting::Picojoules source;
std::array<accounting::Femtograms, 4> nutrients;
DecompositionConfig decomposition;
std::uint16_t construction_per_thousand;
std::uint32_t capacity;
std::uint64_t tick_limit;
};
struct EcosystemReport {
std::uint64_t seed;
std::uint64_t ticks;
std::uint64_t births;
std::uint64_t predation_deaths;
std::uint64_t lifespan_deaths;
// Zero when living consumers remained when the episode stopped.
std::uint64_t extinction_tick;
std::uint32_t founders;
std::uint32_t surviving_lineages;
accounting::Inventory decomposed;
accounting::Inventory conserved;
std::uint64_t fingerprint;
auto operator<=>(const EcosystemReport&) const = default;
};
enum class EcosystemError : std::uint8_t {
invalid_config,
// The community rejected a driver batch. This is a driver defect, not ecology.
community_failure
};
inline constexpr std::size_t max_strategies = 4;
class EcosystemEpisode {
public:
[[nodiscard]] static std::expected<EcosystemEpisode, EcosystemError>
create(EcosystemConfig config, std::span<const StrategyConfig> founders, std::uint64_t seed);
// One driven tick. False once the episode has ended; the report is then final.
[[nodiscard]] std::expected<bool, EcosystemError> step();
[[nodiscard]] std::expected<EcosystemReport, EcosystemError> run();
[[nodiscard]] EcosystemReport report() const noexcept;
[[nodiscard]] const FeedingCommunity& community() const noexcept {
return community_;
}
// Founder ID whose retained ancestry this process descends from; zero if unborn.
[[nodiscard]] std::uint32_t lineage(std::uint32_t id) const noexcept;
private:
EcosystemEpisode(FeedingCommunity community, std::vector<StrategyConfig> founders,
EcosystemConfig config, std::uint64_t seed);
[[nodiscard]] const StrategyConfig& strategy(std::uint32_t id) const noexcept;
FeedingCommunity community_;
std::vector<StrategyConfig> founders_;
EcosystemConfig config_;
Random random_;
std::uint64_t seed_;
std::uint64_t births_{};
std::uint64_t predation_deaths_{};
std::uint64_t lifespan_deaths_{};
std::uint64_t extinction_tick_{};
accounting::Inventory decomposed_{};
bool finished_{};
};
} // namespace evo::processes