43#include <system_error>
59class Lotka_Volterra_Rule
61 double alpha_, beta_, delta_, gamma_, dt_, diff_;
64 Lotka_Volterra_Rule(
double alpha,
double beta,
double delta,
double gamma,
66 : alpha_(alpha), beta_(beta), delta_(
delta), gamma_(
gamma), dt_(dt),
70 std::tuple<double, double>
71 operator()(
const std::tuple<double, double> &
cur,
74 const double x = std::get<0>(
cur);
75 const double y = std::get<1>(
cur);
76 double lap_x = -
static_cast<double>(std::get<0>(
nb).size()) * x;
77 double lap_y = -
static_cast<double>(std::get<1>(
nb).size()) *
y;
78 for (
const auto &p :
std::get<0>(
nb))
lap_x += p;
79 for (
const auto &p :
std::get<1>(
nb))
lap_y += p;
80 const double next_x = x + dt_ * (alpha_ * x - beta_ * x *
y + diff_ *
lap_x);
81 const double next_y =
y + dt_ * (delta_ * x *
y - gamma_ *
y + diff_ *
lap_y);
90 lat.fill(std::tuple{1.0, 0.5});
104 if (x > 1.5
and y < 0.4)
return 'X';
105 if (
y > 0.7
and x < 0.6)
return 'O';
106 if (x > 1.0
and y > 0.4)
return '#';
107 if (x < 0.3
and y < 0.3)
return '.';
119 const double x =
lat.at<0>(c);
120 const double y =
lat.at<1>(c);
127 os <<
"step " << step <<
" Σprey=" <<
x_total <<
" Σpred=" <<
y_total <<
"\n";
136bool parse_u64(
const char *text, std::uint64_t &
out)
noexcept
140 const std::string_view
sv{text};
146 if (
sv.front() ==
'+' or sv.front() ==
'-')
148 std::uint64_t
value = 0;
149 const auto *first =
sv.data();
150 const auto *last = first +
sv.size();
151 const auto [ptr,
ec] = std::from_chars(first, last,
value, 10);
152 if (
ec != std::errc{}
or ptr != last)
162 std::size_t
steps = 200;
169 std::cerr <<
"Invalid [steps]: expected a non-negative integer (got '" <<
argv[1]
173 if (
parsed > std::numeric_limits<std::size_t>::max())
175 std::cerr <<
"[steps] out of range\n";
184 std::cerr <<
"Invalid [side]: expected a non-negative integer (got '" <<
argv[2]
188 if (
parsed > std::numeric_limits<ca_size_t>::max())
190 std::cerr <<
"[side] out of range\n";
197 std::cerr <<
"Invalid side: must be ≥ 4 (need a centre with surrounding cells)\n";
204 std::cout <<
"Lotka–Volterra multi-field CA (SoA) — " <<
side <<
"×" <<
side
205 <<
", " <<
steps <<
" steps\n";
206 std::cout <<
"Glyphs: '.' depleted '+' mixed '#' rich 'X' prey-rich 'O' predator surge\n\n";
210 Lotka_Volterra_Rule{1.0, 0.5, 0.4,
214 std::cout <<
"Initial frame:\n";
219 for (std::size_t t = 0; t <
steps; ++t)
224 std::cout <<
"\nSnapshot:\n";
size_t size_t int32_t value
size_t size_t int32_t * out
Common typedefs and tag types for the Cellular Automata module.
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.
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().
constexpr std::uint32_t delta
File contains only the cells that changed relative to a baseline.
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.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Phase 14 synchronous double-buffered engine for multi-field cellular automata.
Phase 14 multi-field cellular automata lattice (AoS / SoA).
Neighborhoods catalogue for Aleph::CA.