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

Synchronous double-buffered engine for graph CAs. More...

#include <tpl_ca_graph_automaton.H>

Collaboration diagram for Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >:
[legend]

Public Types

using lattice_type = Lattice
 
using state_type = typename Lattice::state_type
 

Public Member Functions

 Graph_Synchronous_Engine (Lattice initial, Rule r)
 Build an engine on top of an existing graph lattice.
 
const Lattice & frame () const noexcept
 
std::size_t steps_run () const noexcept
 
template<typename F >
void on_pre_step (F &&f)
 Register a hook fired before every step().
 
template<typename F >
void on_post_step (F &&f)
 Register a hook fired after every step().
 
void step ()
 Apply the rule to every node once and swap buffers.
 
void run (const std::size_t steps)
 Run several synchronous steps.
 

Private Attributes

Lattice cur_buf_
 
Lattice nxt_buf_
 
Rule rule_
 
Array< state_type > nbuf_
 Aleph::Array reused across cells.
 
std::function< void(std::size_t, const Lattice &)> pre_hook_
 
std::function< void(std::size_t, const Lattice &)> post_hook_
 
std::size_t step_count_ = 0
 

Detailed Description

template<typename Lattice, typename Rule>
class Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >

Synchronous double-buffered engine for graph CAs.

Mirrors the API of Synchronous_Engine (frame, hooks, step, run, steps_run). The differences are internal: there is no neighbour template parameter, the per-cell neighbour count is variable (taken from the precomputed adjacency), and the gather buffer is a single Aleph::Array owned by the engine and reused across cells.

Template Parameters
Latticegraph lattice (typically Graph_Lattice<T>).
Rulerule type satisfying GraphRuleLike<Rule, state_type>.
Complexity
step() is O(sum of degrees) = O(2|E|) for an undirected graph.
Thread-safety
Single driving thread.

Definition at line 321 of file tpl_ca_graph_automaton.H.

Member Typedef Documentation

◆ lattice_type

Definition at line 324 of file tpl_ca_graph_automaton.H.

◆ state_type

Constructor & Destructor Documentation

◆ Graph_Synchronous_Engine()

template<typename Lattice , typename Rule >
Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::Graph_Synchronous_Engine ( Lattice  initial,
Rule  r 
)
inline

Build an engine on top of an existing graph lattice.

Parameters
[in]initialgraph lattice (consumed by move).
[in]rrule instance.
Exceptions
std::bad_allocon next-buffer allocation.
Complexity
O(N + E) for cloning the adjacency into the next buffer.

Definition at line 350 of file tpl_ca_graph_automaton.H.

References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::cur_buf_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::nbuf_, and Aleph::Array< T >::reserve().

Member Function Documentation

◆ frame()

template<typename Lattice , typename Rule >
const Lattice & Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::frame ( ) const
inlinenoexcept
Returns
read-only view of the current frame.

Definition at line 357 of file tpl_ca_graph_automaton.H.

References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::cur_buf_.

◆ on_post_step()

template<typename Lattice , typename Rule >
template<typename F >
void Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::on_post_step ( F &&  f)
inline

Register a hook fired after every step().

Definition at line 371 of file tpl_ca_graph_automaton.H.

References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::post_hook_.

◆ on_pre_step()

template<typename Lattice , typename Rule >
template<typename F >
void Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::on_pre_step ( F &&  f)
inline

Register a hook fired before every step().

Definition at line 364 of file tpl_ca_graph_automaton.H.

References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::pre_hook_.

Referenced by TEST().

◆ run()

template<typename Lattice , typename Rule >
void Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::run ( const std::size_t  steps)
inline

Run several synchronous steps.

Parameters
[in]stepsnumber of consecutive step() calls.

Definition at line 420 of file tpl_ca_graph_automaton.H.

References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step(), and steps.

Referenced by TEST(), TEST(), TEST(), and TEST().

◆ step()

◆ steps_run()

template<typename Lattice , typename Rule >
std::size_t Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::steps_run ( ) const
inlinenoexcept
Returns
number of completed steps.

Definition at line 360 of file tpl_ca_graph_automaton.H.

References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step_count_.

Member Data Documentation

◆ cur_buf_

◆ nbuf_

◆ nxt_buf_

◆ post_hook_

◆ pre_hook_

◆ rule_

◆ step_count_


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