Add funded reproduction with retained lineage identity
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>
This commit is contained in:
+172
-1
@@ -268,6 +268,174 @@ void ordered_replay() {
|
||||
CHECK(sum(*community) == bundle(maximum));
|
||||
}
|
||||
}
|
||||
void funded_reproduction() {
|
||||
const std::array configs{ConsumerConfig{bundle(100), bundle(100), 1000}};
|
||||
auto community =
|
||||
FeedingCommunity::create(producer(), {100}, bundle(20).matter, configs, {}, {2, 750, {}});
|
||||
CHECK(community);
|
||||
const auto total = sum(*community);
|
||||
// Four producer reservoirs, one consumer, two reserved slots and waste.
|
||||
CHECK(community->balances().size() == 8);
|
||||
CHECK(*community->born(2) && !*community->born(3) && !*community->born(4));
|
||||
CHECK(!community->corpse(3) && community->corpse(3).error() == FeedingError::unborn_actor);
|
||||
CHECK(!community->parent(3) && community->parent(3).error() == FeedingError::unborn_actor);
|
||||
CHECK(!community->origin(4) && community->origin(4).error() == FeedingError::unborn_actor);
|
||||
CHECK(community->parent(2) && *community->parent(2) == 0);
|
||||
CHECK(community->origin(2) && community->origin(2)->value == 0);
|
||||
const std::array early{FeedIntent{1, 2, 3, bundle(1)}};
|
||||
const auto denied = community->advance(evo::Tick{1}, early);
|
||||
CHECK(!denied && denied.error() == FeedingError::unborn_actor);
|
||||
// 750/1000 of eight units endows six; the remainder is real heat and waste.
|
||||
const std::array birth{ReproduceIntent{1, 2, bundle(8)}};
|
||||
CHECK(community->advance(evo::Tick{1}, {}, {}, birth));
|
||||
CHECK(community->last_births().size() == 1);
|
||||
CHECK(community->last_births()[0] == (ReproduceReceipt{1, 3, bundle(6), bundle(2)}));
|
||||
CHECK(community->balances()[4] == bundle(92) && community->balances()[5] == bundle(6));
|
||||
CHECK(community->balances()[3].energy.value == 4); // Growth heat plus construction heat.
|
||||
CHECK(community->balances().back() == (Inventory{{}, bundle(2).matter}));
|
||||
CHECK(*community->born(3) && *community->active(3));
|
||||
CHECK(*community->parent(3) == 2 && community->origin(3)->value == 1);
|
||||
CHECK(sum(*community) == total);
|
||||
// The child acts from the next tick using its duplicated parent configuration.
|
||||
const std::array meal{FeedIntent{1, 3, 2, bundle(1)}};
|
||||
CHECK(community->advance(evo::Tick{2}, meal));
|
||||
CHECK(community->balances()[4] == bundle(91) && community->balances()[5] == bundle(7));
|
||||
CHECK(community->last_births().empty() && sum(*community) == total);
|
||||
}
|
||||
void reproduction_limits_and_rollback() {
|
||||
const std::array configs{ConsumerConfig{bundle(100), bundle(100), 1000}};
|
||||
auto community = FeedingCommunity::create(producer(), {100}, bundle(20).matter, configs, {},
|
||||
{1, 1000, bundle(10)});
|
||||
CHECK(community);
|
||||
const auto before = copy(*community);
|
||||
const auto progress = community->progress();
|
||||
const auto reject = [&](std::span<const ReproduceIntent> births, FeedingError expected) {
|
||||
const auto result = community->advance(evo::Tick{1}, {}, {}, births);
|
||||
CHECK(!result && result.error() == expected);
|
||||
CHECK(copy(*community) == before && community->progress() == progress);
|
||||
CHECK(community->last_births().empty() && *community->active(2) && !*community->born(3));
|
||||
};
|
||||
const std::array small{ReproduceIntent{1, 2, bundle(9)}};
|
||||
reject(small, FeedingError::invalid_endowment); // Below the configured endowment floor.
|
||||
const std::array nothing{ReproduceIntent{1, 2, {}}};
|
||||
reject(nothing, FeedingError::invalid_endowment);
|
||||
const std::array huge{ReproduceIntent{1, 2, bundle(101)}};
|
||||
reject(huge, FeedingError::insufficient_inventory);
|
||||
const std::array reserved{ReproduceIntent{1, 3, bundle(10)}};
|
||||
reject(reserved, FeedingError::unborn_actor);
|
||||
for (const auto parent : {0U, 1U, 99U}) {
|
||||
const std::array invalid{ReproduceIntent{1, parent, bundle(10)}};
|
||||
reject(invalid, FeedingError::invalid_batch);
|
||||
}
|
||||
const std::array unsequenced{ReproduceIntent{0, 2, bundle(10)}};
|
||||
reject(unsequenced, FeedingError::invalid_batch);
|
||||
const std::array twice{ReproduceIntent{1, 2, bundle(10)}, ReproduceIntent{2, 2, bundle(10)}};
|
||||
reject(twice, FeedingError::invalid_batch); // One funded birth per parent per tick.
|
||||
const std::vector<ReproduceIntent> many(max_consumers + 1, ReproduceIntent{1, 2, bundle(10)});
|
||||
reject(many, FeedingError::invalid_batch);
|
||||
// Energy is abundant but one element is not; the whole tick must roll back.
|
||||
const std::array starved{ConsumerConfig{{{1000}, {Femtograms{1}}}, {}, 0}};
|
||||
auto scarce = FeedingCommunity::create(producer(), {}, {}, starved, {}, {1, 1000, {}});
|
||||
CHECK(scarce);
|
||||
const auto opening = copy(*scarce);
|
||||
const std::array unfunded{ReproduceIntent{1, 2, {{10}, {Femtograms{2}}}}};
|
||||
const auto refused = scarce->advance(evo::Tick{1}, {}, {}, unfunded);
|
||||
CHECK(!refused && refused.error() == FeedingError::insufficient_inventory);
|
||||
CHECK(copy(*scarce) == opening && !*scarce->born(3));
|
||||
const std::array affordable{ReproduceIntent{1, 2, {{10}, {Femtograms{1}}}}};
|
||||
CHECK(scarce->advance(evo::Tick{1}, {}, {}, affordable));
|
||||
const std::array pair{ConsumerConfig{bundle(100), bundle(100), 1000},
|
||||
ConsumerConfig{bundle(100), bundle(100), 1000}};
|
||||
auto limited =
|
||||
FeedingCommunity::create(producer(), {100}, bundle(20).matter, pair, {}, {1, 1000, {}});
|
||||
CHECK(limited);
|
||||
const auto available = copy(*limited);
|
||||
const std::array both{ReproduceIntent{1, 2, bundle(10)}, ReproduceIntent{2, 3, bundle(10)}};
|
||||
const auto overflowing = limited->advance(evo::Tick{1}, {}, {}, both);
|
||||
CHECK(!overflowing && overflowing.error() == FeedingError::no_capacity);
|
||||
CHECK(copy(*limited) == available); // Capacity rejects; it never funds a smaller child.
|
||||
const std::array single{ReproduceIntent{1, 2, bundle(10)}};
|
||||
CHECK(limited->advance(evo::Tick{1}, {}, {}, single));
|
||||
CHECK(limited->last_births()[0].child == 4);
|
||||
const std::array queued{ReproduceIntent{1, 3, bundle(10)}};
|
||||
const auto full = limited->advance(evo::Tick{2}, {}, {}, queued);
|
||||
CHECK(!full && full.error() == FeedingError::no_capacity);
|
||||
const std::array death{TerminalEvent{2}};
|
||||
CHECK(limited->advance(evo::Tick{2}, {}, death));
|
||||
const auto orphaned = limited->advance(evo::Tick{3}, {}, {}, single);
|
||||
CHECK(!orphaned && orphaned.error() == FeedingError::inactive_actor);
|
||||
CHECK(*limited->parent(4) == 2 && limited->origin(4)->value == 1);
|
||||
CHECK(!*limited->active(2) && *limited->parent(2) == 0); // Ancestry outlives the parent.
|
||||
}
|
||||
void lineage_identity_and_permutation() {
|
||||
const std::array configs{ConsumerConfig{bundle(100), bundle(100), 1000}};
|
||||
auto community =
|
||||
FeedingCommunity::create(producer(), {}, {}, configs, {bundle(1000)}, {2, 1000, {}});
|
||||
CHECK(community);
|
||||
const auto total = sum(*community);
|
||||
const std::array first{ReproduceIntent{1, 2, bundle(10)}};
|
||||
CHECK(community->advance(evo::Tick{1}, {}, {}, first));
|
||||
CHECK(community->last_births()[0].child == 3);
|
||||
const std::array kill{TerminalEvent{3}};
|
||||
CHECK(community->advance(evo::Tick{2}, {}, kill));
|
||||
CHECK(!*community->active(3) && *community->corpse(3) == Inventory{});
|
||||
CHECK(*community->parent(3) == 2 && community->origin(3)->value == 1);
|
||||
const std::array second{ReproduceIntent{1, 2, bundle(10)}};
|
||||
CHECK(community->advance(evo::Tick{3}, {}, {}, second));
|
||||
CHECK(community->last_births()[0].child == 4); // A retired identity is never reused.
|
||||
CHECK(*community->parent(4) == 2 && community->origin(4)->value == 3);
|
||||
CHECK(*community->parent(3) == 2 && sum(*community) == total);
|
||||
for (std::uint64_t seed = 0; seed < 32; ++seed) {
|
||||
evo::Random random{seed};
|
||||
const std::array parents{ConsumerConfig{bundle(1000), bundle(10), 1000},
|
||||
ConsumerConfig{bundle(1000), bundle(10), 1000}};
|
||||
auto a = FeedingCommunity::create(producer(), {10'000}, bundle(1000).matter, parents, {},
|
||||
{8, 600, {}});
|
||||
CHECK(a);
|
||||
auto b = *a;
|
||||
const auto conserved = sum(*a);
|
||||
for (std::uint64_t tick = 1; tick <= 4; ++tick) {
|
||||
std::array births{ReproduceIntent{1, 2, bundle(4)}, ReproduceIntent{2, 3, bundle(4)}};
|
||||
CHECK(a->advance(evo::Tick{tick}, {}, {}, births));
|
||||
if (random.next() % 2 != 0) {
|
||||
std::ranges::reverse(births);
|
||||
}
|
||||
CHECK(b.advance(evo::Tick{tick}, {}, {}, births));
|
||||
CHECK(copy(*a) == copy(b) && a->progress() == b.progress());
|
||||
CHECK(std::ranges::equal(a->last_births(), b.last_births()));
|
||||
CHECK(sum(*a) == conserved);
|
||||
}
|
||||
const std::array exhausted{ReproduceIntent{1, 2, bundle(4)}};
|
||||
CHECK(!a->advance(evo::Tick{5}, {}, {}, exhausted));
|
||||
}
|
||||
for (const auto construction : {0U, 1000U}) {
|
||||
const std::array funded{ConsumerConfig{bundle(50), {}, 0}};
|
||||
auto endpoint = FeedingCommunity::create(producer(), {}, {}, funded, {},
|
||||
{1, static_cast<std::uint16_t>(construction), {}});
|
||||
CHECK(endpoint);
|
||||
const auto conserved = sum(*endpoint);
|
||||
const std::array birth{ReproduceIntent{1, 2, bundle(50)}};
|
||||
CHECK(endpoint->advance(evo::Tick{1}, {}, {}, birth));
|
||||
const auto receipt = endpoint->last_births()[0];
|
||||
CHECK(receipt.endowment == bundle(construction == 0 ? 0 : 50));
|
||||
CHECK(receipt.overhead == bundle(construction == 0 ? 50 : 0));
|
||||
// A zero endowment is an empty living child, not a free one: the parent still paid.
|
||||
CHECK(*endpoint->active(3) && sum(*endpoint) == conserved);
|
||||
}
|
||||
constexpr auto maximum = std::numeric_limits<std::uint64_t>::max();
|
||||
const std::array extremes{ConsumerConfig{bundle(maximum), {}, 0}};
|
||||
auto extreme =
|
||||
FeedingCommunity::create(producer(), {}, {}, extremes, {}, {1, 1000, bundle(maximum)});
|
||||
CHECK(extreme);
|
||||
const std::array birth{ReproduceIntent{1, 2, bundle(maximum)}};
|
||||
CHECK(extreme->advance(evo::Tick{1}, {}, {}, birth));
|
||||
CHECK(extreme->last_births()[0].endowment == bundle(maximum));
|
||||
CHECK(*extreme->parent(3) == 2 && sum(*extreme) == bundle(maximum));
|
||||
CHECK(!FeedingCommunity::create(producer(), {}, {}, configs, {}, {1, 1001, {}}));
|
||||
const std::vector<ConsumerConfig> saturated(max_consumers, configs[0]);
|
||||
CHECK(!FeedingCommunity::create(producer(), {}, {}, saturated, {}, {1, 1000, {}}));
|
||||
CHECK(FeedingCommunity::create(producer(), {}, {}, saturated, {}, {0, 1000, {}}));
|
||||
}
|
||||
} // namespace
|
||||
int main() try {
|
||||
capture_feeding_and_terminal();
|
||||
@@ -276,7 +444,10 @@ int main() try {
|
||||
corpse_preservation_and_rollback();
|
||||
decomposition_reference();
|
||||
nutrient_return_and_waste();
|
||||
std::cout << "PASS shared feeding, rollback, terminality and conservation\n";
|
||||
funded_reproduction();
|
||||
reproduction_limits_and_rollback();
|
||||
lineage_identity_and_permutation();
|
||||
std::cout << "PASS shared feeding, reproduction, lineage identity and conservation\n";
|
||||
return 0;
|
||||
} catch (...) {
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user