Files
aevolution/include/evo/biology/budding.hpp
T
dingo 5d8aa4d2e3
Foundation / checks (ecs) (push) Successful in 2m27s
Foundation / checks (deploy) (push) Successful in 4m15s
Foundation / checks (network) (push) Successful in 21m4s
Foundation / checks (client) (push) Successful in 22m22s
Foundation / checks (tsan) (push) Successful in 31m40s
Foundation / postgres-tools (push) Canceled after 0s
Foundation / server-image (push) Canceled after 0s
Foundation / image (push) Canceled after 0s
Foundation / checks (postgres) (push) Canceled after 45m38s
Foundation / checks (checks) (push) Canceled after 45m43s
feat(biology): fund offspring from a distinct inherited genome
2026-10-19 13:09:52 -04:00

60 lines
3.5 KiB
C++

#pragma once
#include "evo/biology/metabolism.hpp"
#include <cstdint>
#include <expected>
#include <optional>
// M11.5 budding (ADR-0098 decision 1, ADR-0125): a funded proposal, detached from any
// owner. The parent pays its ADR-0032 reproduction investment and a starting provision
// from its reserve; nothing is drawn from its body.
namespace evo::biology {
// Seconds of the bud's full demand (maintenance plus full-speed movement) the parent
// provides as starting reserve energy: the founder's reserve rule (ADR-0100). Trial.
inline constexpr std::uint64_t bud_provision_seconds = 30;
struct BudTransition {
GrowthState growth{}; // the bud's, the largest the investment matter builds
accounting::Inventory body{}; // the bud's developed body
accounting::Inventory reserve; // the bud's: leftover matter and the provision
accounting::Inventory parent_reserve; // the parent's reserve after paying
accounting::Picojoules heat{}; // the investment's construction energy
auto operator<=>(const BudTransition&) const = default;
};
enum class BuddingError : std::uint8_t {
no_capability, // The genome cannot reproduce.
not_grown, // The parent is not fully realized, or is damaged.
insufficient_funding, // Some channel of investment plus provision is missing.
development, // The genome's rules cannot develop it.
incompatible_genome // Distinct schema/development laws, or conflicting same-ID contents.
};
// Pure and deterministic. On every channel the parent's reserve before equals its reserve
// after plus the bud's body and reserve, plus heat in energy. A refusal spends nothing.
// `share` > 1 (ADR-0137 twins) funds one of that many buds from the same investment: each
// gets the investment divided by `share`, so twins are smaller, not extra.
[[nodiscard]] std::expected<BudTransition, BuddingError>
fund_bud(const Genome& genome, GrowthState parent_growth,
const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin,
std::uint32_t share = 1);
// ADR-0164: the expressed parent pays its own investment; the distinct inherited
// genome determines the newborn body/growth and its own provision. Both records
// must use the same schema/development versions. Inputs and parent anatomy are
// unchanged. This proposal confers no identity, placement, ancestry or control authority.
[[nodiscard]] std::expected<BudTransition, BuddingError>
fund_offspring(const Genome& parent, const Genome& offspring, GrowthState parent_growth,
const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin,
std::uint32_t share = 1);
// Exact charge for that pair and share from a full-grown, undamaged parent.
[[nodiscard]] std::optional<accounting::Inventory>
offspring_cost(const Genome& parent, const Genome& offspring, std::uint32_t temperature_millikelvin,
std::uint32_t share = 1);
// What one bud takes from a fully grown, undamaged parent of this genome at this temperature
// (ADR-0129 amendment): investment matter per channel, and construction energy plus the
// bud's provision; exactly what `fund_bud` charges such a parent. Nullopt when the genome
// cannot bud or cannot build a cell from its investment.
[[nodiscard]] std::optional<accounting::Inventory> bud_cost(const Genome& genome,
std::uint32_t temperature_millikelvin);
} // namespace evo::biology