107template <
typename O,
typename Lattice>
109 o.on_step_begin(s, f);
156 template <std::
size_t I>
159 return std::get<I>(
obs_);
167 template <std::
size_t I>
170 return std::get<I>(
obs_);
179 return sizeof...(Observers);
191 template <
typename Lattice>
194 std::apply([&](
auto &...
o)
196 (
o.on_step_begin(step, frame), ...);
209 template <
typename Lattice>
212 std::apply([&](
auto &...
o)
214 (
o.on_step_end(step, frame), ...);
261template <
typename Engine,
typename Observer>
264 using Lat =
typename Engine::lattice_type;
267 observer.on_step_begin(step, frame);
291template <
typename Engine,
typename Observer>
294 engine.on_pre_step([&
observer](std::size_t step,
const auto &frame)
296 observer.on_step_begin(step, frame);
298 engine.on_post_step([&
observer](std::size_t step,
const auto &frame)
327template <
typename State>
373 <<
"Density_Observer: index " << i <<
" out of range";
405 template <
typename Lattice>
422 template <
typename Lattice>
457template <
typename Lattice>
507 prev_.emplace(frame);
518 if (
prev_.has_value())
547template <std::
size_t MaxState>
595 template <
typename Lattice>
611 template <
typename Lattice>
655 void push(
const std::uint64_t
h,
const std::size_t step)
noexcept
737 template <
typename Lattice>
752 template <
typename Lattice>
797template <
typename Lattice>
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
Free metric helpers for cellular automata frames.
Common typedefs and tag types for the Cellular Automata module.
Simple dynamic array with automatic resizing and functional operations.
constexpr size_t size() const noexcept
Return the number of elements stored in the stack.
void clear() noexcept
Empties the container.
constexpr bool is_empty() const noexcept
Checks if the container is empty.
T & append(const T &data)
Append a copy of data
Records the number of cells that changed across each step.
void on_step_begin(std::size_t step, const Lattice &frame)
Capture the frame before a step.
std::optional< Lattice > prev_
Activity_Observer()=default
Construct an empty activity observer.
const Array< ca_size_t > & activity() const noexcept
Return the activity time series.
void on_step_end(const std::size_t step, const Lattice &frame)
Record changed cells after a step.
Array< ca_size_t > activity_
void reset() noexcept
Clear the previous frame and activity samples.
std::size_t size() const noexcept
Return the number of recorded steps.
Variadic adaptor that fan-outs notifications to many observers.
std::tuple< Observers... > obs_
static constexpr std::size_t size() noexcept
Return the number of child observers.
void on_step_end(std::size_t step, const Lattice &frame)
Forward a step-end event to every child observer.
Composite_Observer(Observers... observers)
Build the composite from child observers.
auto & get() noexcept
Return mutable access to a child observer.
const auto & get() const noexcept
Return read-only access to a child observer.
void on_step_begin(std::size_t step, const Lattice &frame)
Forward a step-begin event to every child observer.
Records the count of cells in tracked_state per step.
Density_Observer(State s)
Construct an observer tracking a specific state.
Array< ca_size_t > counts_
double density_at(const std::size_t i) const
Return density at a recorded sample.
const Array< ca_size_t > & counts() const noexcept
Return the count time series.
const Array< ca_size_t > & totals() const noexcept
Return the total-cell time series.
Density_Observer()=default
Construct an observer that tracks State{}.
Array< ca_size_t > totals_
void reset() noexcept
Clear all recorded samples.
std::size_t size() const noexcept
Return the number of recorded samples.
void on_step_begin(const std::size_t step, const Lattice &frame)
Record the initial frame before step zero.
void on_step_end(const std::size_t step, const Lattice &frame)
Record the frame after a completed step.
Records the Shannon entropy of the state distribution.
std::size_t size() const noexcept
Return the number of entropy samples.
void on_step_end(const std::size_t step, const Lattice &frame)
Record entropy after a completed step.
void on_step_begin(const std::size_t step, const Lattice &frame)
Record entropy of the initial frame.
Entropy_Observer()=default
Construct an empty entropy observer.
void reset() noexcept
Clear all entropy samples.
const Array< double > & entropy() const noexcept
Return the entropy time series.
Lattice that adds boundary-aware access on top of a storage.
Snapshots the lattice every period steps.
Sampling_Observer()=default
Construct an observer that snapshots every step.
std::size_t size() const noexcept
Return the number of stored snapshots.
const Array< std::size_t > & step_indices() const noexcept
Return step indices for collected snapshots.
Array< Lattice > snapshots_
Array< std::size_t > step_indices_
const Array< Lattice > & snapshots() const noexcept
Return collected snapshots.
void reset() noexcept
Clear all snapshots and step indices.
void on_step_begin(const std::size_t step, const Lattice &frame)
Capture the initial frame when sampling is enabled.
void on_step_end(const std::size_t step, const Lattice &frame)
Capture the completed frame at period boundaries.
Sampling_Observer(const std::size_t period)
Construct an observer with an explicit sampling period.
Detects fixed points and short cycles via frame hashing.
std::optional< std::size_t > cycle_start_
std::size_t buffered_hashes() const noexcept
Return the number of buffered hashes.
Stationary_Detector()=default
Construct a detector with the default 16-frame window.
void reset() noexcept
Clear buffered hashes and detected-cycle state.
std::optional< std::size_t > cycle_start() const noexcept
Return the cycle start step.
Array< std::size_t > steps_
Array< std::uint64_t > hashes_
bool cycle_detected() const noexcept
Return whether a cycle has been detected.
void push(const std::uint64_t h, const std::size_t step) noexcept
std::optional< std::size_t > cycle_length() const noexcept
Return the detected cycle length.
std::size_t max_cycle_length_
std::optional< std::size_t > cycle_length_
void on_step_end(std::size_t step, const Lattice &frame)
Check the completed frame against the recent hash window.
void on_step_begin(const std::size_t step, const Lattice &frame)
Seed the detector with the initial frame hash.
Stationary_Detector(std::size_t max_cycle_length)
Construct a detector with an explicit window size.
Concept satisfied by any cellular-automaton observer.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
void attach_observer(Engine &engine, Observer &observer)
Plug an observer into an engine's pre/post-step hooks.
double shannon_entropy(const Lattice &lat, std::size_t max_state)
Shannon entropy in nats of the [0, max_state) distribution.
void attach_observer_graph(Engine &engine, Observer &observer)
Attach an observer to engines without a lattice_type alias.
ca_size_t total_cells(const Lattice &lat) noexcept
std::uint64_t frame_hash(const Lattice &lat)
Deterministic 64-bit FNV-1a hash of the lattice cells.
ca_size_t count_state(const Lattice &lat, const typename Lattice::state_type &s)
auto make_composite_observer(Observers &&...observers)
Build a Composite_Observer with deduced ownership semantics.
ca_size_t cell_diff_count(const Lattice &a, const Lattice &b)
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Dynamic array container with automatic resizing.
C++20 concepts for the Cellular Automata module.