Close the M2.5 fixture cycle. A bounded list of trusted reproduction intents runs after feeding and before decomposition, so a consumer can fund offspring from what it ingested and a process terminated in that tick cannot reproduce. The intent names a withdrawal from the parent reservoir; a fixed construction fraction endows the child and the remainder becomes real heat and waste. Nothing is credited from outside the community, so conserved totals are unchanged by a birth. Reserved slots are pre-allocated at creation, so a birth never grows the ledger and a full community rejects rather than funding a smaller child. Slots never return to the unborn state, so process identities are never reused, and a parent reference plus origin tick outlive both organisms and survive decomposition. A child duplicates the configuration of its parent because no genome exists yet; this is duplication, not heredity. Default zero capacity leaves the M2.4 reservoir layout and every existing result unchanged, including golden d61ad5bf0c928c76. Native Release, clang-tidy analysis, ASan and format checks pass; Linux CI has not run for this increment yet. This defines no reproductive strategy, fecundity rule, mutation model, gestation, spatial placement or account ownership. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
119 lines
4.4 KiB
C++
119 lines
4.4 KiB
C++
#pragma once
|
|
|
|
#include "evo/processes/producer.hpp"
|
|
|
|
namespace evo::processes {
|
|
struct ConsumerConfig {
|
|
accounting::Inventory opening;
|
|
accounting::Inventory intake_limit;
|
|
std::uint16_t assimilation_per_thousand;
|
|
};
|
|
struct FeedIntent {
|
|
std::uint64_t sequence;
|
|
std::uint32_t consumer;
|
|
std::uint32_t target;
|
|
accounting::Inventory amount;
|
|
};
|
|
struct FeedReceipt {
|
|
std::uint64_t sequence;
|
|
accounting::Inventory assimilated;
|
|
bool target_depleted;
|
|
auto operator<=>(const FeedReceipt&) const = default;
|
|
};
|
|
struct TerminalEvent {
|
|
std::uint32_t actor;
|
|
};
|
|
struct DecompositionConfig {
|
|
accounting::Inventory per_tick_limit{};
|
|
};
|
|
// Reserved slots are allocated at creation; a birth never grows the ledger.
|
|
struct ReproductionConfig {
|
|
std::uint32_t capacity{};
|
|
std::uint16_t construction_per_thousand{};
|
|
accounting::Inventory minimum_endowment{};
|
|
};
|
|
struct ReproduceIntent {
|
|
std::uint64_t sequence;
|
|
std::uint32_t parent;
|
|
accounting::Inventory investment;
|
|
};
|
|
struct ReproduceReceipt {
|
|
std::uint64_t sequence;
|
|
std::uint32_t child;
|
|
accounting::Inventory endowment;
|
|
accounting::Inventory overhead;
|
|
auto operator<=>(const ReproduceReceipt&) const = default;
|
|
};
|
|
enum class FeedingError : std::uint8_t {
|
|
invalid_config,
|
|
wrong_tick,
|
|
invalid_batch,
|
|
invalid_actor,
|
|
inactive_actor,
|
|
unborn_actor,
|
|
not_corpse,
|
|
intake_limit,
|
|
insufficient_inventory,
|
|
no_capacity,
|
|
invalid_endowment,
|
|
accounting_failure
|
|
};
|
|
inline constexpr std::size_t max_consumers = 16;
|
|
|
|
class FeedingCommunity {
|
|
public:
|
|
[[nodiscard]] static std::expected<FeedingCommunity, FeedingError>
|
|
create(ProducerConfig producer, accounting::Picojoules source,
|
|
std::array<accounting::Femtograms, 4> nutrients,
|
|
std::span<const ConsumerConfig> consumers, DecompositionConfig decomposition = {},
|
|
ReproductionConfig reproduction = {});
|
|
[[nodiscard]] std::expected<std::vector<FeedReceipt>, FeedingError>
|
|
advance(Tick target, std::span<const FeedIntent> inputs = {},
|
|
std::span<const TerminalEvent> terminal_events = {},
|
|
std::span<const ReproduceIntent> births = {});
|
|
[[nodiscard]] std::span<const accounting::Inventory> balances() const noexcept {
|
|
return producer_.balances();
|
|
}
|
|
[[nodiscard]] ProducerProgress progress() const noexcept {
|
|
return producer_.progress();
|
|
}
|
|
// Process IDs are one-based. Out-of-range is a query error, not an inactive actor.
|
|
[[nodiscard]] std::expected<bool, FeedingError> active(std::uint32_t id) const noexcept;
|
|
// False for a reserved slot that no reproduction has allocated yet.
|
|
[[nodiscard]] std::expected<bool, FeedingError> born(std::uint32_t id) const noexcept;
|
|
[[nodiscard]] std::expected<accounting::Inventory, FeedingError>
|
|
corpse(std::uint32_t id) const noexcept;
|
|
// Ancestry outlives both organisms; zero identifies a documented founder.
|
|
[[nodiscard]] std::expected<std::uint32_t, FeedingError>
|
|
parent(std::uint32_t id) const noexcept;
|
|
[[nodiscard]] std::expected<Tick, FeedingError> origin(std::uint32_t id) const noexcept;
|
|
[[nodiscard]] accounting::Inventory last_decomposed() const noexcept {
|
|
return last_decomposed_;
|
|
}
|
|
// Committed births of the last successful tick; invalidated by mutation.
|
|
[[nodiscard]] std::span<const ReproduceReceipt> last_births() const noexcept {
|
|
return last_births_;
|
|
}
|
|
|
|
private:
|
|
enum class State : std::uint8_t { unborn, active, corpse };
|
|
FeedingCommunity(ProducerProcess producer, std::vector<ConsumerConfig> consumers,
|
|
DecompositionConfig decomposition, ReproductionConfig reproduction,
|
|
std::uint32_t living);
|
|
[[nodiscard]] std::expected<FeedReceipt, FeedingError> feed(const FeedIntent& input);
|
|
[[nodiscard]] std::expected<ReproduceReceipt, FeedingError>
|
|
reproduce(const ReproduceIntent& input, Tick target);
|
|
[[nodiscard]] std::expected<void, FeedingError> decompose();
|
|
[[nodiscard]] std::expected<State, FeedingError> state(std::uint32_t id) const noexcept;
|
|
ProducerProcess producer_;
|
|
std::vector<ConsumerConfig> consumers_;
|
|
std::vector<State> states_;
|
|
std::vector<std::uint32_t> parents_;
|
|
std::vector<Tick> origins_;
|
|
DecompositionConfig decomposition_;
|
|
ReproductionConfig reproduction_;
|
|
accounting::Inventory last_decomposed_{};
|
|
std::vector<ReproduceReceipt> last_births_;
|
|
};
|
|
} // namespace evo::processes
|