|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Detects fixed points and short cycles via frame hashing. More...
#include <ca-observer.H>
Public Member Functions | |
| Stationary_Detector ()=default | |
| Construct a detector with the default 16-frame window. | |
| Stationary_Detector (std::size_t max_cycle_length) | |
| Construct a detector with an explicit window size. | |
| bool | cycle_detected () const noexcept |
| Return whether a cycle has been detected. | |
| std::optional< std::size_t > | cycle_length () const noexcept |
| Return the detected cycle length. | |
| std::optional< std::size_t > | cycle_start () const noexcept |
| Return the cycle start step. | |
| std::size_t | buffered_hashes () const noexcept |
| Return the number of buffered hashes. | |
| void | reset () noexcept |
| Clear buffered hashes and detected-cycle state. | |
| template<typename Lattice > | |
| void | on_step_begin (const std::size_t step, const Lattice &frame) |
| Seed the detector with the initial frame hash. | |
| template<typename Lattice > | |
| void | on_step_end (std::size_t step, const Lattice &frame) |
| Check the completed frame against the recent hash window. | |
Private Member Functions | |
| void | push (const std::uint64_t h, const std::size_t step) noexcept |
Private Attributes | |
| std::size_t | max_cycle_length_ = 0 |
| Array< std::uint64_t > | hashes_ |
| Array< std::size_t > | steps_ |
| std::optional< std::size_t > | cycle_length_ |
| std::optional< std::size_t > | cycle_start_ |
Detects fixed points and short cycles via frame hashing.
Keeps a ring buffer of the last max_cycle_length frame hashes paired with the step at which they were seen. After every step the new hash is compared against the buffer; on a hit the observer records the cycle length (current step minus the step at which the matching frame was seen) and exposes it through cycle_length().
Multiple periodic patterns active at once (e.g. a blinker plus a glider in different regions) result in the longest reachable cycle within the buffer being detected.
max_cycle_length + 1 hashes.Definition at line 647 of file ca-observer.H.
|
default |
Construct a detector with the default 16-frame window.
| This | function does not throw. |
|
inlineexplicit |
Construct a detector with an explicit window size.
| [in] | max_cycle_length | maximum cycle length to retain. |
| This | function does not throw. |
Definition at line 678 of file ca-observer.H.
|
inlinenoexcept |
Return the number of buffered hashes.
| This | function does not throw. |
Definition at line 712 of file ca-observer.H.
References hashes_, and Aleph::Array< T >::size().
|
inlinenoexcept |
Return whether a cycle has been detected.
| This | function does not throw. |
Definition at line 685 of file ca-observer.H.
References cycle_length_.
|
inlinenoexcept |
Return the detected cycle length.
std::nullopt if none has been found. | This | function does not throw. |
Definition at line 694 of file ca-observer.H.
References cycle_length_.
|
inlinenoexcept |
Return the cycle start step.
std::nullopt if no cycle has been found. | This | function does not throw. |
Definition at line 703 of file ca-observer.H.
References cycle_start_.
|
inline |
Seed the detector with the initial frame hash.
| Lattice | lattice type. |
| [in] | step | step index about to run. |
| [in] | frame | frame before the step. |
| std::bad_alloc | if buffering the hash allocates. |
Definition at line 738 of file ca-observer.H.
References Aleph::and, Aleph::CA::frame_hash(), hashes_, Aleph::Array< T >::is_empty(), max_cycle_length_, and push().
Check the completed frame against the recent hash window.
| Lattice | lattice type. |
| [in] | step | completed step index. |
| [in] | frame | frame after the step. |
| std::bad_alloc | if buffering the hash allocates. |
Definition at line 753 of file ca-observer.H.
References Aleph::blossom_maximum_cardinality_matching(), cycle_length_, cycle_start_, Aleph::CA::frame_hash(), h, hashes_, max_cycle_length_, push(), Aleph::Array< T >::size(), and steps_.
|
inlineprivatenoexcept |
Definition at line 655 of file ca-observer.H.
References Aleph::Array< T >::append(), Aleph::blossom_maximum_cardinality_matching(), h, hashes_, max_cycle_length_, Aleph::Array< T >::remove_first(), Aleph::Array< T >::size(), and steps_.
Referenced by on_step_begin(), and on_step_end().
|
inlinenoexcept |
Clear buffered hashes and detected-cycle state.
| This | function does not throw. |
Definition at line 723 of file ca-observer.H.
References Aleph::Array< T >::clear(), cycle_length_, cycle_start_, hashes_, and steps_.
|
private |
Definition at line 652 of file ca-observer.H.
Referenced by cycle_detected(), cycle_length(), on_step_end(), and reset().
|
private |
Definition at line 653 of file ca-observer.H.
Referenced by cycle_start(), on_step_end(), and reset().
|
private |
Definition at line 650 of file ca-observer.H.
Referenced by buffered_hashes(), on_step_begin(), on_step_end(), push(), and reset().
|
private |
Definition at line 649 of file ca-observer.H.
Referenced by on_step_begin(), on_step_end(), and push().
|
private |
Definition at line 651 of file ca-observer.H.
Referenced by on_step_end(), push(), and reset().