M12.2b: test exact reserve-strata population candidate
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (tsan) (push) Successful in 11m44s
Foundation / checks (client) (push) Successful in 19m23s
Foundation / checks (network) (push) Successful in 19m45s
Foundation / checks (checks) (push) Successful in 45m39s
Foundation / checks (postgres) (push) Successful in 45m56s
Foundation / postgres-tools (push) Successful in 23s
Foundation / server-image (push) Successful in 31s
Foundation / image (push) Successful in 3m35s
Foundation / checks (deploy) (push) Successful in 5s
Foundation / checks (ecs) (push) Successful in 2m26s
Foundation / checks (tsan) (push) Successful in 11m44s
Foundation / checks (client) (push) Successful in 19m23s
Foundation / checks (network) (push) Successful in 19m45s
Foundation / checks (checks) (push) Successful in 45m39s
Foundation / checks (postgres) (push) Successful in 45m56s
Foundation / postgres-tools (push) Successful in 23s
Foundation / server-image (push) Successful in 31s
Foundation / image (push) Successful in 3m35s
This commit is contained in:
@@ -0,0 +1,308 @@
|
||||
#include "reserve_strata.hpp"
|
||||
|
||||
#include "evo/core/random.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
using namespace evo::fixture;
|
||||
using evo::experiment::ReserveStrata;
|
||||
|
||||
// Cost control: retire dead rows while retaining original identities and tie order.
|
||||
// It still invokes the historical scalar stepping rule, including its sort/scratch.
|
||||
struct CompactIndividual {
|
||||
IndividualRun run;
|
||||
std::vector<std::uint64_t> identities;
|
||||
std::uint64_t next_identity{};
|
||||
explicit CompactIndividual(const IndividualRun& source) : run{source} {
|
||||
next_identity = source.members.size();
|
||||
for (std::size_t index = 0; index < source.members.size(); ++index) {
|
||||
identities.push_back(index);
|
||||
}
|
||||
compact();
|
||||
}
|
||||
void compact() {
|
||||
std::size_t written = 0;
|
||||
for (std::size_t index = 0; index < run.members.size(); ++index) {
|
||||
if (run.members[index].alive) {
|
||||
run.members[written] = run.members[index];
|
||||
identities[written] = identities[index];
|
||||
++written;
|
||||
}
|
||||
}
|
||||
run.members.resize(written);
|
||||
identities.resize(written);
|
||||
}
|
||||
void step() {
|
||||
run.step();
|
||||
while (identities.size() < run.members.size()) {
|
||||
identities.push_back(next_identity++);
|
||||
}
|
||||
compact();
|
||||
}
|
||||
[[nodiscard]] Census census() const {
|
||||
return run.census();
|
||||
}
|
||||
[[nodiscard]] std::vector<evo::experiment::IdentifiedReserve> portrait() const {
|
||||
std::vector<evo::experiment::IdentifiedReserve> result;
|
||||
for (std::size_t index = 0; index < run.members.size(); ++index) {
|
||||
const auto& member = run.members[index];
|
||||
result.push_back({identities[index], member.age, member.energy, member.matter});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<evo::experiment::IdentifiedReserve> identified(const IndividualRun& run) {
|
||||
std::vector<evo::experiment::IdentifiedReserve> result;
|
||||
for (std::size_t index = 0; index < run.members.size(); ++index) {
|
||||
const auto& member = run.members[index];
|
||||
if (member.alive) {
|
||||
result.push_back({index, member.age, member.energy, member.matter});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void matches(const IndividualRun& individual, const ReserveStrata& strata) {
|
||||
insist(individual.census() == strata.census(), "strata census mismatch");
|
||||
insist(identified(individual) == strata.portrait(), "strata identified portrait mismatch");
|
||||
insist(individual.members.size() == strata.next_identity(), "strata identity mismatch");
|
||||
insist(individual.environment == strata.environment(), "strata environment mismatch");
|
||||
insist(individual.matter_store == strata.matter_store(), "strata matter store mismatch");
|
||||
insist(individual.detritus_energy == strata.detritus_energy(), "strata energy sink mismatch");
|
||||
insist(individual.detritus_matter == strata.detritus_matter(), "strata matter sink mismatch");
|
||||
}
|
||||
|
||||
void controls() {
|
||||
// Same age, distinct reserves, a compressed range and a partially funded birth
|
||||
// range. Census-only comparison cannot detect paying the wrong parent.
|
||||
auto contested = founding_contested(0, 6);
|
||||
contested.members = {{50, 120, 80}, {50, 120, 80}, {50, 120, 80}, {50, 200, 90}};
|
||||
ReserveStrata partial{contested};
|
||||
insist(partial.groups().size() == 2, "strata did not compress identical members");
|
||||
for (unsigned tick = 0; tick < 80; ++tick) {
|
||||
contested.step();
|
||||
partial.step();
|
||||
matches(contested, partial);
|
||||
}
|
||||
insist(partial.census().births > 0, "strata control never reproduced");
|
||||
|
||||
auto fragmented = founding_individuals(5);
|
||||
fragmented.members = {
|
||||
{10, 0, 5, false}, {10, 1, 5}, {10, 1, 5}, {10, 0, 5, false}, {10, 200, 5}};
|
||||
ReserveStrata gaps{fragmented};
|
||||
fragmented.step();
|
||||
gaps.step();
|
||||
matches(fragmented, gaps);
|
||||
insist(gaps.census().living == 1, "strata did not preserve viable outlier");
|
||||
insist(gaps.portrait().front().identity == 4, "strata compacted away identity");
|
||||
|
||||
auto empty = founding_individuals(0);
|
||||
ReserveStrata vacant{empty};
|
||||
empty.step();
|
||||
vacant.step();
|
||||
matches(empty, vacant);
|
||||
|
||||
const auto source = founding_individuals(100);
|
||||
ReserveStrata whole{source};
|
||||
ReserveStrata partitioned{source};
|
||||
whole.advance(401);
|
||||
partitioned.advance(0);
|
||||
partitioned.advance(1);
|
||||
partitioned.advance(63);
|
||||
partitioned.advance(337);
|
||||
insist(whole.portrait() == partitioned.portrait() && whole.census() == partitioned.census() &&
|
||||
whole.total_energy() == partitioned.total_energy() &&
|
||||
whole.total_matter() == partitioned.total_matter() &&
|
||||
whole.environment() == partitioned.environment() &&
|
||||
whole.matter_store() == partitioned.matter_store() &&
|
||||
whole.next_identity() == partitioned.next_identity(),
|
||||
"strata partition mismatch");
|
||||
|
||||
auto invalid = source;
|
||||
invalid.rule.threshold_energy = invalid.rule.investment_energy - 1;
|
||||
bool rejected = false;
|
||||
try {
|
||||
(void)ReserveStrata{invalid};
|
||||
} catch (const ModelViolation&) {
|
||||
rejected = true;
|
||||
}
|
||||
insist(rejected, "strata admitted unsupported underfunded rule");
|
||||
rejected = false;
|
||||
try {
|
||||
(void)evo::experiment::checked_product(std::numeric_limits<std::uint64_t>::max(), 2);
|
||||
} catch (const ModelViolation&) {
|
||||
rejected = true;
|
||||
}
|
||||
insist(rejected, "strata product overflow was not rejected");
|
||||
}
|
||||
|
||||
IndividualRun seeded(std::uint64_t seed, std::uint64_t supply) {
|
||||
auto run = founding_individuals(0);
|
||||
run.rule.environment_energy = supply;
|
||||
evo::Random random{seed};
|
||||
for (unsigned block = 0; block < 20; ++block) {
|
||||
// Fixed modulo fixture sampling; no gameplay distribution is selected.
|
||||
const Member member{random.next() % 400, random.next() % 180, random.next() % 150};
|
||||
for (unsigned index = 0; index < 5; ++index) {
|
||||
run.members.push_back(member);
|
||||
}
|
||||
}
|
||||
return run;
|
||||
}
|
||||
|
||||
void compare(IndividualRun reference, std::uint64_t seed, std::string_view split,
|
||||
std::uint64_t ticks) {
|
||||
ReserveStrata strata{reference};
|
||||
CompactIndividual compact{reference};
|
||||
const auto energy = reference.total_energy();
|
||||
const auto matter = reference.total_matter();
|
||||
std::size_t peak_rows = strata.groups().size();
|
||||
std::uint64_t peak_living = reference.census().living;
|
||||
matches(reference, strata);
|
||||
for (std::uint64_t tick = 0; tick < ticks; ++tick) {
|
||||
reference.step();
|
||||
strata.step();
|
||||
compact.step();
|
||||
matches(reference, strata);
|
||||
insist(compact.census() == reference.census() && compact.portrait() == strata.portrait() &&
|
||||
compact.run.total_energy() == energy && compact.run.total_matter() == matter &&
|
||||
compact.run.environment == reference.environment &&
|
||||
compact.run.matter_store == reference.matter_store &&
|
||||
compact.run.detritus_energy == reference.detritus_energy &&
|
||||
compact.run.detritus_matter == reference.detritus_matter,
|
||||
"compact cost control diverged");
|
||||
insist(reference.total_energy() == energy && strata.total_energy() == energy,
|
||||
"strata energy conservation failure");
|
||||
insist(reference.total_matter() == matter && strata.total_matter() == matter,
|
||||
"strata matter conservation failure");
|
||||
peak_rows = std::max(peak_rows, strata.groups().size());
|
||||
peak_living = std::max(peak_living, strata.census().living);
|
||||
}
|
||||
std::cout << "{\"kind\":\"comparison\",\"split\":\"" << split << "\",\"seed\":" << seed
|
||||
<< ",\"supply\":" << reference.rule.environment_energy << ",\"ticks\":" << ticks
|
||||
<< ",\"identified_trajectory_exact\":true,\"false_extinction\":false,"
|
||||
"\"population_gap_ppt\":0,\"energy_gap_ppt\":0,\"matter_gap_ppt\":0,"
|
||||
"\"peak_strata\":"
|
||||
<< peak_rows << ",\"peak_living\":" << peak_living
|
||||
<< ",\"final_living\":" << strata.census().living << "}\n";
|
||||
}
|
||||
|
||||
template <typename Run> void timed(Run run, std::uint64_t supply, unsigned sample) {
|
||||
std::size_t peak_rows = 0, peak_payload = 0, peak_capacity = 0;
|
||||
const auto observe = [&] {
|
||||
std::size_t rows = 0, payload = 0, capacity = 0;
|
||||
if constexpr (std::is_same_v<Run, IndividualRun>) {
|
||||
rows = run.members.size();
|
||||
payload = rows * sizeof(Member);
|
||||
capacity = run.members.capacity() * sizeof(Member);
|
||||
} else if constexpr (std::is_same_v<Run, CompactIndividual>) {
|
||||
rows = run.run.members.size();
|
||||
payload = rows * sizeof(Member) + run.identities.size() * sizeof(std::uint64_t);
|
||||
capacity = run.run.members.capacity() * sizeof(Member) +
|
||||
run.identities.capacity() * sizeof(std::uint64_t);
|
||||
} else {
|
||||
rows = run.groups().size();
|
||||
payload = rows * sizeof(evo::experiment::ReserveStratum);
|
||||
capacity = run.capacity_bytes();
|
||||
}
|
||||
peak_rows = std::max(peak_rows, rows);
|
||||
peak_payload = std::max(peak_payload, payload);
|
||||
peak_capacity = std::max(peak_capacity, capacity);
|
||||
};
|
||||
observe();
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
for (unsigned tick = 0; tick < 10'000; ++tick) {
|
||||
run.step();
|
||||
observe();
|
||||
}
|
||||
const auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - start)
|
||||
.count();
|
||||
if (sample == 0) {
|
||||
return;
|
||||
}
|
||||
constexpr auto tier = [] {
|
||||
if constexpr (std::is_same_v<Run, IndividualRun>) {
|
||||
return "historical_individual";
|
||||
} else if constexpr (std::is_same_v<Run, CompactIndividual>) {
|
||||
return "compact_individual";
|
||||
} else {
|
||||
return "exact_strata";
|
||||
}
|
||||
}();
|
||||
std::cout << "{\"kind\":\"timing\",\"tier\":\"" << tier << "\",\"supply\":" << supply
|
||||
<< ",\"sample\":" << sample << ",\"elapsed_ns\":" << ns
|
||||
<< ",\"peak_rows\":" << peak_rows << ",\"peak_payload_bytes\":" << peak_payload
|
||||
<< ",\"peak_capacity_bytes\":" << peak_capacity
|
||||
<< ",\"final_living\":" << run.census().living << "}\n";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) try {
|
||||
if (argc > 2 || (argc == 2 && std::string_view{argv[1]} != "--verify")) {
|
||||
std::fputs("usage: evo-reserve-strata [--verify]\n", stderr);
|
||||
return 2;
|
||||
}
|
||||
std::cout << "{\"kind\":\"metadata\",\"candidate\":\"exact-reserve-strata-1\","
|
||||
"\"reference\":\"resolution-fixture-2\",\"founders\":100,"
|
||||
"\"production_qualified\":false,\"compiler\":\""
|
||||
#if defined(__clang__)
|
||||
<< "Clang " << __clang_version__
|
||||
#elif defined(_MSC_VER)
|
||||
<< "MSVC " << _MSC_VER
|
||||
#else
|
||||
<< "GCC " << __VERSION__
|
||||
#endif
|
||||
<< "\",\"build\":\""
|
||||
#if defined(NDEBUG)
|
||||
<< "release"
|
||||
#else
|
||||
<< "debug"
|
||||
#endif
|
||||
<< "\"}\n";
|
||||
controls();
|
||||
for (const auto supply : {240U, 300U, 360U}) {
|
||||
Rule rule;
|
||||
rule.environment_energy = supply;
|
||||
compare(founding_individuals(100, rule), 0, "historical", 10'000);
|
||||
if (argc == 1) {
|
||||
for (unsigned sample = 0; sample <= 3; ++sample) {
|
||||
const auto source = founding_individuals(100, rule);
|
||||
if (sample % 2 == 0) {
|
||||
timed(source, supply, sample);
|
||||
timed(CompactIndividual{source}, supply, sample);
|
||||
timed(ReserveStrata{source}, supply, sample);
|
||||
} else {
|
||||
timed(ReserveStrata{source}, supply, sample);
|
||||
timed(CompactIndividual{source}, supply, sample);
|
||||
timed(source, supply, sample);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (std::uint64_t seed = 0; seed < 16; ++seed) {
|
||||
for (const auto supply : {180U, 240U, 300U, 360U, 480U}) {
|
||||
compare(seeded(seed, supply), seed, seed < 8 ? "development" : "holdout", 1'500);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
} catch (const evo::fixture::ModelViolation& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what);
|
||||
return 1;
|
||||
} catch (const std::exception& error) {
|
||||
std::fprintf(stderr, "%s\n", error.what());
|
||||
return 1;
|
||||
} catch (...) {
|
||||
std::fputs("unknown reserve-strata failure\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
#pragma once
|
||||
|
||||
// ADR-0134: an isolated exact-state experiment, not Cohort v1 or runtime biology.
|
||||
#include "../../tests/fixtures/resolution_model.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
#include <numeric>
|
||||
#include <span>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace evo::experiment {
|
||||
using fixture::insist;
|
||||
|
||||
inline std::uint64_t checked_add(std::uint64_t left, std::uint64_t right) {
|
||||
insist(right <= std::numeric_limits<std::uint64_t>::max() - left, "strata sum overflow");
|
||||
return left + right;
|
||||
}
|
||||
inline std::uint64_t checked_product(std::uint64_t left, std::uint64_t right) {
|
||||
insist(right == 0 || left <= std::numeric_limits<std::uint64_t>::max() / right,
|
||||
"strata product overflow");
|
||||
return left * right;
|
||||
}
|
||||
|
||||
struct ReserveStratum {
|
||||
std::uint64_t first{}, count{}, age{}, energy{}, matter{};
|
||||
auto operator<=>(const ReserveStratum&) const = default;
|
||||
};
|
||||
struct IdentifiedReserve {
|
||||
std::uint64_t identity{}, age{}, energy{}, matter{};
|
||||
auto operator<=>(const IdentifiedReserve&) const = default;
|
||||
};
|
||||
|
||||
class ReserveStrata {
|
||||
public:
|
||||
explicit ReserveStrata(const fixture::IndividualRun& source)
|
||||
: rule_{source.rule}, next_identity_{source.members.size()},
|
||||
environment_{source.environment}, matter_store_{source.matter_store},
|
||||
detritus_energy_{source.detritus_energy}, detritus_matter_{source.detritus_matter},
|
||||
births_{source.births}, deaths_{source.deaths} {
|
||||
insist(rule_.threshold_energy >= rule_.investment_energy,
|
||||
"strata unsupported underfunded breeding rule");
|
||||
for (std::size_t index = 0; index < source.members.size(); ++index) {
|
||||
const auto& member = source.members[index];
|
||||
if (member.alive) {
|
||||
append(groups_, {index, 1, member.age, member.energy, member.matter});
|
||||
}
|
||||
}
|
||||
// Validate the exact totals rather than trusting wrapped reference sums.
|
||||
(void)total_energy();
|
||||
(void)total_matter();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::span<const ReserveStratum> groups() const noexcept {
|
||||
return groups_;
|
||||
}
|
||||
[[nodiscard]] std::size_t capacity_bytes() const noexcept {
|
||||
return groups_.capacity() * sizeof(ReserveStratum);
|
||||
}
|
||||
[[nodiscard]] fixture::Census census() const {
|
||||
fixture::Census result;
|
||||
result.births = births_;
|
||||
result.deaths = deaths_;
|
||||
for (const auto& group : groups_) {
|
||||
result.living = checked_add(result.living, group.count);
|
||||
result.energy = checked_add(result.energy, checked_product(group.count, group.energy));
|
||||
result.matter = checked_add(result.matter, checked_product(group.count, group.matter));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
[[nodiscard]] std::uint64_t total_energy() const {
|
||||
return checked_add(checked_add(environment_, detritus_energy_), census().energy);
|
||||
}
|
||||
[[nodiscard]] std::uint64_t total_matter() const {
|
||||
return checked_add(checked_add(matter_store_, detritus_matter_), census().matter);
|
||||
}
|
||||
[[nodiscard]] std::uint64_t environment() const noexcept {
|
||||
return environment_;
|
||||
}
|
||||
[[nodiscard]] std::uint64_t matter_store() const noexcept {
|
||||
return matter_store_;
|
||||
}
|
||||
[[nodiscard]] std::uint64_t detritus_energy() const noexcept {
|
||||
return detritus_energy_;
|
||||
}
|
||||
[[nodiscard]] std::uint64_t detritus_matter() const noexcept {
|
||||
return detritus_matter_;
|
||||
}
|
||||
[[nodiscard]] std::uint64_t next_identity() const noexcept {
|
||||
return next_identity_;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<IdentifiedReserve> portrait() const {
|
||||
std::vector<IdentifiedReserve> result;
|
||||
for (const auto& group : groups_) {
|
||||
for (std::uint64_t index = 0; index < group.count; ++index) {
|
||||
result.push_back(
|
||||
{checked_add(group.first, index), group.age, group.energy, group.matter});
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void advance(std::uint64_t ticks) {
|
||||
// Interval partitioning only; never replace fixed steps with a larger dt.
|
||||
for (std::uint64_t tick = 0; tick < ticks; ++tick) {
|
||||
step();
|
||||
}
|
||||
}
|
||||
|
||||
void step() {
|
||||
const auto share = rule_.per_capita(census().living); // Before starvation, like reference.
|
||||
for (auto& group : groups_) {
|
||||
if (rule_.starves(group.energy)) {
|
||||
retire(group);
|
||||
continue;
|
||||
}
|
||||
group.energy -= rule_.upkeep_energy;
|
||||
detritus_energy_ =
|
||||
checked_add(detritus_energy_, checked_product(group.count, rule_.upkeep_energy));
|
||||
const auto paid = std::min(group.matter, rule_.upkeep_matter);
|
||||
group.matter -= paid;
|
||||
detritus_matter_ = checked_add(detritus_matter_, checked_product(group.count, paid));
|
||||
const auto energy = checked_product(group.count, share);
|
||||
const auto matter = checked_product(group.count, rule_.matter_intake);
|
||||
insist(environment_ >= energy, "strata environment depleted");
|
||||
insist(matter_store_ >= matter, "strata matter store depleted");
|
||||
environment_ -= energy;
|
||||
matter_store_ -= matter;
|
||||
group.energy = checked_add(group.energy, share);
|
||||
group.matter = checked_add(group.matter, rule_.matter_intake);
|
||||
group.age = checked_add(group.age, 1);
|
||||
if (group.age >= rule_.lifespan) {
|
||||
retire(group);
|
||||
}
|
||||
}
|
||||
std::erase_if(groups_, [](const auto& group) { return group.count == 0; });
|
||||
|
||||
auto population = census().living;
|
||||
std::vector<std::size_t> order(groups_.size());
|
||||
std::iota(order.begin(), order.end(), std::size_t{0});
|
||||
std::ranges::sort(order, [&](std::size_t left, std::size_t right) {
|
||||
if (groups_[left].age != groups_[right].age) {
|
||||
return groups_[left].age > groups_[right].age;
|
||||
}
|
||||
return groups_[left].first < groups_[right].first;
|
||||
});
|
||||
std::vector<std::uint64_t> reproducing(groups_.size());
|
||||
std::uint64_t newborns = 0;
|
||||
for (const auto index : order) {
|
||||
const auto& group = groups_[index];
|
||||
if (population >= rule_.capacity) {
|
||||
break;
|
||||
}
|
||||
if (!rule_.breeds(group.age, group.energy) || group.matter < rule_.investment_matter) {
|
||||
continue;
|
||||
}
|
||||
const auto count = std::min(group.count, rule_.capacity - population);
|
||||
reproducing[index] = count;
|
||||
population = checked_add(population, count);
|
||||
newborns = checked_add(newborns, count);
|
||||
}
|
||||
std::vector<ReserveStratum> after;
|
||||
for (std::size_t index = 0; index < groups_.size(); ++index) {
|
||||
auto group = groups_[index];
|
||||
const auto count = reproducing[index];
|
||||
if (count != 0) {
|
||||
append(after,
|
||||
{group.first, count, group.age, group.energy - rule_.investment_energy,
|
||||
group.matter - rule_.investment_matter});
|
||||
group.first = checked_add(group.first, count);
|
||||
group.count -= count;
|
||||
}
|
||||
append(after, group);
|
||||
}
|
||||
append(after,
|
||||
{next_identity_, newborns, 0, rule_.investment_energy, rule_.investment_matter});
|
||||
next_identity_ = checked_add(next_identity_, newborns);
|
||||
births_ = checked_add(births_, newborns);
|
||||
groups_ = std::move(after);
|
||||
}
|
||||
|
||||
private:
|
||||
static void append(std::vector<ReserveStratum>& target, ReserveStratum group) {
|
||||
if (group.count == 0) {
|
||||
return;
|
||||
}
|
||||
(void)checked_add(group.first, group.count);
|
||||
if (!target.empty()) {
|
||||
auto& previous = target.back();
|
||||
if (checked_add(previous.first, previous.count) == group.first &&
|
||||
previous.age == group.age && previous.energy == group.energy &&
|
||||
previous.matter == group.matter) {
|
||||
previous.count = checked_add(previous.count, group.count);
|
||||
return;
|
||||
}
|
||||
}
|
||||
target.push_back(group);
|
||||
}
|
||||
void retire(ReserveStratum& group) {
|
||||
detritus_energy_ =
|
||||
checked_add(detritus_energy_, checked_product(group.count, group.energy));
|
||||
detritus_matter_ =
|
||||
checked_add(detritus_matter_, checked_product(group.count, group.matter));
|
||||
deaths_ = checked_add(deaths_, group.count);
|
||||
group.count = 0;
|
||||
}
|
||||
fixture::Rule rule_;
|
||||
std::uint64_t next_identity_{};
|
||||
std::vector<ReserveStratum> groups_;
|
||||
std::uint64_t environment_{}, matter_store_{}, detritus_energy_{}, detritus_matter_{};
|
||||
std::uint64_t births_{}, deaths_{};
|
||||
};
|
||||
} // namespace evo::experiment
|
||||
Reference in New Issue
Block a user