ADR-0125 and the M11.5 plan define budding and wildlife descendants. The first piece is biology only: fund_bud pays the ADR-0032 investment and a 30 s provision from the parent's reserve, builds the bud at the largest growth the investment matter allows, and sends construction energy to heat, refusing with nothing spent when any channel is short. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
5.6 KiB
C++
129 lines
5.6 KiB
C++
// M11.5a (ADR-0125): the funded bud proposal.
|
|
#include "evo/biology/budding.hpp"
|
|
#include "evo/biology/founder.hpp"
|
|
|
|
#include <iostream>
|
|
#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("budding line " + std::to_string(location.line()));
|
|
}
|
|
#define CHECK(expression) check(static_cast<bool>(expression))
|
|
constexpr std::uint32_t temperate = 293'150;
|
|
|
|
Genome founder() {
|
|
const auto genome = primitive_founder(5, 5);
|
|
CHECK(genome);
|
|
return *genome;
|
|
}
|
|
Inventory plenty() {
|
|
constexpr std::uint64_t lots = 1'000'000'000'000;
|
|
return {{lots}, {Femtograms{lots}, Femtograms{lots}, Femtograms{lots}, Femtograms{lots}}};
|
|
}
|
|
// The parent's reserve before equals its reserve after plus the bud's body and reserve,
|
|
// plus heat in energy: nothing is created or lost on any channel.
|
|
bool conserves(const Inventory& before, const BudTransition& bud) {
|
|
for (std::size_t c = 0; c < before.matter.size(); ++c)
|
|
if (before.matter[c].value != bud.parent_reserve.matter[c].value +
|
|
bud.body.matter[c].value + bud.reserve.matter[c].value)
|
|
return false;
|
|
return bud.body.energy.value == 0 && before.energy.value == bud.parent_reserve.energy.value +
|
|
bud.reserve.energy.value +
|
|
bud.heat.value;
|
|
}
|
|
|
|
void a_grown_parent_funds_the_largest_bud_its_investment_builds() {
|
|
const auto genome = founder();
|
|
const auto reserve = plenty();
|
|
const auto bud = fund_bud(genome, {1000, 0}, reserve, temperate);
|
|
CHECK(bud);
|
|
CHECK(conserves(reserve, *bud));
|
|
const auto parent = metabolic_budget(genome, {1000, 0}, {temperate, {}});
|
|
CHECK(parent);
|
|
// The founder invests half its body, so the bud is a partly realized cell.
|
|
CHECK(bud->growth.realized_per_thousand > 0 && bud->growth.realized_per_thousand < 1000 &&
|
|
bud->growth.damage_per_thousand == 0);
|
|
CHECK(bud->heat == parent->reproduction_investment.energy);
|
|
const auto developed = metabolic_budget(genome, bud->growth, {temperate, {}});
|
|
CHECK(developed);
|
|
CHECK(bud->body.matter == developed->body.matter);
|
|
// One more step of growth would not fit the investment.
|
|
if (bud->growth.realized_per_thousand < 1000) {
|
|
const auto larger =
|
|
metabolic_budget(genome, {bud->growth.realized_per_thousand + 1, 0}, {temperate, {}});
|
|
CHECK(larger);
|
|
bool fits = true;
|
|
for (std::size_t c = 0; c < larger->body.matter.size(); ++c)
|
|
fits = fits &&
|
|
larger->body.matter[c].value <= parent->reproduction_investment.matter[c].value;
|
|
CHECK(!fits);
|
|
}
|
|
// The provision is 30 seconds of the bud's own full demand.
|
|
CHECK(bud->reserve.energy.value == developed->demand.value * bud_provision_seconds * 1'000'000 /
|
|
developed->rate_microseconds);
|
|
CHECK(fund_bud(genome, {1000, 0}, reserve, temperate) == bud); // Deterministic.
|
|
}
|
|
|
|
void every_short_channel_refuses_and_spends_nothing() {
|
|
const auto genome = founder();
|
|
const auto exact = fund_bud(genome, {1000, 0}, plenty(), temperate);
|
|
CHECK(exact);
|
|
// The exact cost: what the parent's reserve lost.
|
|
Inventory cost;
|
|
for (std::size_t c = 0; c < cost.matter.size(); ++c)
|
|
cost.matter[c].value = plenty().matter[c].value - exact->parent_reserve.matter[c].value;
|
|
cost.energy.value = plenty().energy.value - exact->parent_reserve.energy.value;
|
|
const auto paid = fund_bud(genome, {1000, 0}, cost, temperate);
|
|
CHECK(paid && paid->parent_reserve == Inventory{} && conserves(cost, *paid));
|
|
for (std::size_t c = 0; c <= cost.matter.size(); ++c) {
|
|
auto short_one = cost;
|
|
if (c == cost.matter.size()) {
|
|
if (short_one.energy.value == 0)
|
|
continue;
|
|
--short_one.energy.value;
|
|
} else {
|
|
if (short_one.matter[c].value == 0)
|
|
continue;
|
|
--short_one.matter[c].value;
|
|
// Abundant energy never pays for missing matter.
|
|
short_one.energy.value += 1'000'000'000;
|
|
}
|
|
CHECK(fund_bud(genome, {1000, 0}, short_one, temperate).error() ==
|
|
BuddingError::insufficient_funding);
|
|
}
|
|
}
|
|
|
|
void only_a_grown_undamaged_reproducing_parent_buds() {
|
|
const auto genome = founder();
|
|
CHECK(fund_bud(genome, {999, 0}, plenty(), temperate).error() == BuddingError::not_grown);
|
|
CHECK(fund_bud(genome, {1000, 1}, plenty(), temperate).error() == BuddingError::not_grown);
|
|
const auto barren = Genome::create({9,
|
|
1,
|
|
2,
|
|
{},
|
|
{{Capability::energy_conversion, 400, 0},
|
|
{Capability::membrane, 1, 0},
|
|
{Capability::target_size, 8'000'000, 0}}});
|
|
CHECK(barren);
|
|
CHECK(fund_bud(*barren, {1000, 0}, plenty(), temperate).error() == BuddingError::no_capability);
|
|
}
|
|
} // namespace
|
|
|
|
int main() {
|
|
try {
|
|
a_grown_parent_funds_the_largest_bud_its_investment_builds();
|
|
every_short_channel_refuses_and_spends_nothing();
|
|
only_a_grown_undamaged_reproducing_parent_buds();
|
|
} catch (const std::exception& error) {
|
|
std::cerr << error.what() << '\n';
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|