55#include <gtest/gtest.h>
76struct Discrete_Predator_Prey_Rule
80 using fields = std::tuple<std::int32_t, std::int32_t>;
84 std::int32_t operator()(
const fields &
cur,
const nb_views &
nb)
const noexcept =
delete;
88 const auto prey = std::get<0>(
cur);
89 const auto pred = std::get<1>(
cur);
106 using fields = std::tuple<std::int32_t, std::int32_t>;
109 fields operator()(
const fields &
cur,
const nb_views &
nb)
const noexcept
111 const auto prey = std::get<0>(
cur);
112 const auto pred = std::get<1>(
cur);
123template <
typename Layout>
125 std::int32_t, std::int32_t>;
127template <
typename Layout>
135 const std::int32_t
prey =
static_cast<std::int32_t
>((i + j +
seed) % 7);
136 const std::int32_t
pred =
static_cast<std::int32_t
>((i * 2 + j +
seed) % 5);
145template <
typename A,
typename B>
148 if (a.extents() != b.extents())
150 for (
ca_size_t i = 0; i < a.size(0); ++i)
151 for (
ca_size_t j = 0; j < a.size(1); ++j)
154 if (a.template
at<0>(c) != b.template
at<0>(c))
156 if (a.template
at<1>(c) != b.template
at<1>(c))
182 for (std::size_t t = 0; t < 25; ++t)
185 <<
"diverged at step " << t;
190 <<
"diverged after 25 steps";
206 static_cast<int>((i + j) & 1));
218 lat.at<1>({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)}),
234class Multi_Field_Gray_Scott
236 double feed_, kill_, du_, dv_, dt_;
240 Multi_Field_Gray_Scott(
double feed,
double kill,
double du,
double dv,
double dt = 1.0)
241 : feed_(feed), kill_(kill), du_(
du), dv_(
dv), dt_(dt)
244 std::tuple<double, double>
245 operator()(
const std::tuple<double, double> &
cur,
248 const double u = std::get<0>(
cur);
249 const double v = std::get<1>(
cur);
250 const auto &
uv = std::get<0>(
nb);
251 const auto &
vv = std::get<1>(
nb);
254 for (std::size_t
k = 0;
k <
uv.size(); ++
k)
256 for (std::size_t
k = 0;
k <
vv.size(); ++
k)
258 const double uvv = u * v * v;
259 double next_u = u + dt_ * (du_ *
lu -
uvv + feed_ * (1.0 - u));
260 double next_v = v + dt_ * (dv_ *
lv +
uvv - (feed_ + kill_) * v);
297 std::move(
mf), Multi_Field_Gray_Scott{0.0367, 0.0649, 0.16, 0.08, 1.0},
300 for (std::size_t t = 0; t < 50; ++t)
321 const Cell
mc =
meng.frame().at(c);
323 <<
"u differs at (" << i <<
"," << j <<
")";
325 <<
"v differs at (" << i <<
"," << j <<
")";
336class Lotka_Volterra_Rule
338 double alpha_, beta_, delta_, gamma_, dt_;
342 Lotka_Volterra_Rule(
double alpha,
double beta,
double delta,
double gamma,
344 : alpha_(alpha), beta_(beta), delta_(
delta), gamma_(
gamma), dt_(dt),
347 std::tuple<double, double>
348 operator()(
const std::tuple<double, double> &
cur,
351 const double prey = std::get<0>(
cur);
352 const double pred = std::get<1>(
cur);
354 double prey_lap = -
static_cast<double>(std::get<0>(
nb).size()) *
prey;
355 double pred_lap = -
static_cast<double>(std::get<1>(
nb).size()) *
pred;
385 std::move(
lat), Lotka_Volterra_Rule{1.0, 0.5, 0.4, 0.5, 0.05, 0.05},
394 for (std::size_t t = 0; t < 200; ++t)
405 ASSERT_GE(
eng.frame().at<0>(c), 0.0) <<
"prey<0 at step " << t;
406 ASSERT_GE(
eng.frame().at<1>(c), 0.0) <<
"pred<0 at step " << t;
407 ASSERT_LT(
eng.frame().at<0>(c), 1
e6) <<
"prey blew up at step " << t;
408 ASSERT_LT(
eng.frame().at<1>(c), 1
e6) <<
"pred blew up at step " << t;
423 if ((b > a
and b > c)
or (b < a
and b < c))
427 <<
"Lotka-Volterra prey trajectory shows no oscillation";
437 L lat({3, 3}, std::tuple{0, 7});
459 EXPECT_EQ(
eng.frame().at<0>({static_cast<ca_index_t>(1),
460 static_cast<ca_index_t>(1)}),
466 EXPECT_EQ(
eng.frame().at<0>({static_cast<ca_index_t>(i),
467 static_cast<ca_index_t>(j)}),
Common typedefs and tag types for the Cellular Automata module.
Adaptor: apply a mono-field rule to field I, leave the other fields unchanged.
Gray-Scott reaction-diffusion rule.
Dense odd-sized 2-D convolution kernel.
T neighbour_weight(const std::size_t k) const
Return a centre-skipping neighbour weight.
constexpr T center() const noexcept
Return the centre weight.
Lattice that adds boundary-aware access on top of a storage.
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Synchronous double-buffered engine for multi-field lattices.
void step()
Apply the multi-field rule to every cell once and swap buffers.
Multi-field lattice with selectable storage layout.
auto & field()
Mutable reference to the underlying single-field lattice for field I.
void set(const coord_type &c, const V &v)
Strict write access to field I.
Synchronous double-buffered engine.
Von Neumann (L1) neighborhood of radius R in N dimensions.
__gmp_expr< T, __gmp_unary_expr< __gmp_expr< T, U >, __gmp_gamma_function > > gamma(const __gmp_expr< T, U > &expr)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Freq_Node * pred
Predecessor node in level-order traversal.
constexpr std::uint32_t delta
File contains only the cells that changed relative to a baseline.
constexpr Game_Of_Life_Rule make_game_of_life_rule() noexcept
Build the canonical Game of Life rule.
std::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
std::array< ca_index_t, N > Coord_Vec
Default coordinate vector.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Outer_Totalistic_Rule< Game_Of_Life_Functor > Game_Of_Life_Rule
Outer-totalistic rule type implementing Conway's Game of Life.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Out-of-range neighbours behave as if the lattice ended.
Two-field state for reaction-diffusion cellular automata.
The lattice wraps around on every axis.
Continuous and memory-bearing CA rules (Phase 9).
Synchronous double-buffered engine for cellular automata.
Cellular automata lattice with pluggable boundary policies.
Phase 14 synchronous double-buffered engine for multi-field cellular automata.
Phase 14 multi-field cellular automata lattice (AoS / SoA).
Phase 14 multi-field local rules for Aleph::CA.
Neighborhoods catalogue for Aleph::CA.
Rule mechanisms for Aleph::CA.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).