65 std::discrete_distribution<int> pick({0.10, 0.45, 0.45});
68 lat.set({static_cast<ca_index_t>(i), static_cast<ca_index_t>(j)},
76 case Schelling_Cell::EMPTY:
return '.';
77 case Schelling_Cell::TYPE_A:
return 'A';
78 case Schelling_Cell::TYPE_B:
return 'B';
89 static_cast<ca_index_t>(j)}));
100 std::size_t
total = 0;
108 if (c ==
static_cast<int>(Schelling_Cell::EMPTY))
118 if (right !=
static_cast<int>(Schelling_Cell::EMPTY))
121 if (right == c) ++
same;
123 if (
down !=
static_cast<int>(Schelling_Cell::EMPTY))
129 return total == 0 ? 0.0
130 :
static_cast<double>(
same) /
static_cast<double>(
total);
133std::string
bar(
double v, std::size_t width = 40)
136 = std::min(width,
static_cast<std::size_t
>(v *
static_cast<double>(width)));
137 return std::string(
k,
'|') + std::string(width -
k,
' ');
142 std::uint64_t master_seed,
145 std::cout <<
"\n========================================\n";
146 std::cout <<
" Schelling threshold = "
147 << std::fixed << std::setprecision(2) << threshold
150 <<
" seed = 0x" << std::hex << master_seed << std::dec <<
'\n';
151 std::cout <<
"========================================\n";
159 std::cout <<
" same-type edge fraction (initial) = "
160 << std::fixed << std::setprecision(3) <<
q0 << std::defaultfloat
161 <<
" [" <<
bar(
q0) <<
"]\n";
166 std::cout <<
" same-type edge fraction (final) = "
167 << std::fixed << std::setprecision(3) << q1 << std::defaultfloat
168 <<
" [" <<
bar(q1) <<
"]\n";
170 std::cout <<
"\nFinal configuration:\n";
180 constexpr std::uint64_t master_seed = 0x5C4E11Aull;
183 std::cout <<
"Schelling-style local segregation on a 48x48 toroidal lattice\n";
184 std::cout <<
" Moore radius 1, two types of agents + 10% vacancy\n";
185 std::cout <<
" same-type edge fraction is a cluster-quality proxy:\n";
186 std::cout <<
" ~0.50 = mixed ~1.00 = perfectly segregated\n";
191 std::cout <<
"\nInitial configuration (shared by every scenario):\n";
194 std::cout <<
"same-type edge fraction = "
195 << std::fixed << std::setprecision(3) <<
q_seed << std::defaultfloat
198 for (
const double threshold : {0.30, 0.50, 0.70})
201 std::cout <<
"\nNote: master_seed and the initial frame are shared across\n"
202 " threshold scenarios, so the trace is reproducible\n"
203 " bit-for-bit on any thread count.\n";
Reproducible random-number support for stochastic CA rules (Phase 8).
Common typedefs and tag types for the Cellular Automata module.
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.
Synchronous double-buffered engine.
static void bar(int val, int scale=1)
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.
Schelling_Cell
Discrete states of the Schelling automaton.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
Main namespace for Aleph-w library functions.
The lattice wraps around on every axis.
Synchronous double-buffered engine for cellular automata.
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).