Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::CA::Density_Observer< State > Class Template Reference

Records the count of cells in tracked_state per step. More...

#include <ca-observer.H>

Collaboration diagram for Aleph::CA::Density_Observer< State >:
[legend]

Public Member Functions

 Density_Observer ()=default
 Construct an observer that tracks State{}.
 
 Density_Observer (State s)
 Construct an observer tracking a specific state.
 
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.
 
double density_at (const std::size_t i) const
 Return density at a recorded sample.
 
std::size_t size () const noexcept
 Return the number of recorded samples.
 
void reset () noexcept
 Clear all recorded samples.
 
template<typename Lattice >
void on_step_begin (const std::size_t step, const Lattice &frame)
 Record the initial frame before step zero.
 
template<typename Lattice >
void on_step_end (const std::size_t step, const Lattice &frame)
 Record the frame after a completed step.
 

Private Attributes

State tracked_state_ {}
 
Array< ca_size_t > counts_
 
Array< ca_size_t > totals_
 
bool seeded_ = false
 

Detailed Description

template<typename State>
class Aleph::CA::Density_Observer< State >

Records the count of cells in tracked_state per step.

At the end of every step the observer pushes one entry into its history. The very first sample is recorded inside on_step_begin for step == 0, so the time series includes the initial frame.

Template Parameters
Statecell state type to track.
Complexity
Callbacks are O(N) per sampled frame and O(1) extra space per sample, where N is the number of cells.
Thread-safety
Thread-safe for concurrent readers after simulation stops; not thread-safe for concurrent writers/callbacks.
Exception-safety
Strong guarantee unless array allocation throws during sampling.

Definition at line 328 of file ca-observer.H.

Constructor & Destructor Documentation

◆ Density_Observer() [1/2]

template<typename State >
Aleph::CA::Density_Observer< State >::Density_Observer ( )
default

Construct an observer that tracks State{}.

Exceptions
Anyexception thrown by State default construction.

◆ Density_Observer() [2/2]

template<typename State >
Aleph::CA::Density_Observer< State >::Density_Observer ( State  s)
inlineexplicit

Construct an observer tracking a specific state.

Parameters
[in]sstate value counted at every sample.
Exceptions
Anyexception thrown while moving/copying s.

Definition at line 345 of file ca-observer.H.

Member Function Documentation

◆ counts()

template<typename State >
const Array< ca_size_t > & Aleph::CA::Density_Observer< State >::counts ( ) const
inlinenoexcept

Return the count time series.

Returns
counts, one per recorded step including the initial frame.
Exceptions
Thisfunction does not throw.

Definition at line 351 of file ca-observer.H.

References Aleph::CA::Density_Observer< State >::counts_.

◆ density_at()

template<typename State >
double Aleph::CA::Density_Observer< State >::density_at ( const std::size_t  i) const
inline

Return density at a recorded sample.

Parameters
[in]isample index.
Returns
counts()[i] / totals()[i], or 0 for empty lattices.
Exceptions
std::out_of_rangeif i >= size().

Definition at line 370 of file ca-observer.H.

References ah_out_of_range_error_if, Aleph::CA::Density_Observer< State >::counts_, Aleph::Array< T >::size(), and Aleph::CA::Density_Observer< State >::totals_.

◆ on_step_begin()

template<typename State >
template<typename Lattice >
void Aleph::CA::Density_Observer< State >::on_step_begin ( const std::size_t  step,
const Lattice &  frame 
)
inline

Record the initial frame before step zero.

Template Parameters
Latticelattice type.
Parameters
[in]stepstep index about to run.
[in]frameframe before the step.
Exceptions
std::bad_allocif appending the sample allocates.

Definition at line 406 of file ca-observer.H.

References Aleph::and, Aleph::Array< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::count_state(), Aleph::CA::Density_Observer< State >::counts_, Aleph::CA::Density_Observer< State >::seeded_, Aleph::CA::total_cells(), Aleph::CA::Density_Observer< State >::totals_, and Aleph::CA::Density_Observer< State >::tracked_state_.

◆ on_step_end()

template<typename State >
template<typename Lattice >
void Aleph::CA::Density_Observer< State >::on_step_end ( const std::size_t  step,
const Lattice &  frame 
)
inline

Record the frame after a completed step.

Template Parameters
Latticelattice type.
Parameters
[in]stepcompleted step index, ignored.
[in]frameframe after the step.
Exceptions
std::bad_allocif appending the sample allocates.

Definition at line 423 of file ca-observer.H.

References Aleph::Array< T >::append(), Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::count_state(), Aleph::CA::Density_Observer< State >::counts_, Aleph::CA::total_cells(), Aleph::CA::Density_Observer< State >::totals_, and Aleph::CA::Density_Observer< State >::tracked_state_.

◆ reset()

template<typename State >
void Aleph::CA::Density_Observer< State >::reset ( )
inlinenoexcept

Clear all recorded samples.

Exceptions
Thisfunction does not throw.
Complexity
O(size()).

Definition at line 392 of file ca-observer.H.

References Aleph::Array< T >::clear(), Aleph::CA::Density_Observer< State >::counts_, Aleph::CA::Density_Observer< State >::seeded_, and Aleph::CA::Density_Observer< State >::totals_.

◆ size()

template<typename State >
std::size_t Aleph::CA::Density_Observer< State >::size ( ) const
inlinenoexcept

Return the number of recorded samples.

Returns
sample count.
Exceptions
Thisfunction does not throw.

Definition at line 381 of file ca-observer.H.

References Aleph::CA::Density_Observer< State >::counts_, and Aleph::Array< T >::size().

◆ totals()

template<typename State >
const Array< ca_size_t > & Aleph::CA::Density_Observer< State >::totals ( ) const
inlinenoexcept

Return the total-cell time series.

Returns
total cell counts, aligned with counts().
Exceptions
Thisfunction does not throw.

Definition at line 360 of file ca-observer.H.

References Aleph::CA::Density_Observer< State >::totals_.

Member Data Documentation

◆ counts_

◆ seeded_

◆ totals_

◆ tracked_state_

template<typename State >
State Aleph::CA::Density_Observer< State >::tracked_state_ {}
private

The documentation for this class was generated from the following file: