feat(biology): fund offspring from a distinct inherited genome
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
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
This commit is contained in:
@@ -519,6 +519,11 @@ if(BUILD_TESTING)
|
|||||||
evo_owned_target(evo-budding-tests)
|
evo_owned_target(evo-budding-tests)
|
||||||
add_test(NAME budding-contracts COMMAND evo-budding-tests)
|
add_test(NAME budding-contracts COMMAND evo-budding-tests)
|
||||||
set_tests_properties(budding-contracts PROPERTIES TIMEOUT 120)
|
set_tests_properties(budding-contracts PROPERTIES TIMEOUT 120)
|
||||||
|
add_executable(evo-offspring-tests tests/offspring_tests.cpp)
|
||||||
|
target_link_libraries(evo-offspring-tests PRIVATE evo::biology)
|
||||||
|
evo_owned_target(evo-offspring-tests)
|
||||||
|
add_test(NAME offspring-inherited-funding COMMAND evo-offspring-tests)
|
||||||
|
set_tests_properties(offspring-inherited-funding PROPERTIES TIMEOUT 120)
|
||||||
add_executable(evo-lineage-tests tests/lineage_tests.cpp)
|
add_executable(evo-lineage-tests tests/lineage_tests.cpp)
|
||||||
target_link_libraries(evo-lineage-tests PRIVATE evo::biology)
|
target_link_libraries(evo-lineage-tests PRIVATE evo::biology)
|
||||||
evo_owned_target(evo-lineage-tests)
|
evo_owned_target(evo-lineage-tests)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ spec:
|
|||||||
env:
|
env:
|
||||||
- {name: REGION_SESSION, value: "dev"}
|
- {name: REGION_SESSION, value: "dev"}
|
||||||
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
- {name: REGION_SESSION_LISTEN, value: "0.0.0.0:7400"}
|
||||||
- {name: REGION_SESSION_WINDOW, value: "dev-20261019T165803-c8e9d2c7:1792443483"}
|
- {name: REGION_SESSION_WINDOW, value: "dev-20261019T170913-a5535407:1792444153"}
|
||||||
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
- {name: REGION_M10_MAX_GRANT_LIFETIME, value: "14400"}
|
||||||
ports:
|
ports:
|
||||||
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
# QUIC (ADR-0090): UDP only; nothing listens on TCP 7400.
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
# Project status and next steps
|
# Project status and next steps
|
||||||
|
|
||||||
|
## Distinct-genome offspring funding - 2026-10-19
|
||||||
|
|
||||||
|
[ADR-0164](adr/0164-distinct-genome-offspring-funding.md) implements the first
|
||||||
|
biology operation for generational structural inheritance. An unchanged parent
|
||||||
|
can fund a child with a distinct inherited anatomy and starting demand, with
|
||||||
|
exact energy/element closure and no free tissue. Siblings retain the selected
|
||||||
|
plan while archive records keep the parent's expressed genome separate.
|
||||||
|
|
||||||
|
Both full MSVC/GCC Release suites pass **83/83**. Focused ASan/UBSan, clang-tidy
|
||||||
|
and formatting pass; [validation](engineering/VALIDATION.md) records exact scope.
|
||||||
|
Stored offspring plans, mutation timing, birth control handoff, retained NPC
|
||||||
|
behavior and choice UI remain next work. Current live/default biology is unchanged.
|
||||||
|
|
||||||
## Gameplay alignment: structural inheritance and succession - 2026-10-19
|
## Gameplay alignment: structural inheritance and succession - 2026-10-19
|
||||||
|
|
||||||
The maintainer accepts [ADR-0163](adr/0163-structural-inheritance-and-offspring-succession.md):
|
The maintainer accepts [ADR-0163](adr/0163-structural-inheritance-and-offspring-succession.md):
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
# ADR-0164: Fund offspring from a distinct inherited genome
|
||||||
|
|
||||||
|
## Status and scope
|
||||||
|
|
||||||
|
Accepted for the first portable biology implementation segment of ADR-0163,
|
||||||
|
2026-10-19. Extends ADR-0032/0125/0137. This is a complete pure funding proposal,
|
||||||
|
not admission of new owner rules, stored heritable state or player succession.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
Add `fund_offspring(parent, offspring, growth, reserve, temperature, share)` and
|
||||||
|
`offspring_cost(parent, offspring, temperature, share)` to the existing biology
|
||||||
|
budding API. Both genomes are immutable validated records. Require equal schema
|
||||||
|
and development versions in this first adapter. Refuse a reused genome ID with
|
||||||
|
different contents. Archive ancestry, authority, placement and durable publication
|
||||||
|
remain the caller's responsibility; a cost proposal grants none of those rights.
|
||||||
|
|
||||||
|
The expressed parent determines reproductive capability, grown/undamaged
|
||||||
|
eligibility, and the existing reproduction investment, including construction
|
||||||
|
heat and any admitted reproduction-skill coefficient. Divide that investment
|
||||||
|
channelwise by `share` exactly as existing twins do; remainders stay with the parent.
|
||||||
|
The offspring genome determines its own body, birth growth and energy provision.
|
||||||
|
Select the largest growth in 1..1000 whose body fits every investment matter
|
||||||
|
channel. Remaining invested matter is child reserve. The parent additionally
|
||||||
|
funds 30 seconds of that child's own full demand at its birth growth. This uses
|
||||||
|
the existing trial provisioning constant, not an adult-body or survival grant.
|
||||||
|
|
||||||
|
As before, refuse if the largest body's full provision is unaffordable; do not
|
||||||
|
silently select a smaller child to reduce that energy bill. A non-reproducing
|
||||||
|
offspring is permitted if the reproductive parent can construct it. A parent
|
||||||
|
without reproduction cannot use a reproductive child's capabilities to bud.
|
||||||
|
Cross-schema/development reproduction is explicitly unsupported pending a later
|
||||||
|
versioned conversion contract, rather than mixing construction laws implicitly.
|
||||||
|
|
||||||
|
Every channel closes exactly:
|
||||||
|
|
||||||
|
`parent reserve before = parent reserve after + child body + child reserve + heat`
|
||||||
|
|
||||||
|
Heat has energy only and body has matter only. The parent body is never spent or
|
||||||
|
rebuilt. Inputs remain unchanged, and refusals return no partial transition.
|
||||||
|
Cost uses the same funding path against a bounded ample reserve; exact shown
|
||||||
|
cost funds the proposal and one-unit shortage in any required channel refuses.
|
||||||
|
The shared investment and fixed tissue composition bound all supported genomes
|
||||||
|
well below that ample value. Unsupported or impossible proposals have no cost.
|
||||||
|
|
||||||
|
Existing `fund_bud` and `bud_cost` delegate with the same genome in both roles.
|
||||||
|
All old signatures, numerical behavior, rule meanings and golden bytes remain.
|
||||||
|
No dependency, library boundary or existing codec changes.
|
||||||
|
|
||||||
|
## Alternatives, benefits, costs and risks
|
||||||
|
|
||||||
|
Rebuilding the parent into the selected child form violates ADR-0163. Pricing
|
||||||
|
the entire proposal from the child would let it supply reproductive capability
|
||||||
|
or change the parent's already expressed investment. Copying the old parent body
|
||||||
|
into a differently shaped child can fail elemental composition and geometry.
|
||||||
|
Separating the two derivations supplies an actual funded biological operation
|
||||||
|
without introducing a second balance or arbitrary mutation fee.
|
||||||
|
|
||||||
|
The cost is two explicit genome inputs and an incompatible-genome refusal.
|
||||||
|
This adapter retains existing reproduction/rounding limitations; it does not
|
||||||
|
select final balance, new morphology, heredity timing or a future hybrid species
|
||||||
|
model. Funding a possible newborn does not prove mature ecological viability.
|
||||||
|
|
||||||
|
## Qualification and next boundaries
|
||||||
|
|
||||||
|
Check old same-genome equality across supported founders, distinct membrane/size
|
||||||
|
and demand variants, maximal feasible growth, all-channel closure and shortages,
|
||||||
|
twins, sterile children, parent eligibility, incompatible versions and reused IDs.
|
||||||
|
Retain real archive parent/child links through a codec round-trip without changing
|
||||||
|
the parent's expressed genome. Tests run under NDEBUG, analysis and ASan/UBSan.
|
||||||
|
|
||||||
|
Next define and implement versioned expressed/heritable owner state, operator
|
||||||
|
expression timing and retained plan history, then atomic birth/control choice,
|
||||||
|
bounded persistent NPC behavior and readable birth UI. Current default/DEV rules
|
||||||
|
continue exact-copy budding; SQL admission, census, migration and old snapshots
|
||||||
|
do not acquire these features by accepting this pure operation.
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
# Architecture decision records
|
# Architecture decision records
|
||||||
|
|
||||||
|
- [ADR-0164: Distinct-genome offspring funding](0164-distinct-genome-offspring-funding.md) - pure funded reproduction separates the expressed parent's investment from the inherited child's anatomy and provision; old same-genome behavior retained, owner/control integration pending.
|
||||||
|
|
||||||
- [ADR-0163: Structural inheritance and one-way offspring succession](0163-structural-inheritance-and-offspring-succession.md) - maintainer-accepted target gameplay: offspring structural traits, irreversible birth-time control choice and NPC-parent behavior/reproductive continuity; implementation pending.
|
- [ADR-0163: Structural inheritance and one-way offspring succession](0163-structural-inheritance-and-offspring-succession.md) - maintainer-accepted target gameplay: offspring structural traits, irreversible birth-time control choice and NPC-parent behavior/reproductive continuity; implementation pending.
|
||||||
|
|
||||||
- [ADR-0162: Bounded unscripted wildlife generations](0162-bounded-unscripted-wildlife-generations.md) - a predeclared finite player-origin raw/cohort measurement with production controller, hold-outs and controls; no biological or deployment change.
|
- [ADR-0162: Bounded unscripted wildlife generations](0162-bounded-unscripted-wildlife-generations.md) - a predeclared finite player-origin raw/cohort measurement with production controller, hold-outs and controls; no biological or deployment change.
|
||||||
|
|||||||
@@ -22,6 +22,22 @@ be implemented before this behavior is offered. Choice timing and pause policy
|
|||||||
remain explicit implementation decisions. The M11 decisions and diagram below
|
remain explicit implementation decisions. The M11 decisions and diagram below
|
||||||
describe the old baseline, not a prohibition on the accepted target behavior.
|
describe the old baseline, not a prohibition on the accepted target behavior.
|
||||||
|
|
||||||
|
## Implemented portable offspring funding
|
||||||
|
|
||||||
|
[ADR-0164](../adr/0164-distinct-genome-offspring-funding.md) implements
|
||||||
|
`fund_offspring` and `offspring_cost` in the biology budding API. The expressed
|
||||||
|
parent supplies reproductive eligibility and its own investment; a distinct
|
||||||
|
inherited genome supplies the child's body, largest feasible birth growth and
|
||||||
|
starting demand. Every elemental channel and energy close exactly. The parent
|
||||||
|
is not rebuilt. Changed schema/development laws and conflicting same-ID genomes
|
||||||
|
refuse. Two share-funded children cannot manufacture the parent's invested matter.
|
||||||
|
|
||||||
|
Tests cover changed anatomy and demand, sterile children, exact cost/shortages,
|
||||||
|
twins and retained archive identities. Existing same-genome helpers delegate to
|
||||||
|
this operation with identical parent/child inputs. This is a pure proposal;
|
||||||
|
stored heritable state, mutation expression timing, succession, NPC behavior and
|
||||||
|
birth UI remain unimplemented. Current live rules still produce exact-copy buds.
|
||||||
|
|
||||||
## Historical M11 baseline and open strategies
|
## Historical M11 baseline and open strategies
|
||||||
|
|
||||||
Locked: irreversible death, independent descendants and no offline progression.
|
Locked: irreversible death, independent descendants and no offline progression.
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ control and census state do not implement that target. These require coordinated
|
|||||||
versioned biology, authority, recovery and UI work; earlier exact-copy generation
|
versioned biology, authority, recovery and UI work; earlier exact-copy generation
|
||||||
evidence does not close that gap or establish the intended generational gameplay.
|
evidence does not close that gap or establish the intended generational gameplay.
|
||||||
|
|
||||||
|
[ADR-0164](../adr/0164-distinct-genome-offspring-funding.md) now implements the
|
||||||
|
pure biological funding step with distinct parent/offspring genomes and exact
|
||||||
|
closure. Existing same-genome behavior remains. Persistent heritable plans,
|
||||||
|
expression timing, authority handoff and NPC/UI integration are still required.
|
||||||
|
|
||||||
## Persistence boundary resolved by 12.3b
|
## Persistence boundary resolved by 12.3b
|
||||||
|
|
||||||
ADR-0142 adds dedicated profile 5, population trace 1 and schema 44; raw profile 4
|
ADR-0142 adds dedicated profile 5, population trace 1 and schema 44; raw profile 4
|
||||||
|
|||||||
@@ -1,5 +1,37 @@
|
|||||||
# Validation report
|
# Validation report
|
||||||
|
|
||||||
|
## 2026-10-19 - Distinct-genome offspring funding
|
||||||
|
|
||||||
|
[ADR-0164](../adr/0164-distinct-genome-offspring-funding.md) adds a complete pure
|
||||||
|
funding proposal with distinct expressed-parent and inherited-child genomes. The
|
||||||
|
parent pays its own admitted investment; child anatomy, largest feasible birth
|
||||||
|
growth and provision come from the child's genome. Old helpers delegate with
|
||||||
|
the same genome in both roles. No owner/save/rules, default opening, SQL or live
|
||||||
|
gameplay changes; stored plans and control succession are still pending.
|
||||||
|
|
||||||
|
Executed locally:
|
||||||
|
|
||||||
|
- MSVC 19.44 Release full CTest **83/83 passed, 20.65 s**, with NDEBUG.
|
||||||
|
- GCC 14.2 Release full CTest **83/83 passed, 15.06 s**, with NDEBUG.
|
||||||
|
- Clang 19.1 ASan/UBSan budding, distinct-genome offspring and funded maturation
|
||||||
|
tests **3/3 passed, 30.76 s**, without sanitizer reports.
|
||||||
|
- clang-tidy 19 on implementation and tests, repository clang-format 19 and diff
|
||||||
|
whitespace checks pass. Initial test analysis caught an optional dereference
|
||||||
|
hidden behind a test macro; an explicit runtime guard resolves it. Refusal
|
||||||
|
checks guard `expected::error()` under NDEBUG as well.
|
||||||
|
|
||||||
|
Tests cover distinct membrane/size and movement-demand plans, largest funded
|
||||||
|
growth, exact cost and each channel shortage, twin investment, sterile offspring,
|
||||||
|
parent capability/growth/damage, impossible anatomy, schema/development mismatch,
|
||||||
|
same-ID conflict, sibling plan round-trip and retained archive parent/child
|
||||||
|
identity. All old tests/golden meanings remain. No private database rerun: the new
|
||||||
|
mixed-genome path is not admitted by the existing cellular owner or SQL bundle.
|
||||||
|
|
||||||
|
The required DEV window in this push expires **2026-10-19 21:09:13 UTC**.
|
||||||
|
Rendered policy passes: 75 objects in 74 files, 138 rendered objects in 17 overlays,
|
||||||
|
zero failures. The unchanged policy self-test matrix was not repeated. No live
|
||||||
|
deployment or World0 operation was performed.
|
||||||
|
|
||||||
## 2026-10-19 - Accepted structural inheritance and birth succession direction
|
## 2026-10-19 - Accepted structural inheritance and birth succession direction
|
||||||
|
|
||||||
[ADR-0163](../adr/0163-structural-inheritance-and-offspring-succession.md) records
|
[ADR-0163](../adr/0163-structural-inheritance-and-offspring-succession.md) records
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ enum class BuddingError : std::uint8_t {
|
|||||||
no_capability, // The genome cannot reproduce.
|
no_capability, // The genome cannot reproduce.
|
||||||
not_grown, // The parent is not fully realized, or is damaged.
|
not_grown, // The parent is not fully realized, or is damaged.
|
||||||
insufficient_funding, // Some channel of investment plus provision is missing.
|
insufficient_funding, // Some channel of investment plus provision is missing.
|
||||||
development // The genome's rules cannot develop it.
|
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
|
// Pure and deterministic. On every channel the parent's reserve before equals its reserve
|
||||||
@@ -37,6 +38,18 @@ enum class BuddingError : std::uint8_t {
|
|||||||
fund_bud(const Genome& genome, GrowthState parent_growth,
|
fund_bud(const Genome& genome, GrowthState parent_growth,
|
||||||
const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin,
|
const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin,
|
||||||
std::uint32_t share = 1);
|
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
|
// 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
|
// (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
|
// bud's provision; exactly what `fund_bud` charges such a parent. Nullopt when the genome
|
||||||
|
|||||||
+21
-2
@@ -18,6 +18,18 @@ std::expected<BudTransition, BuddingError> fund_bud(const Genome& genome, Growth
|
|||||||
const accounting::Inventory& parent_reserve,
|
const accounting::Inventory& parent_reserve,
|
||||||
std::uint32_t temperature_millikelvin,
|
std::uint32_t temperature_millikelvin,
|
||||||
std::uint32_t share) {
|
std::uint32_t share) {
|
||||||
|
return fund_offspring(genome, genome, parent_growth, parent_reserve, temperature_millikelvin,
|
||||||
|
share);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::expected<BudTransition, BuddingError>
|
||||||
|
fund_offspring(const Genome& genome, const Genome& offspring, GrowthState parent_growth,
|
||||||
|
const accounting::Inventory& parent_reserve, std::uint32_t temperature_millikelvin,
|
||||||
|
std::uint32_t share) {
|
||||||
|
if (genome.schema_version() != offspring.schema_version() ||
|
||||||
|
genome.development_version() != offspring.development_version() ||
|
||||||
|
(genome.id() == offspring.id() && genome != offspring))
|
||||||
|
return std::unexpected{BuddingError::incompatible_genome};
|
||||||
if (share == 0)
|
if (share == 0)
|
||||||
return std::unexpected{BuddingError::no_capability};
|
return std::unexpected{BuddingError::no_capability};
|
||||||
if (!genome.carries(Capability::reproduction))
|
if (!genome.carries(Capability::reproduction))
|
||||||
@@ -47,7 +59,7 @@ std::expected<BudTransition, BuddingError> fund_bud(const Genome& genome, Growth
|
|||||||
// channel. Bodies grow with realized growth, so the scan stops at the first fit.
|
// channel. Bodies grow with realized growth, so the scan stops at the first fit.
|
||||||
for (std::uint32_t realized = 1000; realized > 0; --realized) {
|
for (std::uint32_t realized = 1000; realized > 0; --realized) {
|
||||||
const GrowthState growth{realized, 0};
|
const GrowthState growth{realized, 0};
|
||||||
const auto bud = metabolic_budget(genome, growth, {temperature_millikelvin, {}});
|
const auto bud = metabolic_budget(offspring, growth, {temperature_millikelvin, {}});
|
||||||
if (!bud)
|
if (!bud)
|
||||||
return std::unexpected{BuddingError::development};
|
return std::unexpected{BuddingError::development};
|
||||||
accounting::Inventory body_only = bud->body;
|
accounting::Inventory body_only = bud->body;
|
||||||
@@ -88,13 +100,20 @@ std::expected<BudTransition, BuddingError> fund_bud(const Genome& genome, Growth
|
|||||||
|
|
||||||
std::optional<accounting::Inventory> bud_cost(const Genome& genome,
|
std::optional<accounting::Inventory> bud_cost(const Genome& genome,
|
||||||
std::uint32_t temperature_millikelvin) {
|
std::uint32_t temperature_millikelvin) {
|
||||||
|
return offspring_cost(genome, genome, temperature_millikelvin);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<accounting::Inventory> offspring_cost(const Genome& parent, const Genome& offspring,
|
||||||
|
std::uint32_t temperature_millikelvin,
|
||||||
|
std::uint32_t share) {
|
||||||
// Fund against an ample reserve and read the charge: one code path decides both.
|
// Fund against an ample reserve and read the charge: one code path decides both.
|
||||||
constexpr std::uint64_t ample = std::uint64_t{1} << 60U;
|
constexpr std::uint64_t ample = std::uint64_t{1} << 60U;
|
||||||
const accounting::Inventory unlimited{
|
const accounting::Inventory unlimited{
|
||||||
{ample},
|
{ample},
|
||||||
{accounting::Femtograms{ample}, accounting::Femtograms{ample},
|
{accounting::Femtograms{ample}, accounting::Femtograms{ample},
|
||||||
accounting::Femtograms{ample}, accounting::Femtograms{ample}}};
|
accounting::Femtograms{ample}, accounting::Femtograms{ample}}};
|
||||||
const auto funded = fund_bud(genome, {1000, 0}, unlimited, temperature_millikelvin);
|
const auto funded =
|
||||||
|
fund_offspring(parent, offspring, {1000, 0}, unlimited, temperature_millikelvin, share);
|
||||||
if (!funded)
|
if (!funded)
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
accounting::Inventory cost;
|
accounting::Inventory cost;
|
||||||
|
|||||||
@@ -0,0 +1,209 @@
|
|||||||
|
#include "evo/biology/budding.hpp"
|
||||||
|
#include "evo/biology/founder.hpp"
|
||||||
|
#include "evo/biology/lineage.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
|
#include <optional>
|
||||||
|
#include <source_location>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
using namespace evo::biology;
|
||||||
|
using namespace evo::accounting;
|
||||||
|
void check(bool condition, std::source_location location = std::source_location::current()) {
|
||||||
|
if (!condition)
|
||||||
|
throw std::runtime_error("offspring line " + std::to_string(location.line()));
|
||||||
|
}
|
||||||
|
#define CHECK(expression) check(static_cast<bool>(expression))
|
||||||
|
template <typename T, typename E> T checked(std::expected<T, E> result) {
|
||||||
|
CHECK(result);
|
||||||
|
return *result;
|
||||||
|
}
|
||||||
|
bool refuses(const std::expected<BudTransition, BuddingError>& result, BuddingError error) {
|
||||||
|
return !result && result.error() == error;
|
||||||
|
}
|
||||||
|
constexpr std::uint32_t temperate = 293'150;
|
||||||
|
Inventory plenty() {
|
||||||
|
constexpr std::uint64_t lots = 1'000'000'000'000;
|
||||||
|
return {{lots}, {Femtograms{lots}, Femtograms{lots}, Femtograms{lots}, Femtograms{lots}}};
|
||||||
|
}
|
||||||
|
GenomeDraft draft(const Genome& parent, std::uint64_t id) {
|
||||||
|
return {id,
|
||||||
|
id,
|
||||||
|
parent.development_version(),
|
||||||
|
{parent.id()},
|
||||||
|
{parent.capabilities().begin(), parent.capabilities().end()},
|
||||||
|
parent.schema_version()};
|
||||||
|
}
|
||||||
|
Genome variant(const Genome& parent, std::uint64_t id, Capability target,
|
||||||
|
std::optional<std::uint32_t> parameter) {
|
||||||
|
auto change = draft(parent, id);
|
||||||
|
if (!parameter)
|
||||||
|
std::erase_if(change.capabilities, [target](auto record) { return record.kind == target; });
|
||||||
|
else {
|
||||||
|
const auto found = std::ranges::find(change.capabilities, target, &CapabilityRecord::kind);
|
||||||
|
CHECK(found != change.capabilities.end());
|
||||||
|
found->parameter = *parameter;
|
||||||
|
}
|
||||||
|
return checked(Genome::create(change));
|
||||||
|
}
|
||||||
|
void conservation(const Inventory& before, const BudTransition& result) {
|
||||||
|
CHECK(result.body.energy.value == 0);
|
||||||
|
CHECK(before.energy.value ==
|
||||||
|
result.parent_reserve.energy.value + result.reserve.energy.value + result.heat.value);
|
||||||
|
for (std::size_t channel = 0; channel < before.matter.size(); ++channel)
|
||||||
|
CHECK(before.matter[channel].value == result.parent_reserve.matter[channel].value +
|
||||||
|
result.body.matter[channel].value +
|
||||||
|
result.reserve.matter[channel].value);
|
||||||
|
}
|
||||||
|
void verify_pair(const Genome& parent, const Genome& child, std::uint32_t share) {
|
||||||
|
const auto parent_bytes = parent.encode();
|
||||||
|
const auto child_bytes = child.encode();
|
||||||
|
const auto reserve = plenty();
|
||||||
|
const auto result =
|
||||||
|
checked(fund_offspring(parent, child, {1000, 0}, reserve, temperate, share));
|
||||||
|
conservation(reserve, result);
|
||||||
|
const auto investment =
|
||||||
|
checked(metabolic_budget(parent, {1000, 0}, {temperate, {}})).reproduction_investment;
|
||||||
|
const auto developed = checked(metabolic_budget(child, result.growth, {temperate, {}}));
|
||||||
|
CHECK(result.body == developed.body);
|
||||||
|
CHECK(result.heat.value == investment.energy.value / share);
|
||||||
|
CHECK(result.reserve.energy.value ==
|
||||||
|
developed.demand.value * bud_provision_seconds * 1'000'000 / developed.rate_microseconds);
|
||||||
|
for (std::size_t channel = 0; channel < reserve.matter.size(); ++channel)
|
||||||
|
CHECK(result.body.matter[channel].value + result.reserve.matter[channel].value ==
|
||||||
|
investment.matter[channel].value / share);
|
||||||
|
if (result.growth.realized_per_thousand < 1000) {
|
||||||
|
const auto larger = checked(
|
||||||
|
metabolic_budget(child, {result.growth.realized_per_thousand + 1, 0}, {temperate, {}}));
|
||||||
|
bool does_not_fit = false;
|
||||||
|
for (std::size_t channel = 0; channel < reserve.matter.size(); ++channel)
|
||||||
|
does_not_fit |=
|
||||||
|
larger.body.matter[channel].value > investment.matter[channel].value / share;
|
||||||
|
CHECK(does_not_fit);
|
||||||
|
}
|
||||||
|
const auto cost = offspring_cost(parent, child, temperate, share);
|
||||||
|
if (!cost)
|
||||||
|
throw std::runtime_error("offspring has no exact cost");
|
||||||
|
const auto exact = checked(fund_offspring(parent, child, {1000, 0}, *cost, temperate, share));
|
||||||
|
conservation(*cost, exact);
|
||||||
|
CHECK(exact.parent_reserve == Inventory{} && exact.body == result.body &&
|
||||||
|
exact.growth == result.growth && exact.reserve == result.reserve);
|
||||||
|
for (std::size_t channel = 0; channel < 5; ++channel) {
|
||||||
|
auto short_one = *cost;
|
||||||
|
auto& value = channel == 0 ? short_one.energy.value : short_one.matter[channel - 1].value;
|
||||||
|
if (value == 0)
|
||||||
|
continue;
|
||||||
|
--value;
|
||||||
|
if (channel != 0)
|
||||||
|
short_one.energy.value = std::numeric_limits<std::uint64_t>::max();
|
||||||
|
const auto before = short_one;
|
||||||
|
const auto refused = fund_offspring(parent, child, {1000, 0}, short_one, temperate, share);
|
||||||
|
CHECK(!refused && refused.error() == BuddingError::insufficient_funding);
|
||||||
|
CHECK(short_one == before);
|
||||||
|
}
|
||||||
|
CHECK(parent.encode() == parent_bytes && child.encode() == child_bytes);
|
||||||
|
CHECK(fund_offspring(parent, child, {1000, 0}, reserve, temperate, share) == result);
|
||||||
|
}
|
||||||
|
void distinct_anatomy_and_demand() {
|
||||||
|
const auto parent = checked(primitive_founder(5, 5, primitive_founder_v3));
|
||||||
|
const auto thicker = variant(parent, 6, Capability::membrane, 2);
|
||||||
|
const auto inherited = checked(fund_offspring(parent, thicker, {1000, 0}, plenty(), temperate));
|
||||||
|
const auto copied = checked(fund_bud(parent, {1000, 0}, plenty(), temperate));
|
||||||
|
CHECK(inherited.body != copied.body);
|
||||||
|
CHECK(inherited.growth != copied.growth);
|
||||||
|
for (const auto share : {1U, 2U}) {
|
||||||
|
verify_pair(parent, thicker, share);
|
||||||
|
verify_pair(parent, variant(parent, 7, Capability::target_size, 80'000'000), share);
|
||||||
|
verify_pair(parent, variant(parent, 8, Capability::movement, 40'000), share);
|
||||||
|
verify_pair(parent, variant(parent, 9, Capability::reproduction, std::nullopt), share);
|
||||||
|
}
|
||||||
|
// Two share-2 offspring spend at most the same parent matter investment.
|
||||||
|
const auto first = checked(fund_offspring(parent, thicker, {1000, 0}, plenty(), temperate, 2));
|
||||||
|
const auto second =
|
||||||
|
checked(fund_offspring(parent, thicker, {1000, 0}, first.parent_reserve, temperate, 2));
|
||||||
|
conservation(first.parent_reserve, second);
|
||||||
|
CHECK(first.body == second.body && first.growth == second.growth);
|
||||||
|
const auto investment =
|
||||||
|
checked(metabolic_budget(parent, {1000, 0}, {temperate, {}})).reproduction_investment;
|
||||||
|
for (std::size_t channel = 0; channel < 4; ++channel)
|
||||||
|
CHECK(plenty().matter[channel].value - second.parent_reserve.matter[channel].value <=
|
||||||
|
investment.matter[channel].value);
|
||||||
|
}
|
||||||
|
void compatibility_and_parent_eligibility() {
|
||||||
|
const auto parent = checked(primitive_founder(5, 5, primitive_founder_v3));
|
||||||
|
const auto child = variant(parent, 6, Capability::membrane, 2);
|
||||||
|
const auto sterile = variant(parent, 7, Capability::reproduction, std::nullopt);
|
||||||
|
CHECK(refuses(fund_offspring(sterile, child, {1000, 0}, plenty(), temperate),
|
||||||
|
BuddingError::no_capability));
|
||||||
|
CHECK(refuses(fund_offspring(parent, child, {999, 0}, plenty(), temperate),
|
||||||
|
BuddingError::not_grown));
|
||||||
|
CHECK(refuses(fund_offspring(parent, child, {1000, 1}, plenty(), temperate),
|
||||||
|
BuddingError::not_grown));
|
||||||
|
CHECK(refuses(fund_offspring(parent, child, {1000, 0}, plenty(), temperate, 0),
|
||||||
|
BuddingError::no_capability));
|
||||||
|
CHECK(!offspring_cost(sterile, child, temperate));
|
||||||
|
CHECK(!offspring_cost(parent, child, temperate, 0));
|
||||||
|
auto incompatible = draft(child, 8);
|
||||||
|
incompatible.schema_version = genome_schema_v3;
|
||||||
|
auto refused = fund_offspring(parent, checked(Genome::create(incompatible)), {1000, 0},
|
||||||
|
plenty(), temperate);
|
||||||
|
CHECK(!refused && refused.error() == BuddingError::incompatible_genome);
|
||||||
|
incompatible = draft(child, 9);
|
||||||
|
incompatible.development_version = 3;
|
||||||
|
CHECK(refuses(fund_offspring(parent, checked(Genome::create(incompatible)), {1000, 0}, plenty(),
|
||||||
|
temperate),
|
||||||
|
BuddingError::incompatible_genome));
|
||||||
|
auto alias = draft(child, parent.id());
|
||||||
|
alias.parents.clear();
|
||||||
|
CHECK(refuses(
|
||||||
|
fund_offspring(parent, checked(Genome::create(alias)), {1000, 0}, plenty(), temperate),
|
||||||
|
BuddingError::incompatible_genome));
|
||||||
|
const auto huge = variant(parent, 10, Capability::target_size, 1'000'000'000);
|
||||||
|
const auto unbuildable = variant(huge, 11, Capability::membrane, 10'000);
|
||||||
|
refused = fund_offspring(parent, unbuildable, {1000, 0}, plenty(), temperate);
|
||||||
|
CHECK(!refused && refused.error() == BuddingError::insufficient_funding);
|
||||||
|
CHECK(!offspring_cost(parent, unbuildable, temperate));
|
||||||
|
}
|
||||||
|
void old_founders_and_archive_identity() {
|
||||||
|
for (const auto version : {primitive_founder_v1, primitive_founder_v2, primitive_founder_v3}) {
|
||||||
|
const auto parent = checked(primitive_founder(5, 5, version));
|
||||||
|
for (const auto share : {1U, 2U})
|
||||||
|
CHECK(fund_bud(parent, {1000, 0}, plenty(), temperate, share) ==
|
||||||
|
fund_offspring(parent, parent, {1000, 0}, plenty(), temperate, share));
|
||||||
|
CHECK(bud_cost(parent, temperate) == offspring_cost(parent, parent, temperate));
|
||||||
|
}
|
||||||
|
const auto parent = checked(primitive_founder(5, 5, primitive_founder_v3));
|
||||||
|
const auto plan = variant(parent, 6, Capability::membrane, 2);
|
||||||
|
const auto restored_plan = checked(Genome::decode(plan.encode()));
|
||||||
|
const auto first = checked(fund_offspring(parent, plan, {1000, 0}, plenty(), temperate));
|
||||||
|
const auto sibling =
|
||||||
|
checked(fund_offspring(parent, restored_plan, {1000, 0}, first.parent_reserve, temperate));
|
||||||
|
CHECK(first.body == sibling.body && first.growth == sibling.growth);
|
||||||
|
LineageArchive archive;
|
||||||
|
CHECK(archive.admit(parent));
|
||||||
|
CHECK(archive.admit(plan));
|
||||||
|
CHECK(archive.record_birth(100, parent.id(), {0}));
|
||||||
|
CHECK(archive.record_birth(101, plan.id(), {1}));
|
||||||
|
CHECK(archive.record_birth(102, plan.id(), {2}));
|
||||||
|
const auto restored = checked(LineageArchive::decode(archive.encode()));
|
||||||
|
CHECK(checked(restored.current_genome(100)) == parent.id());
|
||||||
|
CHECK(checked(restored.current_genome(101)) == plan.id());
|
||||||
|
CHECK(checked(restored.current_genome(102)) == plan.id());
|
||||||
|
CHECK(checked(restored.common_ancestor(parent.id(), plan.id())) == parent.id());
|
||||||
|
CHECK(checked(restored.living_carriers(parent.id())) == 1);
|
||||||
|
CHECK(checked(restored.living_carriers(plan.id())) == 2);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
int main() try {
|
||||||
|
distinct_anatomy_and_demand();
|
||||||
|
compatibility_and_parent_eligibility();
|
||||||
|
old_founders_and_archive_identity();
|
||||||
|
return 0;
|
||||||
|
} catch (const std::exception& error) {
|
||||||
|
std::cerr << error.what() << '\n';
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user