Aleph-w 7.10.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.
 
 Graph_Synchronous_Engine (const Graph_Synchronous_Engine &other)=default
 Copy another engine: its lattices, its rule, its hooks and its count of steps.
 
 Graph_Synchronous_Engine (Graph_Synchronous_Engine &&other) noexcept(std::is_nothrow_move_constructible_v< Lattice > and std::is_nothrow_move_constructible_v< Rule >)
 Take the simulation of another engine, which is left with empty lattices, no hooks and no steps run.
 
Graph_Synchronous_Engine & operator= (const Graph_Synchronous_Engine &other)=default
 Copy another engine into this one: its lattices, its rule, its hooks and its count of steps.
 
Graph_Synchronous_Engine & operator= (Graph_Synchronous_Engine &&other) noexcept(noexcept(swap(other)))
 Exchange this engine with another, which is left with the previous simulation of this one.
 
void swap (Graph_Synchronous_Engine &other) noexcept(noexcept(cur_buf_.swap(other.cur_buf_)) and std::is_nothrow_swappable_v< Rule >)
 Exchange in O(1) the simulation of this engine and another.
 
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 Member Functions

void swap_all_or_none (Graph_Synchronous_Engine &other)
 

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 358 of file tpl_ca_graph_automaton.H.

Member Typedef Documentation

◆ lattice_type

template<typename Lattice , typename Rule >
using Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::lattice_type = Lattice

Definition at line 361 of file tpl_ca_graph_automaton.H.

◆ state_type

template<typename Lattice , typename Rule >
using Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::state_type = typename Lattice::state_type

Definition at line 362 of file tpl_ca_graph_automaton.H.

Constructor & Destructor Documentation

◆ Graph_Synchronous_Engine() [1/3]

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 387 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().

◆ Graph_Synchronous_Engine() [2/3]

template<typename Lattice , typename Rule >
Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::Graph_Synchronous_Engine ( const Graph_Synchronous_Engine< Lattice, Rule > &  other)
default

Copy another engine: its lattices, its rule, its hooks and its count of steps.

Parameters
[in]otherengine to copy.

◆ Graph_Synchronous_Engine() [3/3]

template<typename Lattice , typename Rule >
Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::Graph_Synchronous_Engine ( Graph_Synchronous_Engine< Lattice, Rule > &&  other)
inlinenoexcept

Take the simulation of another engine, which is left with empty lattices, no hooks and no steps run.

The implicit move took the lattices but copied the step counter: the moved-from engine reported the steps of a simulation that it no longer had.

Parameters
[in,out]otherengine to move from.

Definition at line 408 of file tpl_ca_graph_automaton.H.

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 502 of file tpl_ca_graph_automaton.H.

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

Referenced by TEST().

◆ 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 516 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 509 of file tpl_ca_graph_automaton.H.

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

Referenced by TEST().

◆ operator=() [1/2]

template<typename Lattice , typename Rule >
Graph_Synchronous_Engine & Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::operator= ( const Graph_Synchronous_Engine< Lattice, Rule > &  other)
default

Copy another engine into this one: its lattices, its rule, its hooks and its count of steps.

Parameters
[in]otherengine to copy.
Returns
this engine.

◆ operator=() [2/2]

template<typename Lattice , typename Rule >
Graph_Synchronous_Engine & Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::operator= ( Graph_Synchronous_Engine< Lattice, Rule > &&  other)
inlinenoexcept

Exchange this engine with another, which is left with the previous simulation of this one.

Parameters
[in,out]otherengine to move from.
Returns
this engine.

Definition at line 429 of file tpl_ca_graph_automaton.H.

References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap().

◆ 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 565 of file tpl_ca_graph_automaton.H.

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

Referenced by TEST(), 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 505 of file tpl_ca_graph_automaton.H.

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

◆ swap()

template<typename Lattice , typename Rule >
void Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap ( Graph_Synchronous_Engine< Lattice, Rule > &  other)
inlinenoexcept

Exchange in O(1) the simulation of this engine and another.

Parameters
[in,out]otherengine to exchange with.
Exceptions
whatswapping the rules or the lattices throws. When one of those swaps may throw, the rules are exchanged before the lattices, all or none: if a swap throws, those before it are exchanged back, and both engines are left as they were, if the swap that threw left its arguments as they were. If a swap that puts one back throws too, both engines can only be destroyed or assigned. std::swap(), for a rule without a swap of its own, may leave it moved from.

Definition at line 448 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_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::nxt_buf_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::post_hook_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::pre_hook_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::rule_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step_count_, Aleph::Array< T >::swap(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap(), Aleph::CA::Lattice< Storage, Boundary >::swap(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap_all_or_none().

Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::operator=(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap_all_or_none().

◆ swap_all_or_none()

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: