pub struct CSM<I, O, C>{ /* 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
- The CSM maintains a collection of causal states paired with actions
- Each causal state contains a causaloid that defines when the state should trigger its action
- When data is fed into the CSM, it evaluates the relevant states
- If a state’s conditions are met (evaluated to true), the associated action is triggered
§Usage
The CSM is typically used by:
- Creating causal states with appropriate causaloids that define trigger conditions
- Creating actions that should be executed when states are triggered
- Initializing a CSM with state-action pairs
- 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>
impl<I, O, C> CSM<I, O, C>
Sourcepub fn eval_single_state(
&self,
id: usize,
data: &PropagatingEffect<I>,
) -> Result<(), CsmError>
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§impl<I, O, C> CSM<I, O, C>
impl<I, O, C> CSM<I, O, C>
Sourcepub fn add_single_state(
&self,
state_action: StateAction<I, O, C>,
) -> Result<(), UpdateError>
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>
impl<I, O, C> CSM<I, O, C>
Sourcepub fn remove_single_state(&self, id: usize) -> Result<(), UpdateError>
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>
impl<I, O, C> CSM<I, O, C>
Sourcepub fn update_single_state(
&self,
state_action: StateAction<I, O, C>,
) -> Result<(), UpdateError>
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.
Sourcepub fn update_all_states(
&self,
state_actions: &[(&CausalState<I, O, C>, &CausalAction)],
) -> Result<(), UpdateError>
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>
impl<I, O, C> CSM<I, O, C>
Sourcepub fn new(state_actions: &[(&CausalState<I, O, C>, &CausalAction)]) -> Self
pub fn new(state_actions: &[(&CausalState<I, O, C>, &CausalAction)]) -> Self
Constructs a new CSM.