Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Lookup_Rule< NumStates, NumNeighbors > Class Template Reference

Precomputed transition table for (self, neighbours...). More...

#include <tpl_ca_rule.H>

Collaboration diagram for Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >:
[legend]

Public Types

using table_type = std::array< std::size_t, table_size_v >
 Transition table type storing next states for every input tuple.
 

Public Member Functions

constexpr Lookup_Rule ()=default
 Build a zero-initialised lookup rule.
 
constexpr Lookup_Rule (table_type t)
 Build a lookup rule from a precomputed transition table.
 
constexpr const table_type & raw_table () const noexcept
 Return the underlying transition table.
 
template<typename State >
State operator() (const State &current, Neighbor_View< State > neighbours) const
 Compute the next state using the precomputed table.
 

Static Public Attributes

static constexpr std::size_t num_states_v = NumStates
 Number of distinct cell states accepted by this rule.
 
static constexpr std::size_t num_neighbours_v = NumNeighbors
 Number of neighbour entries required by operator().
 
static constexpr std::size_t table_size_v = ca_rule_detail::static_pow_rule(NumStates, NumNeighbors + 1)
 Number of entries in the transition table.
 

Private Attributes

table_type table_ {}
 

Detailed Description

template<std::size_t NumStates, std::size_t NumNeighbors>
class Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >

Precomputed transition table for (self, neighbours...).

For S states and K neighbours, the table size is S^(K+1). The index used to look up the next state is

idx = self * S^K + neighbours[0] * S^(K-1) + ... + neighbours[K-1]

which matches the canonical "self-major" convention. The factory make_wolfram_elementary_rule(rule_no) translates the standard Wolfram code (which uses a different bit layout) into a table for this convention assuming the neighbourhood used at the call site is Custom_Neighborhood<1, 2>{ {-1, +1} } — i.e. left first, right second.

Template Parameters
NumStatesnumber of distinct cell states.
NumNeighborsnumber of neighbours seen by the rule.

Definition at line 212 of file tpl_ca_rule.H.

Member Typedef Documentation

◆ table_type

template<std::size_t NumStates, std::size_t NumNeighbors>
using Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::table_type = std::array<std::size_t, table_size_v>

Transition table type storing next states for every input tuple.

Definition at line 226 of file tpl_ca_rule.H.

Constructor & Destructor Documentation

◆ Lookup_Rule() [1/2]

template<std::size_t NumStates, std::size_t NumNeighbors>
constexpr Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::Lookup_Rule ( )
constexprdefault

Build a zero-initialised lookup rule.

Every transition maps to state 0.

◆ Lookup_Rule() [2/2]

template<std::size_t NumStates, std::size_t NumNeighbors>
constexpr Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::Lookup_Rule ( table_type  t)
inlineexplicitconstexpr

Build a lookup rule from a precomputed transition table.

Parameters
[in]ttransition table indexed by (self, neighbours...).
Exceptions
Anyexception thrown while copying/moving the table.

Definition at line 243 of file tpl_ca_rule.H.

Member Function Documentation

◆ operator()()

template<std::size_t NumStates, std::size_t NumNeighbors>
template<typename State >
State Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::operator() ( const State &  current,
Neighbor_View< State >  neighbours 
) const
inline

Compute the next state using the precomputed table.

Template Parameters
Statecell state type convertible to std::size_t.
Parameters
[in]currentcurrent centre-cell state.
[in]neighboursread-only neighbour values.
Returns
next state stored in the table.
Exceptions
std::length_errorif neighbours.size() != NumNeighbors.
std::domain_errorif current or a neighbour is outside [0, NumStates).

Definition at line 266 of file tpl_ca_rule.H.

References ah_domain_error_if, ah_length_error_if, Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::table_, and value.

◆ raw_table()

template<std::size_t NumStates, std::size_t NumNeighbors>
constexpr const table_type & Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::raw_table ( ) const
inlineconstexprnoexcept

Return the underlying transition table.

Returns
const reference to the rule table.
Exceptions
Thisfunction does not throw.

Definition at line 250 of file tpl_ca_rule.H.

References Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::table_.

Member Data Documentation

◆ num_neighbours_v

template<std::size_t NumStates, std::size_t NumNeighbors>
constexpr std::size_t Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::num_neighbours_v = NumNeighbors
staticconstexpr

Number of neighbour entries required by operator().

Definition at line 219 of file tpl_ca_rule.H.

◆ num_states_v

template<std::size_t NumStates, std::size_t NumNeighbors>
constexpr std::size_t Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::num_states_v = NumStates
staticconstexpr

Number of distinct cell states accepted by this rule.

Definition at line 216 of file tpl_ca_rule.H.

◆ table_

template<std::size_t NumStates, std::size_t NumNeighbors>
table_type Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::table_ {}
private

◆ table_size_v

template<std::size_t NumStates, std::size_t NumNeighbors>
constexpr std::size_t Aleph::CA::Lookup_Rule< NumStates, NumNeighbors >::table_size_v = ca_rule_detail::static_pow_rule(NumStates, NumNeighbors + 1)
staticconstexpr

Number of entries in the transition table.

Definition at line 222 of file tpl_ca_rule.H.


The documentation for this class was generated from the following file: