|
Aleph-w 7.10.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. | |
| 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 |
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 358 of file tpl_ca_graph_automaton.H.
| using Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::lattice_type = Lattice |
Definition at line 361 of file tpl_ca_graph_automaton.H.
| 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.
|
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 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().
|
default |
Copy another engine: its lattices, its rule, its hooks and its count of steps.
| [in] | other | engine to copy. |
|
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.
| [in,out] | other | engine to move from. |
Definition at line 408 of file tpl_ca_graph_automaton.H.
|
inlinenoexcept |
Definition at line 502 of file tpl_ca_graph_automaton.H.
References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::cur_buf_.
Referenced by TEST().
|
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_.
|
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().
|
default |
Copy another engine into this one: its lattices, its rule, its hooks and its count of steps.
| [in] | other | engine to copy. |
|
inlinenoexcept |
Exchange this engine with another, which is left with the previous simulation of this one.
| [in,out] | other | engine to move from. |
Definition at line 429 of file tpl_ca_graph_automaton.H.
References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap().
|
inline |
Run several synchronous steps.
| [in] | steps | number 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.
|
inline |
Apply the rule to every node once and swap buffers.
| Any | exception propagated by the rule or hooks. |
Definition at line 528 of file tpl_ca_graph_automaton.H.
References Aleph::Array< T >::append(), Aleph::CA::apply_rule(), 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 505 of file tpl_ca_graph_automaton.H.
References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step_count_.
|
inlinenoexcept |
Exchange in O(1) the simulation of this engine and another.
| [in,out] | other | engine to exchange with. |
| what | swapping 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().
|
inlineprivate |
Definition at line 478 of file tpl_ca_graph_automaton.H.
References Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::cur_buf_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::nxt_buf_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::rule_, Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap(), and Aleph::CA::Lattice< Storage, Boundary >::swap().
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap().
|
private |
Definition at line 368 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::Graph_Synchronous_Engine(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::frame(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap_all_or_none().
|
private |
Aleph::Array reused across cells.
Definition at line 371 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::Graph_Synchronous_Engine(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap().
|
private |
|
private |
|
private |
|
private |
|
private |
Definition at line 374 of file tpl_ca_graph_automaton.H.
Referenced by Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::step(), Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::steps_run(), and Aleph::CA::Graph_Synchronous_Engine< Lattice, Rule >::swap().