55#ifndef TPL_CA_ENGINE_H
56#define TPL_CA_ENGINE_H
73namespace ca_engine_detail {
80template <std::
size_t W, std::
size_t H>
89template <
typename Coord,
typename F>
101template <
typename Coord,
typename F>
115template <
typename Coord,
typename F>
130template <std::
size_t W, std::
size_t H,
typename Coord,
typename F>
150template <
typename Coord,
typename F>
182template <
typename Lattice,
typename Rule,
typename Neighborhood,
typename Order = RowMajor>
187 "Synchronous_Engine requires a NeighborhoodLike neighborhood");
189 static_assert(Neighborhood::rank_v ==
Lattice::rank,
"Neighborhood rank must match lattice rank");
258 requires std::default_initializable<Neighborhood>
335 template <
typename F>
346 template <
typename F>
365 using namespace ca_engine_detail;
379 std::array<state_type, neighbour_count>
nbuf{};
393 if constexpr (
rank == 1)
397 else if constexpr (
rank == 2)
403 else if constexpr (std::is_same_v<Order, ColumnMajor>)
408 else if constexpr (
rank == 3)
413 static_assert(
rank <= 3,
"Synchronous_Engine currently supports rank <= 3");
434 for (std::size_t i = 0; i <
steps; ++i)
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
void set(const coord_type &c, const state_type &v)
Strict write: throws if c is out of range.
typename Storage::state_type state_type
typename Storage::extents_type extents_type
const extents_type & extents() const noexcept
void swap(Lattice &other) noexcept(noexcept(store_.swap(other.store_)))
O(1) swap.
typename Storage::coord_type coord_type
static constexpr std::size_t rank
ca_size_t size() const noexcept
state_type at(const coord_type &c) const
Strict access: throws if c is out of range.
Synchronous double-buffered engine.
const extents_type & extents() const noexcept
Return the frame extents.
static constexpr std::size_t rank
Lattice dimension.
static constexpr std::size_t neighbour_count
Number of neighbours.
void run(const std::size_t steps)
Run several synchronous steps.
std::function< void(std::size_t, const Lattice &)> hook_type
Hook signature: (step_index_just_completed, frame).
typename Lattice::extents_type extents_type
Extents type.
const Rule & rule() const noexcept
Read-only access to the rule (used by checkpointing).
Rule & rule() noexcept
Mutable access to the rule (used by checkpointing to restore the master RNG seed of stochastic rules)...
Lattice & write_lattice() noexcept
Mutable access to the current lattice buffer.
void on_post_step(F &&f)
Register a hook fired after every step().
std::size_t steps_run() const noexcept
Return the number of completed steps.
Neighborhood neighborhood_type
Neighborhood type.
typename Lattice::coord_type coord_type
Coordinate type.
void step()
Apply the rule to every cell once and swap buffers.
Synchronous_Engine(Lattice initial, Rule r, Neighborhood n)
Build an engine on top of an existing initial lattice.
void on_pre_step(F &&f)
Register a hook fired before every step().
Order order_type
Iteration order.
const Lattice & frame() const noexcept
Return the current frame.
Synchronous_Engine(Lattice initial, Rule r)
Build an engine with a default-constructed neighbourhood.
typename Lattice::state_type state_type
Cell state type.
void set_step_count(const std::size_t s) noexcept
Override the completed-step counter.
Shape (per-axis sizes) of an mdspan, mixing compile-time and run-time extents.
A coordinate type with N integral components.
Detect whether a lattice exposes a refresh_halo() method (the hallmark of a Ghost_Lattice or any othe...
Storage + topology that carries the cell values.
Connectivity pattern around a coordinate.
Local transition function (any supported signature).
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
void iterate_3d_row_major(const ca_size_t n0, const ca_size_t n1, const ca_size_t n2, F &&f)
3D row-major iteration.
void iterate_1d(ca_size_t n0, F &&f)
1D row-major iteration callback f(coord).
void iterate_2d_column_major(ca_size_t n0, ca_size_t n1, F &&f)
2D column-major iteration.
void iterate_2d_tile(const ca_size_t n0, const ca_size_t n1, F &&f)
2D tiled iteration with tile size H along axis 0 and W along axis 1.
void iterate_2d_row_major(ca_size_t n0, ca_size_t n1, F &&f)
2D row-major iteration.
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.
void gather_neighbors(const Nbh &nh, const L &lat, const typename L::coord_type ¢er, std::span< T > out)
Populate out[0..nh.size()) with neighbour values of center.
std::size_t ca_size_t
Unsigned size component used for extents and counts.
State apply_rule(const Rule &r, const State &s, Neighbor_View< State > v, const Cell_Context< Rank > &ctx)
Invoke a rule, optionally forwarding the per-cell context.
Main namespace for Aleph-w library functions.
Per-cell context handed to rules that need to know "where" and "when" they are firing.
Iterate a 2D lattice in W x H tiles.
Detect whether O is a Tile<W, H> instantiation.
C++20 concepts for the Cellular Automata module.
Neighborhoods catalogue for Aleph::CA.