66 mutable std::uint64_t calls_ = 0;
75 std::uint64_t key = seed_;
76 key = (key * 1099511628211ull) ^ (calls_ + 1);
78 std::mt19937_64
rng(key);
79 std::uniform_int_distribution<std::size_t> pick(0,
neigh.size() - 1);
90 auto edge = [&](std::size_t a, std::size_t b)
96 edge(0, 1); edge(0, 2); edge(1, 2);
98 edge(0, 3); edge(0, 4); edge(3, 4);
100 edge(0, 5); edge(0, 6); edge(5, 6);
106 std::printf(
"Step %4zu :", step);
107 for (std::size_t n = 0; n <
lat.size(); ++n)
108 std::printf(
" %d",
lat.at_node(n));
116 std::ostringstream
os;
117 os <<
"% Aleph::CA voter model bowtie\n";
118 os <<
"\\begin{tikzpicture}[node distance=1.5cm]\n";
119 const double radius = 2.0;
120 const double pi = 3.14159265358979323846;
121 std::array<std::array<double, 2>, 7> pos{};
123 for (
int t = 0; t < 3; ++t)
125 const double theta0 = (2 * pi / 3.0) *
static_cast<double>(t);
126 pos[1 + 2 * t] = {radius * std::cos(
theta0 - 0.3),
127 radius * std::sin(
theta0 - 0.3)};
128 pos[2 + 2 * t] = {radius * std::cos(
theta0 + 0.3),
129 radius * std::sin(
theta0 + 0.3)};
132 for (std::size_t n = 0; n < 7; ++n)
134 const char *
colour =
lat.at_node(n) != 0 ?
"red!60" :
"blue!60";
135 os <<
" \\node[circle, draw, fill=" <<
colour
136 <<
", inner sep=2pt, minimum size=6mm] (n" << n <<
") at (" << pos[n][0]
137 <<
", " << pos[n][1] <<
") {" << n <<
"};\n";
140 for (std::size_t a = 0; a < 7; ++a)
141 for (std::size_t b :
lat.neighbours(a))
143 os <<
" \\draw (n" << a <<
") -- (n" << b <<
");\n";
144 os <<
"\\end{tikzpicture}\n";
155 seed.set_node(1, 1);
seed.set_node(2, 1);
156 seed.set_node(3, 0);
seed.set_node(4, 0);
157 seed.set_node(5, 1);
seed.set_node(6, 1);
159 std::printf(
"Aleph::CA Phase-6 example: voter model on a 7-node bowtie graph\n");
167 for (std::size_t s = 1; s <= 5000; ++s)
170 if ((s % 200) == 0
or s == 1)
173 const int v0 =
eng.frame().at_node(0);
174 for (std::size_t n = 1; n <
eng.frame().
size(); ++n)
175 if (
eng.frame().at_node(n) !=
v0)
183 std::printf(
"Consensus on value %d reached at step %zu\n",
v0, s);
190 std::printf(
"Did not reach consensus within 5000 steps; final state:\n");
194 std::printf(
"\n--- TikZ render of final state ---\n");
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Graph lattice: one cell per node + precomputed adjacency.
Synchronous double-buffered engine for graph CAs.
void step()
Apply the rule to every node once and swap buffers.
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::span< const T > Neighbor_View
Read-only view over a contiguous range of neighbour values.
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
CA whose underlying topology is an arbitrary undirected graph.