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

Reproducible stochastic rule wrapper (Phase 8). More...

#include <tpl_ca_rule.H>

Public Types

using engine_type = Engine
 Underlying engine type used when the wrapped functor accepts an Engine& reference.
 

Public Member Functions

constexpr Probabilistic_Rule (F func)
 Construct a stochastic wrapper from a functor.
 
constexpr Probabilistic_Rule (F func, std::uint64_t master_seed)
 Construct a stochastic wrapper with an explicit master seed.
 
constexpr std::uint64_t master_seed () const noexcept
 
void set_master_seed (std::uint64_t s) noexcept
 Replace the master seed without rebuilding the rule.
 
template<typename State >
requires std::invocable<F &, const State &, Neighbor_View<State>>
State operator() (const State &current, Neighbor_View< State > neighbours) const
 Legacy invocation: forward (state, neighbours) to F.
 
template<typename State , std::size_t Rank>
State operator() (const State &current, Neighbor_View< State > neighbours, const Cell_Context< Rank > &ctx) const
 Reproducible invocation with engine context.
 

Private Attributes

F f_
 
std::uint64_t master_seed_ = 0
 

Detailed Description

template<typename F, typename Engine = std::mt19937_64>
class Aleph::CA::Probabilistic_Rule< F, Engine >

Reproducible stochastic rule wrapper (Phase 8).

Probabilistic_Rule<F, Engine> accepts two functor flavours:

  • Legacy: F(State, Neighbor_View<State>) -> State. Random sources are managed by the functor; the rule simply forwards the call. This is the Phase 0–7 behaviour.
  • Reproducible: F(State, Neighbor_View<State>, Engine&) -> State. The rule receives a Cell_Context<Rank> from the engine, derives a per-cell seed via cell_seed(master_seed, ctx), builds a fresh Engine and hands it by reference to F. Two runs with the same (master_seed, initial frame) are bit-for-bit identical regardless of the number of worker threads.

Both invocation modes coexist on the same class, so a rule that was already a Probabilistic_Rule<F> keeps compiling without changes.

Template Parameters
Ffunctor type accepting one of the two signatures above.
EngineRNG engine handed to reproducible functors. Defaults to std::mt19937_64.

Definition at line 348 of file tpl_ca_rule.H.

Member Typedef Documentation

◆ engine_type

template<typename F , typename Engine = std::mt19937_64>
using Aleph::CA::Probabilistic_Rule< F, Engine >::engine_type = Engine

Underlying engine type used when the wrapped functor accepts an Engine& reference.

Definition at line 356 of file tpl_ca_rule.H.

Constructor & Destructor Documentation

◆ Probabilistic_Rule() [1/2]

template<typename F , typename Engine = std::mt19937_64>
constexpr Aleph::CA::Probabilistic_Rule< F, Engine >::Probabilistic_Rule ( F  func)
inlineexplicitconstexpr

Construct a stochastic wrapper from a functor.

Backwards-compatible 1-argument form: the master seed defaults to 0 and is only consulted when the functor opts in to the reproducible signature.

Parameters
[in]funccallable object satisfying one of the two signatures described above.
Exceptions
Anyexception thrown while moving/copying func.

Definition at line 368 of file tpl_ca_rule.H.

◆ Probabilistic_Rule() [2/2]

template<typename F , typename Engine = std::mt19937_64>
constexpr Aleph::CA::Probabilistic_Rule< F, Engine >::Probabilistic_Rule ( F  func,
std::uint64_t  master_seed 
)
inlineconstexpr

Construct a stochastic wrapper with an explicit master seed.

Parameters
[in]funccallable object accepting (State, Neighbor_View<State>, Engine&).
[in]master_seedroot seed forwarded to cell_seed(master_seed, ctx) for every cell.
Exceptions
Anyexception thrown while moving/copying func.

Definition at line 378 of file tpl_ca_rule.H.

Member Function Documentation

◆ master_seed()

template<typename F , typename Engine = std::mt19937_64>
constexpr std::uint64_t Aleph::CA::Probabilistic_Rule< F, Engine >::master_seed ( ) const
inlineconstexprnoexcept
Returns
the master seed currently used to derive per-cell streams.

Definition at line 383 of file tpl_ca_rule.H.

References Aleph::CA::Probabilistic_Rule< F, Engine >::master_seed_.

◆ operator()() [1/2]

template<typename F , typename Engine = std::mt19937_64>
template<typename State >
requires std::invocable<F &, const State &, Neighbor_View<State>>
State Aleph::CA::Probabilistic_Rule< F, Engine >::operator() ( const State &  current,
Neighbor_View< State >  neighbours 
) const
inline

Legacy invocation: forward (state, neighbours) to F.

Template Parameters
Statecell state type.
Parameters
[in]currentcurrent centre-cell state.
[in]neighboursread-only neighbour values.
Returns
next state produced by the wrapped functor.
Exceptions
Anyexception thrown by the wrapped functor.

Definition at line 400 of file tpl_ca_rule.H.

References Aleph::CA::Probabilistic_Rule< F, Engine >::f_.

◆ operator()() [2/2]

template<typename F , typename Engine = std::mt19937_64>
template<typename State , std::size_t Rank>
State Aleph::CA::Probabilistic_Rule< F, Engine >::operator() ( const State &  current,
Neighbor_View< State >  neighbours,
const Cell_Context< Rank > &  ctx 
) const
inline

Reproducible invocation with engine context.

When F accepts an Engine&, the rule constructs an engine seeded with cell_seed(master_seed_, ctx) and forwards it. When F only accepts the legacy 2-argument signature, the call is forwarded as-is and ctx is ignored.

Template Parameters
Statecell state type.
Ranklattice rank carried by ctx.
Parameters
[in]currentcurrent centre-cell state.
[in]neighboursread-only neighbour values.
[in]ctxper-cell context provided by the engine.
Returns
next state produced by the wrapped functor.
Exceptions
Anyexception thrown by the wrapped functor.

Definition at line 423 of file tpl_ca_rule.H.

References Aleph::blossom_maximum_cardinality_matching(), Aleph::CA::Probabilistic_Rule< F, Engine >::f_, and Aleph::CA::Probabilistic_Rule< F, Engine >::master_seed_.

◆ set_master_seed()

template<typename F , typename Engine = std::mt19937_64>
void Aleph::CA::Probabilistic_Rule< F, Engine >::set_master_seed ( std::uint64_t  s)
inlinenoexcept

Replace the master seed without rebuilding the rule.

Definition at line 389 of file tpl_ca_rule.H.

References Aleph::CA::Probabilistic_Rule< F, Engine >::master_seed_.

Member Data Documentation

◆ f_

◆ master_seed_


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