Decide affordability where composition is known
A construction transition could require more of an element than was available, because the check compared net mass. A step growing a body from 13 to 14 femtograms nets one femtogram but acquires a carbon and a nitrogen while freeing one of other, and released other pays for neither. Matching totals let one element silently fund another. Net mass was never the right question, and the layer asking it could not ask a better one: plan_development has no composition. A single scalar pool could not carry the answer either, since it cannot say that carbon is plentiful while nitrogen is not. The environment now states what is available per ledger channel. plan_development keeps a total-mass bound, which is sound because net never exceeds gross, but it is a proposal rather than an authority. metabolic_budget narrows it to the largest step whose own intake fits channel by channel, and reports the growth that step actually funds. That revises ADR-0031 on this point, recorded in both ADRs. The tests place a single femtogram in each channel in turn and require that no step needing a different element is funded, that nothing is acquired beyond what is present, and that the mass-only plan would have admitted the step; a carbon and a nitrogen together then fund it exactly. Across six target sizes by seven growth fractions by four stock levels, every reported intake fits the availability channel by channel and never exceeds the proposed step. Confirmed to fail with the check removed. The releasing case moved to a target of 20 femtograms, where the step occurs at the full rule step rather than depending on a scarce supply that the corrected plan no longer bounds the same way. Native Release, clang-tidy analysis, ASan and format checks pass 19/19. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
|
||||
## Status
|
||||
|
||||
Adopted for M3.2. The transfer half of ApplyDevelopment, energetic budgets and
|
||||
Adopted for M3.2, and revised by [ADR-0032](0032-metabolic-budgets-from-genome.md)
|
||||
on one point: affordability cannot be settled without composition, so the plan's
|
||||
material check is a total-mass proposal rather than an authority, and the
|
||||
environment states what is available per ledger channel instead of as one pool. The transfer half of ApplyDevelopment, energetic budgets and
|
||||
any coupling to the M2 process fixtures are M3.3. Mutation is M3.4. No gameplay
|
||||
balance, mortality rule or fitness score is selected.
|
||||
|
||||
|
||||
@@ -53,6 +53,17 @@ release rather than a single requirement. The release is a rounding artifact
|
||||
bounded by a few femtograms, not excretion, and the invariant is exact: the body
|
||||
held, plus intake, minus release, is the body reached, on every channel.
|
||||
|
||||
Affordability therefore has to be decided here too, which revises ADR-0031.
|
||||
Net mass is the wrong question: a step whose net growth is one femtogram can
|
||||
still need a carbon and a nitrogen while freeing one of other, and released other
|
||||
is neither. Matching totals would let one element silently pay for another. The
|
||||
environment accordingly carries what is available per ledger channel rather than
|
||||
as a single pool, since a pool cannot say that carbon is plentiful while nitrogen
|
||||
is not. `plan_development` keeps a total-mass bound, which is sound because net
|
||||
never exceeds gross, but it is a proposal and not an authority;
|
||||
`metabolic_budget` narrows it to the largest step whose own intake fits channel by
|
||||
channel, and reports the growth that step actually funds.
|
||||
|
||||
Reproduction investment is the body scaled by the genome's reproduction fraction,
|
||||
with its energy priced at the same construction rate as the organism's own tissue:
|
||||
building offspring tissue costs what building your own does. A genome without the
|
||||
|
||||
@@ -533,6 +533,26 @@ release rather than a single requirement: a body growing from 13 to 14 femtogram
|
||||
acquires one carbon and one nitrogen while freeing one from other. The release is
|
||||
a rounding artifact bounded by a few femtograms, not excretion.
|
||||
|
||||
A follow-up review found the affordability half of the same problem: a transition
|
||||
could require more of an element than was available, because the check compared
|
||||
net mass. A step growing a body from 13 to 14 femtograms nets one femtogram but
|
||||
acquires a carbon and a nitrogen while freeing one of other, and released other
|
||||
pays for neither. The environment now states availability per ledger channel
|
||||
rather than as one pool, since a pool cannot say that carbon is plentiful while
|
||||
nitrogen is not. `plan_development` keeps a total-mass bound, sound because net
|
||||
never exceeds gross but not an authority, and `metabolic_budget` narrows it to the
|
||||
largest step whose own intake fits channel by channel and reports the growth that
|
||||
step funds. That revises ADR-0031 and is recorded there.
|
||||
|
||||
The affordability tests place a single femtogram in each channel in turn and
|
||||
require that no step needing a different element is funded, that nothing is
|
||||
acquired beyond what is present, and that the mass-only plan would have admitted
|
||||
the step; a carbon and a nitrogen together then fund it exactly. Across six target
|
||||
sizes by seven growth fractions by four stock levels, every reported intake is
|
||||
checked to fit the availability channel by channel and never to exceed the step
|
||||
the plan proposed. These tests were confirmed to fail with the per-channel check
|
||||
removed.
|
||||
|
||||
The invariant `held + intake - release == reached` is now asserted per channel for
|
||||
the reviewer's exact case, for the releasing case, across six target sizes by
|
||||
seven growth fractions by four material budgets, and across a forty-step walk from
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/accounting/ledger.hpp"
|
||||
#include "evo/biology/genome.hpp"
|
||||
|
||||
namespace evo::biology {
|
||||
@@ -12,8 +13,10 @@ struct GrowthState {
|
||||
};
|
||||
struct EnvironmentState {
|
||||
std::uint32_t temperature_millikelvin{};
|
||||
// Bounds what a plan can fund. Nothing here is spent or reserved.
|
||||
std::uint64_t available_material{};
|
||||
// What is there to build from, per ledger channel. A single pool could not
|
||||
// say that carbon is plentiful while nitrogen is not, which is the whole
|
||||
// question once a body has a composition. Nothing here is spent or reserved.
|
||||
accounting::Inventory available{};
|
||||
auto operator<=>(const EnvironmentState&) const = default;
|
||||
};
|
||||
// Chosen constants, reviewable as a unit and selected by the genome's
|
||||
@@ -61,7 +64,10 @@ rules_for(std::uint32_t development_version);
|
||||
[[nodiscard]] std::expected<Phenotype, DevelopmentError>
|
||||
derive_phenotype(const Genome& genome, GrowthState growth, EnvironmentState environment);
|
||||
// Advances realized growth toward the target by at most the rule step, reduced to
|
||||
// the largest step the available material funds exactly. Never repairs damage.
|
||||
// the largest step the available mass and energy admit. This bounds by total mass
|
||||
// only: it cannot see which elements a step consumes, so it is a proposal and not
|
||||
// an affordability authority. `metabolic_budget` decides that, per channel, and
|
||||
// can only narrow this further. Never repairs damage.
|
||||
[[nodiscard]] std::expected<DevelopmentPlan, DevelopmentError>
|
||||
plan_development(const Genome& genome, GrowthState growth, EnvironmentState environment);
|
||||
} // namespace evo::biology
|
||||
|
||||
@@ -23,6 +23,7 @@ struct MetabolicRules {
|
||||
// the derived body on every channel. Release is a rounding artifact of the
|
||||
// declared composition, bounded by a few femtograms; it is not excretion.
|
||||
struct ConstructionTransition {
|
||||
GrowthState after; // the growth this transition actually funds
|
||||
accounting::Inventory intake; // energy and matter that must be acquired
|
||||
accounting::Inventory release; // matter freed as the composition rebalances
|
||||
auto operator<=>(const ConstructionTransition&) const = default;
|
||||
|
||||
@@ -39,6 +39,13 @@ std::uint64_t scaled(std::uint64_t value, std::uint64_t numerator) noexcept {
|
||||
// Declared flooring; the remainder is discarded rather than carried.
|
||||
return value / thousand * numerator + value % thousand * numerator / thousand;
|
||||
}
|
||||
std::uint64_t matter_total(const accounting::Inventory& inventory) noexcept {
|
||||
std::uint64_t sum = 0;
|
||||
for (const auto& mass : inventory.matter) {
|
||||
sum += mass.value;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::expected<DevelopmentRules, DevelopmentError> rules_for(std::uint32_t development_version) {
|
||||
@@ -120,8 +127,9 @@ plan_development(const Genome& genome, GrowthState growth, EnvironmentState envi
|
||||
plan.after = growth;
|
||||
const auto remaining = thousand - growth.realized_per_thousand;
|
||||
const auto step = std::min(remaining, rules->growth_step_per_thousand);
|
||||
// Take the largest step the available material funds exactly, never a
|
||||
// partially funded one and never a grant.
|
||||
// Take the largest step the available mass and energy admit, never a
|
||||
// partially funded one and never a grant. This bounds by total mass only;
|
||||
// which elements the step consumes is settled by the composition layer.
|
||||
for (std::uint32_t attempt = step; attempt > 0; --attempt) {
|
||||
auto proposed = growth;
|
||||
proposed.realized_per_thousand += attempt;
|
||||
@@ -133,12 +141,14 @@ plan_development(const Genome& genome, GrowthState growth, EnvironmentState envi
|
||||
return std::unexpected{DevelopmentError::overflow};
|
||||
}
|
||||
const auto material = grown->total_mass - current->total_mass;
|
||||
if (material > environment.available_material) {
|
||||
const auto energy = scaled(material, rules->construction_per_kilogram);
|
||||
if (material > matter_total(environment.available) ||
|
||||
energy > environment.available.energy.value) {
|
||||
continue;
|
||||
}
|
||||
plan.after = proposed;
|
||||
plan.material_required = material;
|
||||
plan.energy_required = scaled(material, rules->construction_per_kilogram);
|
||||
plan.energy_required = energy;
|
||||
break;
|
||||
}
|
||||
return plan;
|
||||
|
||||
+55
-22
@@ -63,6 +63,19 @@ bool combine(accounting::Inventory& total, const accounting::Inventory& amount)
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Every channel and the energy must fit: a surplus of one element never pays for
|
||||
// a shortfall of another.
|
||||
bool fits(const accounting::Inventory& needed, const accounting::Inventory& available) noexcept {
|
||||
if (needed.energy > available.energy) {
|
||||
return false;
|
||||
}
|
||||
for (std::size_t index = 0; index < needed.matter.size(); ++index) {
|
||||
if (needed.matter[index] > available.matter[index]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::uint64_t matter_total(const accounting::Inventory& inventory) noexcept {
|
||||
std::uint64_t sum = 0;
|
||||
for (const auto& mass : inventory.matter) {
|
||||
@@ -136,30 +149,50 @@ metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState envi
|
||||
if (!plan) {
|
||||
return std::unexpected{plan.error()};
|
||||
}
|
||||
const auto grown = derive_phenotype(genome, plan->after, environment);
|
||||
if (!grown) {
|
||||
return std::unexpected{grown.error()};
|
||||
}
|
||||
// Compose the grown body and difference it against the current one. Composing
|
||||
// the mass difference instead would discard the rounding this body already
|
||||
// carries, and the budget could not then reproduce the derived body channel by
|
||||
// channel. Each compartment is still composed separately: the two differ in
|
||||
// what they cost.
|
||||
auto reached = compose(grown->structural_mass, rules->structure);
|
||||
if (!combine(reached, compose(grown->membrane_mass, rules->membrane))) {
|
||||
return std::unexpected{DevelopmentError::overflow};
|
||||
}
|
||||
for (std::size_t index = 0; index < reached.matter.size(); ++index) {
|
||||
const auto held = budget.body.matter[index].value;
|
||||
const auto wanted = reached.matter[index].value;
|
||||
if (wanted >= held) {
|
||||
budget.construction.intake.matter[index].value = wanted - held;
|
||||
} else {
|
||||
budget.construction.release.matter[index].value = held - wanted;
|
||||
// A plan bounds by total mass, which cannot tell whether the elements a step
|
||||
// consumes are actually there: released matter never substitutes for an
|
||||
// element the step needs. Narrow the proposal to the largest step whose own
|
||||
// intake fits channel by channel.
|
||||
budget.construction.after = growth;
|
||||
const auto proposed = plan->after.realized_per_thousand - growth.realized_per_thousand;
|
||||
for (std::uint32_t attempt = proposed; attempt > 0; --attempt) {
|
||||
const GrowthState candidate{growth.realized_per_thousand + attempt,
|
||||
growth.damage_per_thousand};
|
||||
const auto grown = derive_phenotype(genome, candidate, environment);
|
||||
if (!grown) {
|
||||
return std::unexpected{grown.error()};
|
||||
}
|
||||
// Compose the grown body and difference it against the current one.
|
||||
// Composing the mass difference instead would discard the rounding this
|
||||
// body already carries, and the budget could not then reproduce the
|
||||
// derived body channel by channel. Each compartment is still composed
|
||||
// separately: the two differ in what they cost.
|
||||
auto reached = compose(grown->structural_mass, rules->structure);
|
||||
if (!combine(reached, compose(grown->membrane_mass, rules->membrane))) {
|
||||
return std::unexpected{DevelopmentError::overflow};
|
||||
}
|
||||
ConstructionTransition move{};
|
||||
move.after = candidate;
|
||||
std::uint64_t acquired = 0, freed = 0;
|
||||
for (std::size_t index = 0; index < reached.matter.size(); ++index) {
|
||||
const auto held = budget.body.matter[index].value;
|
||||
const auto wanted = reached.matter[index].value;
|
||||
if (wanted >= held) {
|
||||
move.intake.matter[index].value = wanted - held;
|
||||
acquired += wanted - held;
|
||||
} else {
|
||||
move.release.matter[index].value = held - wanted;
|
||||
freed += held - wanted;
|
||||
}
|
||||
}
|
||||
// Energy is priced on the net mass change, as the plan prices it.
|
||||
move.intake.energy.value = scaled(acquired - freed, shape->construction_per_kilogram);
|
||||
if (!fits(move.intake, environment.available)) {
|
||||
continue;
|
||||
}
|
||||
budget.construction = move;
|
||||
break;
|
||||
}
|
||||
// Energy is priced on the net mass change, matching what the plan reports.
|
||||
budget.construction.intake.energy.value = plan->energy_required;
|
||||
if (genome.carries(Capability::reproduction)) {
|
||||
const auto fraction = *genome.parameter(Capability::reproduction);
|
||||
// A parent divides the body it has, so the investment keeps its composition.
|
||||
|
||||
@@ -30,7 +30,12 @@ Genome build(const GenomeDraft& source) {
|
||||
check(genome.has_value());
|
||||
return *genome;
|
||||
}
|
||||
constexpr EnvironmentState temperate{293'150, 1'000'000'000};
|
||||
// Development bounds growth by total mass, so a single channel carries the supply
|
||||
// here; which elements a step consumes is settled in metabolism_tests.
|
||||
constexpr evo::accounting::Inventory supply(std::uint64_t matter, std::uint64_t energy) {
|
||||
return {{energy}, {evo::accounting::Femtograms{matter}, {}, {}, {}}};
|
||||
}
|
||||
constexpr EnvironmentState temperate{293'150, supply(1'000'000'000, 1'000'000'000)};
|
||||
|
||||
void hand_calculated_phenotype() {
|
||||
const auto genome = build(draft());
|
||||
@@ -75,7 +80,7 @@ void identical_inputs_give_identical_phenotypes() {
|
||||
for (std::uint32_t realized = 0; realized <= 1000; realized += 125) {
|
||||
for (std::uint32_t damage = 0; damage <= 1000; damage += 250) {
|
||||
for (const auto temperature : {0U, 293'150U, 400'000U}) {
|
||||
const EnvironmentState environment{temperature, 1'000'000};
|
||||
const EnvironmentState environment{temperature, supply(1'000'000, 1'000'000)};
|
||||
const auto first = derive_phenotype(genome, {realized, damage}, environment);
|
||||
const auto second = derive_phenotype(genome, {realized, damage}, environment);
|
||||
CHECK(first && second && *first == *second);
|
||||
@@ -117,14 +122,14 @@ void thermal_shortfall_is_reported_not_enforced() {
|
||||
const auto tolerant = build(source);
|
||||
const auto bare = build(draft());
|
||||
for (const auto offset : {0U, 5'000U}) {
|
||||
const EnvironmentState warm{293'150 + offset, 0};
|
||||
const EnvironmentState warm{293'150 + offset, {}};
|
||||
const auto inside = derive_phenotype(tolerant, {1000, 0}, warm);
|
||||
CHECK(inside && inside->thermal_shortfall == 0);
|
||||
}
|
||||
const EnvironmentState hot{293'150 + 8'000, 0};
|
||||
const EnvironmentState hot{293'150 + 8'000, {}};
|
||||
const auto stressed = derive_phenotype(tolerant, {1000, 0}, hot);
|
||||
CHECK(stressed && stressed->thermal_shortfall == 3'000);
|
||||
const EnvironmentState cold{293'150 - 8'000, 0};
|
||||
const EnvironmentState cold{293'150 - 8'000, {}};
|
||||
const auto chilled = derive_phenotype(tolerant, {1000, 0}, cold);
|
||||
CHECK(chilled && chilled->thermal_shortfall == 3'000); // Symmetric about the reference.
|
||||
// Without the capability every deviation is reported in full.
|
||||
@@ -167,14 +172,14 @@ void plans_are_bounded_and_funded() {
|
||||
CHECK(funded->material_required == 2'632'000); // 22832000 - 20200000
|
||||
CHECK(funded->energy_required == 105'280); // material * 40 per 1000 fg
|
||||
// One femtogram short of the full step buys exactly the largest step that fits.
|
||||
const EnvironmentState tight{293'150, 2'631'999};
|
||||
const EnvironmentState tight{293'150, supply(2'631'999, 1'000'000'000)};
|
||||
const auto reduced = plan_development(genome, {500, 0}, tight);
|
||||
CHECK(reduced);
|
||||
CHECK(reduced->after == (GrowthState{549, 0}));
|
||||
CHECK(reduced->material_required == 2'624'000);
|
||||
CHECK(reduced->material_required <= tight.available_material);
|
||||
CHECK(reduced->material_required <= tight.available.matter[0].value);
|
||||
// No material funds no growth, and nothing is granted.
|
||||
const EnvironmentState barren{293'150, 0};
|
||||
const EnvironmentState barren{293'150, {}};
|
||||
const auto refused = plan_development(genome, {500, 0}, barren);
|
||||
CHECK(refused && refused->after == (GrowthState{500, 0}));
|
||||
CHECK(refused->material_required == 0 && refused->energy_required == 0);
|
||||
@@ -198,7 +203,7 @@ void flooring_consequences() {
|
||||
{Capability::membrane, 1, 0},
|
||||
{Capability::target_size, 1, 0}};
|
||||
const auto tiny = build(source);
|
||||
const EnvironmentState barren{293'150, 0};
|
||||
const EnvironmentState barren{293'150, {}};
|
||||
const auto plan = plan_development(tiny, {500, 0}, barren);
|
||||
CHECK(plan && plan->after == (GrowthState{550, 0}));
|
||||
CHECK(plan->material_required == 0 && plan->energy_required == 0);
|
||||
|
||||
+98
-16
@@ -38,7 +38,23 @@ GenomeDraft capable() {
|
||||
source.capabilities.push_back({Capability::reproduction, 300, 0});
|
||||
return source;
|
||||
}
|
||||
constexpr EnvironmentState temperate{293'150, 1'000'000'000};
|
||||
// Every channel stocked alike, so availability never accidentally hides a
|
||||
// per-element shortfall except where a test sets one deliberately.
|
||||
constexpr Inventory pooled(std::uint64_t value) {
|
||||
return {{value}, {Femtograms{value}, Femtograms{value}, Femtograms{value}, Femtograms{value}}};
|
||||
}
|
||||
constexpr EnvironmentState temperate{293'150, pooled(1'000'000'000)};
|
||||
bool fits_within(const Inventory& needed, const Inventory& available) {
|
||||
if (needed.energy.value > available.energy.value) {
|
||||
return false;
|
||||
}
|
||||
for (std::size_t index = 0; index < 4; ++index) {
|
||||
if (needed.matter[index].value > available.matter[index].value) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
std::uint64_t matter_total(const Inventory& inventory) {
|
||||
std::uint64_t sum = 0;
|
||||
for (const auto& mass : inventory.matter) {
|
||||
@@ -100,8 +116,9 @@ void construction_composes_each_compartment() {
|
||||
CHECK(plan && plan->material_required == matter_total(budget->construction.intake) -
|
||||
matter_total(budget->construction.release));
|
||||
CHECK(plan->energy_required == budget->construction.intake.energy.value);
|
||||
CHECK(budget->construction.after == plan->after);
|
||||
// Unaffordable growth leaves nothing to move.
|
||||
const EnvironmentState barren{293'150, 0};
|
||||
const EnvironmentState barren{293'150, pooled(0)};
|
||||
const auto starved = metabolic_budget(genome, {500, 0}, barren);
|
||||
CHECK(starved && matter_total(starved->construction.intake) == 0);
|
||||
CHECK(matter_total(starved->construction.release) == 0);
|
||||
@@ -134,19 +151,22 @@ void construction_reproduces_the_derived_body() {
|
||||
before->construction.release.matter[index].value ==
|
||||
after->body.matter[index].value);
|
||||
}
|
||||
// A step can also free a femtogram as the declared shares rebalance: this
|
||||
// body goes from 13 to 14 fg, and other falls from 6 to 5.
|
||||
source.capabilities[2].parameter = 1000;
|
||||
// A step can also free a femtogram as the declared shares rebalance. At a
|
||||
// target of 20 fg a full step moves the body from 13 to 14 fg: carbon and
|
||||
// nitrogen each gain one while other falls from 6 to 5.
|
||||
source.capabilities[2].parameter = 20;
|
||||
const auto small = build(source);
|
||||
const EnvironmentState scarce{293'150, 1};
|
||||
const auto crawling = metabolic_budget(small, {13, 0}, scarce);
|
||||
CHECK(crawling);
|
||||
const auto crawling = metabolic_budget(small, {650, 0}, temperate);
|
||||
CHECK(crawling && crawling->phenotype.structural_mass == 13);
|
||||
CHECK(crawling->body.matter[3].value == 6);
|
||||
CHECK(crawling->construction.after == (GrowthState{700, 0}));
|
||||
CHECK(crawling->construction.intake.matter[0].value == 1);
|
||||
CHECK(crawling->construction.intake.matter[1].value == 1);
|
||||
CHECK(crawling->construction.intake.matter[2].value == 0);
|
||||
CHECK(crawling->construction.release.matter[3].value == 1);
|
||||
const auto stepped = metabolic_budget(small, {14, 0}, scarce);
|
||||
CHECK(stepped && stepped->body.matter[3].value == 5);
|
||||
const auto stepped = metabolic_budget(small, {700, 0}, temperate);
|
||||
CHECK(stepped && stepped->phenotype.structural_mass == 14);
|
||||
CHECK(stepped->body.matter[3].value == 5);
|
||||
for (std::size_t index = 0; index < 4; ++index) {
|
||||
CHECK(crawling->body.matter[index].value +
|
||||
crawling->construction.intake.matter[index].value -
|
||||
@@ -155,6 +175,65 @@ void construction_reproduces_the_derived_body() {
|
||||
}
|
||||
}
|
||||
|
||||
void released_matter_never_funds_another_element() {
|
||||
// The 13 to 14 fg step again: net growth is one femtogram, but it acquires a
|
||||
// carbon and a nitrogen while freeing one of other. Released other is neither
|
||||
// carbon nor nitrogen, so a single femtogram cannot fund it whatever channel
|
||||
// that femtogram sits in.
|
||||
auto source = draft();
|
||||
source.capabilities[2].parameter = 20;
|
||||
const auto genome = build(source);
|
||||
for (std::size_t channel = 0; channel < 4; ++channel) {
|
||||
Inventory single{{1'000'000}, {}};
|
||||
single.matter[channel].value = 1; // One femtogram, and only one.
|
||||
const EnvironmentState scarce{293'150, single};
|
||||
// The mass-only plan is what would be fooled: it sees a net of one
|
||||
// femtogram against a pool of one and admits the step.
|
||||
const auto plan = plan_development(genome, {650, 0}, scarce);
|
||||
CHECK(plan && plan->after == (GrowthState{700, 0}) && plan->material_required == 1);
|
||||
const auto budget = metabolic_budget(genome, {650, 0}, scarce);
|
||||
CHECK(budget);
|
||||
CHECK(budget->construction.after != (GrowthState{700, 0})); // Not funded.
|
||||
// Nothing is acquired at all: the steps that remain change no mass.
|
||||
CHECK(matter_total(budget->construction.intake) == 0);
|
||||
CHECK(matter_total(budget->construction.release) == 0);
|
||||
CHECK(fits_within(budget->construction.intake, single));
|
||||
const auto reached = metabolic_budget(genome, budget->construction.after, scarce);
|
||||
CHECK(reached && reached->phenotype.structural_mass == 13);
|
||||
}
|
||||
// A carbon and a nitrogen together are exactly what the step needs.
|
||||
Inventory exact{{1'000'000}, {}};
|
||||
exact.matter[0].value = 1;
|
||||
exact.matter[1].value = 1;
|
||||
const auto precise = metabolic_budget(genome, {650, 0}, {293'150, exact});
|
||||
CHECK(precise && precise->construction.after == (GrowthState{700, 0}));
|
||||
CHECK(precise->construction.intake.matter[0].value == 1);
|
||||
CHECK(precise->construction.intake.matter[1].value == 1);
|
||||
CHECK(precise->construction.release.matter[3].value == 1);
|
||||
}
|
||||
|
||||
void every_transition_is_affordable_channel_by_channel() {
|
||||
auto source = capable();
|
||||
for (const std::uint32_t target : {1U, 999U, 1001U, 9'999U, 123'457U, 8'000'000U}) {
|
||||
source.capabilities[2].parameter = target;
|
||||
const auto genome = build(source);
|
||||
for (const std::uint32_t realized : {0U, 1U, 13U, 333U, 500U, 950U, 1000U}) {
|
||||
for (const std::uint64_t stock : {0ULL, 1ULL, 7ULL, 1'000'000ULL}) {
|
||||
const EnvironmentState environment{293'150, pooled(stock)};
|
||||
const auto budget = metabolic_budget(genome, {realized, 0}, environment);
|
||||
CHECK(budget);
|
||||
// Whatever a step reports, every element of it must be there.
|
||||
CHECK(fits_within(budget->construction.intake, environment.available));
|
||||
// A funded step never exceeds what the mass-only plan proposed.
|
||||
const auto plan = plan_development(genome, {realized, 0}, environment);
|
||||
CHECK(plan && budget->construction.after.realized_per_thousand <=
|
||||
plan->after.realized_per_thousand);
|
||||
CHECK(budget->construction.after.damage_per_thousand == 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void every_transition_conserves_each_channel() {
|
||||
auto source = capable();
|
||||
for (const std::uint32_t target : {1U, 999U, 1001U, 9'999U, 123'457U, 8'000'000U}) {
|
||||
@@ -162,11 +241,12 @@ void every_transition_conserves_each_channel() {
|
||||
const auto genome = build(source);
|
||||
for (const std::uint32_t realized : {0U, 1U, 13U, 333U, 500U, 950U, 1000U}) {
|
||||
for (const std::uint64_t material : {0ULL, 1ULL, 7ULL, 1'000'000'000ULL}) {
|
||||
const EnvironmentState environment{293'150, material};
|
||||
const EnvironmentState environment{293'150, pooled(material)};
|
||||
const auto budget = metabolic_budget(genome, {realized, 0}, environment);
|
||||
const auto plan = plan_development(genome, {realized, 0}, environment);
|
||||
CHECK(budget && plan);
|
||||
const auto reached = metabolic_budget(genome, plan->after, environment);
|
||||
const auto reached =
|
||||
metabolic_budget(genome, budget->construction.after, environment);
|
||||
CHECK(reached);
|
||||
// Spending the budget must reproduce the derived body exactly, on
|
||||
// every channel, not merely in total.
|
||||
@@ -180,7 +260,7 @@ void every_transition_conserves_each_channel() {
|
||||
CHECK(matter_total(budget->construction.intake) >=
|
||||
matter_total(budget->construction.release));
|
||||
CHECK(matter_total(budget->construction.intake) -
|
||||
matter_total(budget->construction.release) ==
|
||||
matter_total(budget->construction.release) <=
|
||||
plan->material_required);
|
||||
}
|
||||
}
|
||||
@@ -199,13 +279,13 @@ void repeated_growth_conserves_each_channel() {
|
||||
CHECK(opening);
|
||||
for (int step = 0; step < 40 && growth.realized_per_thousand < 1000; ++step) {
|
||||
const auto budget = metabolic_budget(genome, growth, temperate);
|
||||
const auto plan = plan_development(genome, growth, temperate);
|
||||
CHECK(budget && plan);
|
||||
CHECK(budget &&
|
||||
budget->construction.after.realized_per_thousand > growth.realized_per_thousand);
|
||||
for (std::size_t index = 0; index < 4; ++index) {
|
||||
acquired.matter[index].value += budget->construction.intake.matter[index].value;
|
||||
freed.matter[index].value += budget->construction.release.matter[index].value;
|
||||
}
|
||||
growth = plan->after;
|
||||
growth = budget->construction.after;
|
||||
}
|
||||
CHECK(growth.realized_per_thousand == 1000);
|
||||
const auto finished = metabolic_budget(genome, growth, temperate);
|
||||
@@ -374,6 +454,8 @@ int main() try {
|
||||
hand_calculated_budget();
|
||||
construction_composes_each_compartment();
|
||||
construction_reproduces_the_derived_body();
|
||||
released_matter_never_funds_another_element();
|
||||
every_transition_is_affordable_channel_by_channel();
|
||||
every_transition_conserves_each_channel();
|
||||
repeated_growth_conserves_each_channel();
|
||||
thicker_membrane_costs_matter_and_maintenance();
|
||||
|
||||
Reference in New Issue
Block a user