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>
54 lines
2.8 KiB
C++
54 lines
2.8 KiB
C++
#pragma once
|
|
|
|
#include "evo/accounting/ledger.hpp"
|
|
#include "evo/biology/development.hpp"
|
|
|
|
namespace evo::biology {
|
|
// Shares in thousandths over the ledger's C/N/P/other channels, summing to 1000.
|
|
// The last channel absorbs the rounding remainder, so a split conserves mass.
|
|
using Composition = std::array<std::uint16_t, 4>;
|
|
// Chosen constants, selected by the same development version as ADR-0031 and
|
|
// reviewable as a unit. Declared model parameters, not balance.
|
|
struct MetabolicRules {
|
|
Composition structure;
|
|
Composition membrane;
|
|
// Picojoules per tick per 1000 femtograms at 1000 micrometres per tick.
|
|
std::uint64_t movement_per_kilogram;
|
|
// Picojoules of intake capacity per 1000 femtograms of it.
|
|
std::uint64_t intake_energy_per_kilogram;
|
|
};
|
|
// The exact per-channel move from the body an organism has to the one a growth
|
|
// step produces. Composing the mass difference instead would discard the rounding
|
|
// the existing body already carries, so spending the budget could not reproduce
|
|
// 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;
|
|
};
|
|
// Every budget a phenotype implies. Each is derived from a different phenotype
|
|
// quantity, so one genome parameter moves some and not others: none of this is a
|
|
// multiplier applied to a total.
|
|
struct MetabolicBudget {
|
|
Phenotype phenotype;
|
|
accounting::Inventory body; // matter only; a body is not energy
|
|
accounting::Picojoules maintenance; // per tick
|
|
accounting::Picojoules movement; // per tick at full speed, a capacity
|
|
accounting::Picojoules demand; // maintenance plus movement
|
|
ConstructionTransition construction; // what the next growth step would move
|
|
accounting::Inventory intake_limit; // per tick
|
|
// Zero without the reproduction capability, rather than a default.
|
|
accounting::Inventory reproduction_investment;
|
|
std::uint16_t assimilation_per_thousand{};
|
|
auto operator<=>(const MetabolicBudget&) const = default;
|
|
};
|
|
[[nodiscard]] std::expected<MetabolicRules, DevelopmentError>
|
|
metabolic_rules_for(std::uint32_t development_version);
|
|
// The single place the genome's description of capability becomes ledger
|
|
// quantities. The genome record itself stays free of accounting types.
|
|
[[nodiscard]] std::expected<MetabolicBudget, DevelopmentError>
|
|
metabolic_budget(const Genome& genome, GrowthState growth, EnvironmentState environment);
|
|
} // namespace evo::biology
|