51#include <gtest/gtest.h>
98 for (
const auto &
row : adj)
111 for (
const auto &
row : adj)
133 for (std::size_t n = 0; n <
lat.size(); ++n)
134 lat.set_node(n,
static_cast<int>(n + 1));
135 for (std::size_t n = 0; n <
lat.size(); ++n)
155 for (std::size_t n = 0; n <
lat.size(); ++n)
167struct Majority_Functor
171 std::size_t alive = 0;
175 const std::size_t
deg =
neigh.size();
188class Voter_Rule_Driver
191 mutable std::uint64_t calls_ = 0;
200 std::uint64_t key = seed_;
201 key = (key * 1099511628211ull) ^ (calls_ + 1);
203 std::mt19937_64
rng(key);
204 std::uniform_int_distribution<std::size_t> pick(0,
neigh.size() - 1);
214 using Rule = Majority_Functor;
217 for (std::size_t n = 0; n <
eng.frame().
size(); ++n)
224 using Rule = Majority_Functor;
227 for (std::size_t n = 0; n <
eng.frame().
size(); ++n)
239 seed, Majority_Functor{});
241 for (std::size_t n = 0; n <
eng.frame().
size(); ++n)
253 auto edge = [&](std::size_t a, std::size_t b)
258 edge(0, 1); edge(0, 2); edge(1, 2);
259 edge(0, 3); edge(0, 4); edge(3, 4);
260 edge(0, 5); edge(0, 6); edge(5, 6);
263 seed.set_node(1, 1);
seed.set_node(2, 1);
264 seed.set_node(5, 1);
seed.set_node(6, 1);
266 Voter_Rule_Driver
driver(2026u);
271 const int v0 =
eng.frame().at_node(0);
272 for (std::size_t n = 1; n <
eng.frame().
size(); ++n)
274 <<
"voter model did not reach consensus on the bowtie graph";
282 seed, Majority_Functor{});
285 std::size_t
post = 0;
317 std::vector<int>
initial(16, 0);
324 for (std::size_t n = 0; n <
seed.size(); ++n)
333 for (std::size_t n = 0; n <
eng.frame().
size(); ++n)
335 <<
"block at node " << n <<
" was not still under graph engine";
Common typedefs and tag types for the Cellular Automata module.
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.
ca_size_t size() const noexcept
Coord_Vec< 1 > coord_type
Synchronous double-buffered engine for graph CAs.
void run(const std::size_t steps)
Run several synchronous steps.
void on_pre_step(F &&f)
Register a hook fired before every step().
Rule whose next state depends on (current, alive_count).
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.
Array< Array< std::size_t > > make_grid_graph_adjacency(std::size_t rows, std::size_t cols, bool periodic=false)
Build the adjacency of a 2D 4-neighbour grid graph.
Array< Array< std::size_t > > make_path_graph_adjacency(std::size_t n, bool cycle=false)
Build the adjacency of a path graph with n nodes.
Main namespace for Aleph-w library functions.
size_t size(Node *root) noexcept
Functor implementing Conway's Game of Life canonical rule (B3/S23).
C++20 concepts for the Cellular Automata module.
CA whose underlying topology is an arbitrary undirected graph.
Rule mechanisms for Aleph::CA.