Implement M6.7 bounded environmental interval scheduling
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
#include "evo/processes/environmental_community.hpp"
|
||||
#include "evo/processes/environmental_schedule.hpp"
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <source_location>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -406,6 +409,119 @@ void decay_continuation() {
|
||||
}
|
||||
}
|
||||
}
|
||||
void scheduled_intervals() {
|
||||
for (std::uint64_t rules : {1U, 2U}) {
|
||||
auto c = config();
|
||||
c.rules = rules;
|
||||
c.growth_numerator = 1;
|
||||
if (rules == 2)
|
||||
c.decay.fill(1);
|
||||
auto create = [&]() {
|
||||
auto made =
|
||||
EnvironmentalCommunity::create(c,
|
||||
resources({100, 100, 100, 100, 0, 0, 100, 0, 100, 0},
|
||||
{10, 0, 0, 20, 10, 10, 0, 30, 0, 0}),
|
||||
8000000);
|
||||
CHECK(made);
|
||||
return std::move(*made);
|
||||
};
|
||||
std::array<EnvironmentalInput, 130> inputs{};
|
||||
std::array<EnvironmentalReport, 130> expected{};
|
||||
auto reference = create();
|
||||
for (std::size_t i = 0; i < inputs.size(); ++i) {
|
||||
inputs[i] = {i % 7 == 0 ? 260000U : 290000U, i % 3 == 0 ? 0U : 1U, {}};
|
||||
if (i == 1 || i == 8)
|
||||
inputs[i].bite[0] = 1;
|
||||
if (rules == 2 && i == 16)
|
||||
inputs[i].terminal[1] = 1;
|
||||
if (rules == 2 && i == 32)
|
||||
inputs[i].terminal[0] = 1;
|
||||
auto r = reference->advance(i + 1, inputs[i]);
|
||||
CHECK(r);
|
||||
expected[i] = *r;
|
||||
}
|
||||
for (std::size_t width : {1U, 3U, 17U, 64U}) {
|
||||
auto o = create();
|
||||
for (std::size_t begin = 0; begin < inputs.size();) {
|
||||
const auto end = std::min(begin + width, inputs.size());
|
||||
auto r = schedule_environment(*o, {identity, begin, end, 50000,
|
||||
std::span{inputs}.subspan(begin, end - begin)});
|
||||
CHECK(r && !r->failure && r->committed == end - begin && r->last_tick == end);
|
||||
for (std::size_t j = 0; j < r->committed; ++j)
|
||||
CHECK(r->reports[j] == expected[begin + j]);
|
||||
auto saved = o->snapshot();
|
||||
CHECK(saved);
|
||||
auto pause = schedule_environment(*o, {identity, end, end, 50000, {}});
|
||||
CHECK(pause && !pause->failure && pause->committed == 0 && pause->last_tick == end);
|
||||
CHECK(o->snapshot() == saved);
|
||||
auto restored = EnvironmentalCommunity::restore(*saved, identity, 8000000);
|
||||
CHECK(restored);
|
||||
o = std::move(*restored);
|
||||
begin = end;
|
||||
}
|
||||
CHECK(o->snapshot() == reference->snapshot());
|
||||
}
|
||||
}
|
||||
}
|
||||
void interval_boundaries() {
|
||||
auto o = make();
|
||||
std::array<EnvironmentalInput, 65> inputs{};
|
||||
inputs.fill({290000, 1, {}});
|
||||
const auto initial = o->snapshot();
|
||||
CHECK(initial);
|
||||
const auto reject = [&](EnvironmentalInterval request, EnvironmentalIntervalError error) {
|
||||
auto r = schedule_environment(*o, request);
|
||||
CHECK(!r && r.error() == error);
|
||||
CHECK(o->snapshot() == initial);
|
||||
};
|
||||
reject({{8, 9}, 0, 1, 50000, std::span{inputs}.first(1)}, EnvironmentalIntervalError::identity);
|
||||
reject({identity, 0, 1, 50001, std::span{inputs}.first(1)},
|
||||
EnvironmentalIntervalError::quantum);
|
||||
reject({identity, 1, 2, 50000, std::span{inputs}.first(1)}, EnvironmentalIntervalError::stale);
|
||||
reject({identity, 0, 65, 50000, inputs}, EnvironmentalIntervalError::backlog);
|
||||
reject({identity, 0, std::numeric_limits<std::uint64_t>::max(), 50000, {}},
|
||||
EnvironmentalIntervalError::backlog);
|
||||
reject({identity, 0, 1, 50000, {}}, EnvironmentalIntervalError::input_count);
|
||||
reject({identity, 0, 0, 50000, std::span{inputs}.first(1)},
|
||||
EnvironmentalIntervalError::input_count);
|
||||
auto maximum = schedule_environment(*o, {identity, 0, 64, 50000, std::span{inputs}.first(64)});
|
||||
CHECK(maximum && !maximum->failure && maximum->committed == 64);
|
||||
const auto saved = o->snapshot();
|
||||
CHECK(saved);
|
||||
auto stale = schedule_environment(*o, {identity, 0, 64, 50000, std::span{inputs}.first(64)});
|
||||
CHECK(!stale && stale.error() == EnvironmentalIntervalError::stale);
|
||||
auto reversed = schedule_environment(*o, {identity, 64, 63, 50000, {}});
|
||||
CHECK(!reversed && reversed.error() == EnvironmentalIntervalError::range);
|
||||
CHECK(o->snapshot() == saved);
|
||||
|
||||
for (std::size_t failed_at : {0U, 2U, 3U}) {
|
||||
auto partial = make();
|
||||
auto reference = make();
|
||||
std::array<EnvironmentalInput, 4> commands{};
|
||||
commands.fill({290000, 1, {}});
|
||||
commands[failed_at].temperature_mK = 0;
|
||||
auto r = schedule_environment(*partial, {identity, 0, 4, 50000, commands});
|
||||
CHECK(r && r->failure && r->committed == failed_at && r->last_tick == failed_at);
|
||||
const auto failure = r->failure;
|
||||
if (!failure)
|
||||
throw std::runtime_error("missing interval failure");
|
||||
CHECK(failure->tick == failed_at + 1 && failure->cause == CommunityError::input);
|
||||
for (std::size_t j = 0; j < failed_at; ++j)
|
||||
CHECK(reference->advance(j + 1, commands[j]) == r->reports[j]);
|
||||
CHECK(partial->snapshot() == reference->snapshot());
|
||||
auto bytes = partial->snapshot();
|
||||
CHECK(bytes);
|
||||
auto restored = EnvironmentalCommunity::restore(*bytes, identity, 8000000);
|
||||
CHECK(restored);
|
||||
commands[failed_at].temperature_mK = 290000;
|
||||
auto remaining = std::span{commands}.subspan(failed_at);
|
||||
auto resumed = schedule_environment(**restored, {identity, failed_at, 4, 50000, remaining});
|
||||
CHECK(resumed && !resumed->failure && resumed->committed == remaining.size());
|
||||
for (std::size_t j = failed_at; j < commands.size(); ++j)
|
||||
CHECK(reference->advance(j + 1, commands[j]));
|
||||
CHECK((*restored)->snapshot() == reference->snapshot());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
int main() {
|
||||
try {
|
||||
@@ -415,6 +531,8 @@ int main() {
|
||||
terminal_decay();
|
||||
terminal_codec_validation();
|
||||
decay_continuation();
|
||||
scheduled_intervals();
|
||||
interval_boundaries();
|
||||
return 0;
|
||||
} catch (const std::exception& e) {
|
||||
std::fprintf(stderr, "%s\n", e.what());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "evo/core/random.hpp"
|
||||
#include "evo/processes/environmental_community.hpp"
|
||||
#include "evo/processes/environmental_schedule.hpp"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
@@ -340,6 +341,10 @@ void exhausted_tick() {
|
||||
CHECK((*restored)->advance(maximum, input)); // exact retry remains legal
|
||||
CHECK(!(*restored)->advance(0, input)); // cannot wrap
|
||||
CHECK(!(*restored)->advance(maximum - 64, input)); // outside retained window
|
||||
auto pause = schedule_environment(**restored, {identity, maximum, maximum, 50000, {}});
|
||||
CHECK(pause && !pause->failure && pause->committed == 0 && pause->last_tick == maximum);
|
||||
auto wrap = schedule_environment(**restored, {identity, maximum, 0, 50000, {&input, 1}});
|
||||
CHECK(!wrap && wrap.error() == EnvironmentalIntervalError::range);
|
||||
CHECK(bytes(**restored) == b);
|
||||
}
|
||||
void sequences(std::uint64_t ticks) {
|
||||
|
||||
Reference in New Issue
Block a user