CSM

Struct CSM 

Source
pub struct CSM<I, O, C>
where I: Default + Clone, O: CsmEvaluable + Default + Debug + Clone, C: Clone,
{ /* private fields */ }
Expand description

§Causal State Machine (CSM)

A Causal State Machine (CSM) is a structure that manages relationships between causal states and actions. It provides a mechanism for evaluating states based on input data and triggering associated actions when specific conditions are met.

§Purpose

The CSM is designed to model systems where different states can trigger specific actions when certain conditions are met. It’s particularly useful for:

  • Event-driven systems where actions should be triggered based on state changes
  • Monitoring systems that need to respond to specific conditions
  • Control systems that need to take actions based on sensor readings
  • Any system where cause-effect relationships need to be modeled and evaluated

§How It Works

  1. The CSM maintains a collection of causal states paired with actions
  2. Each causal state contains a causaloid that defines when the state should trigger its action
  3. When data is fed into the CSM, it evaluates the relevant states
  4. If a state’s conditions are met (evaluated to true), the associated action is triggered

§Usage

The CSM is typically used by:

  1. Creating causal states with appropriate causaloids that define trigger conditions
  2. Creating actions that should be executed when states are triggered
  3. Initializing a CSM with state-action pairs
  4. Feeding data into the CSM for evaluation

See the example in examples/csm/src/main.rs for a practical implementation.

Implementations§

Source§

impl<I, O, C> CSM<I, O, C>
where I: Default + Clone + Debug + Send + Sync + 'static, O: CsmEvaluable + Default + Debug + Clone + Send + Sync + 'static, C: Clone + Debug + Send + Sync + 'static,

Source

pub fn eval_single_state( &self, id: usize, data: &PropagatingEffect<I>, ) -> Result<(), CsmError>

Evaluates a single causal state at the index position id. If the state evaluates to an active effect, the associated action is fired. An active effect can be Deterministic(true) or an Uncertain type that passes its hypothesis test.

§Errors

Returns CsmError if the state does not exist, evaluation fails, or the action fails to fire. Also returns an error if the causaloid returns a probabilistic effect, which cannot be evaluated in a single state context.

Source

pub fn eval_all_states(&self) -> Result<(), CsmError>

Evaluates all causal states in the CSM using their internal data. For each state that evaluates to an active effect, the associated action is fired.

§Errors

Returns CsmError if any state evaluation or action firing fails.

Source§

impl<I, O, C> CSM<I, O, C>
where I: Default + Clone, O: CsmEvaluable + Default + Debug + Clone, C: Clone,

Source

pub fn add_single_state( &self, state_action: StateAction<I, O, C>, ) -> Result<(), UpdateError>

Inserts a new state action using the state’s internal ID. Returns UpdateError if a state with that ID already exists.

Source§

impl<I, O, C> CSM<I, O, C>
where I: Default + Clone, O: CsmEvaluable + Default + Debug + Clone, C: Clone,

Source

pub fn remove_single_state(&self, id: usize) -> Result<(), UpdateError>

Removes a state action at the index position id. Returns UpdateError if the index does not exist.

Source§

impl<I, O, C> CSM<I, O, C>
where I: Default + Clone, O: CsmEvaluable + Default + Debug + Clone, C: Clone,

Source

pub fn update_single_state( &self, state_action: StateAction<I, O, C>, ) -> Result<(), UpdateError>

Updates a causal state using the state’s internal ID. Returns UpdateError if the state does not exist.

Source

pub fn update_all_states( &self, state_actions: &[(&CausalState<I, O, C>, &CausalAction)], ) -> Result<(), UpdateError>

Updates all causal state with a new state collection. Note, this operation erases all previous states in the CSM by generating a new collection. Returns UpdateError if the update operation failed.

Source§

impl<I, O, C> CSM<I, O, C>
where I: Default + Clone, O: CsmEvaluable + Default + Debug + Clone, C: Clone,

Source

pub fn new(state_actions: &[(&CausalState<I, O, C>, &CausalAction)]) -> Self

Constructs a new CSM.

Source

pub fn len(&self) -> usize

Returns the number of elements in the CSM.

Source

pub fn is_empty(&self) -> bool

Returns true if the CSM contains no elements.

Auto Trait Implementations§

§

impl<I, O, C> Freeze for CSM<I, O, C>

§

impl<I, O, C> RefUnwindSafe for CSM<I, O, C>

§

impl<I, O, C> Send for CSM<I, O, C>
where C: Send + Sync, I: Send + Sync, O: Send + Sync,

§

impl<I, O, C> Sync for CSM<I, O, C>
where C: Send + Sync, I: Send + Sync, O: Send + Sync,

§

impl<I, O, C> Unpin for CSM<I, O, C>

§

impl<I, O, C> UnwindSafe for CSM<I, O, C>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.