|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Synchronous double-buffered engine for graph CAs. More...
#include <tpl_ca_graph_automaton.H>
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 |
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.
| Lattice | graph lattice (typically Graph_Lattice<T>). |
| Rule | rule type satisfying GraphRuleLike<Rule, state_type>. |
step() is O(sum of degrees) = O(2|E|) for an undirected graph.Definition at line 321 of file tpl_ca_graph_automaton.H.
| using Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::lattice_type = Lattice |
Definition at line 324 of file tpl_ca_graph_automaton.H.
| using Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::state_type = typename Lattice::state_type |
Definition at line 325 of file tpl_ca_graph_automaton.H.
|
inline |
Build an engine on top of an existing graph lattice.
| [in] | initial | graph lattice (consumed by move). |
| [in] | r | rule instance. |
| std::bad_alloc | on next-buffer allocation. |
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().
|
inlinenoexcept |
Definition at line 357 of file tpl_ca_graph_automaton.H.
References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::cur_buf_.
|
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_.
|
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().
|
inline |
Run several synchronous steps.
| [in] | steps | number 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.
|
inline |
Apply the rule to every node once and swap buffers.
| Any | exception propagated by the rule or hooks. |
Definition at line 383 of file tpl_ca_graph_automaton.H.
References Aleph::Array< T >::append(), Aleph::CA::apply_rule(), Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::cur_buf_, k, 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::Array< T >::size(), Aleph::CA::Lattice< Storage, Boundary >::size(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step_count_, and Aleph::CA::Lattice< Storage, Boundary >::swap().
Referenced by main(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::run().
|
inlinenoexcept |
Definition at line 360 of file tpl_ca_graph_automaton.H.
References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step_count_.
|
private |
|
private |
Aleph::Array reused across cells.
Definition at line 334 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::Graph_Synchronous_Engine(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step().
|
private |
Definition at line 332 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step().
|
private |
Definition at line 336 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::on_post_step(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step().
|
private |
Definition at line 335 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::on_pre_step(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step().
|
private |
Definition at line 333 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step().
|
private |
Definition at line 337 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::steps_run().