59 std::discrete_distribution<int> pick({0.20, 0.40, 0.40});
62 g.set({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)},
74 const auto self = g.at({
static_cast<ca_index_t>(i),
79 std::size_t
other = 0;
85 const auto v = g.at_safe({
static_cast<ca_index_t>(i) +
di,
97 accum +=
static_cast<double>(
same) /
static_cast<double>(
total);
101 return agents == 0 ? 0.0 : accum /
static_cast<double>(
agents);
105void render(
const Grid &g, std::ostream &
os)
107 for (
ca_size_t i = 0; i < g.size(0); ++i)
109 for (
ca_size_t j = 0; j < g.size(1); ++j)
111 const auto v = g.at({
static_cast<ca_index_t>(i),
113 os << (v == 0 ?
" " : v == 1 ?
"AA" :
"BB");
123 std::size_t
steps = 30;
126 if (
argc >= 2)
steps =
static_cast<std::size_t
>(std::stoul(
argv[1]));
133 std::cout <<
"Schelling segregation: same rule, three schemes\n";
134 std::cout <<
" side = " <<
side <<
", steps = " <<
steps
135 <<
", seed = 0x" << std::hex <<
seed_value << std::dec <<
"\n\n";
136 std::cout <<
"Initial frame (segregation index "
145 std::cout <<
"Synchronous_Update (double-buffer) — segregation "
147 render(sync.frame(), std::cout);
154 std::cout <<
"Sequential_Update (in-place) — segregation "
156 render(seq.frame(), std::cout);
164 static_cast<std::size_t
>(
side *
side)});
166 std::cout <<
"Random_Asynchronous_Update — segregation "
172 <<
"Compare segregation indices: typically the asynchronous schemes\n"
173 <<
"converge more smoothly to higher segregation than synchronous\n"
174 <<
"ones, because synchronous updates can swap occupants in lockstep\n"
175 <<
"and oscillate.\n";
Reproducible random-number support for stochastic CA rules (Phase 8).
Common typedefs and tag types for the Cellular Automata module.
Update-scheme aware engine.
Lattice that adds boundary-aware access on top of a storage.
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Local approximation of the Schelling segregation model.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
std::ptrdiff_t ca_index_t
Signed coordinate component used by lattices and neighborhoods.
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.
Pick one cell at random per sub-step, update it in place.
In-place sequential update (no double buffer).
Classical double-buffer synchronous update.
The lattice wraps around on every axis.
Phase 13 update-scheme aware engine.
Cellular automata lattice with pluggable boundary policies.
Neighborhoods catalogue for Aleph::CA.
Reproducible stochastic CA rules (Phase 8).
Dense, contiguous storage for cellular automata cells (1D/2D/3D).
Phase 13 update-scheme strategies for Aleph::CA.