Python YASMIN (Yet Another State MachINe)
Loading...
Searching...
No Matches
yasmin.concurrence.Concurrence Class Reference
Inheritance diagram for yasmin.concurrence.Concurrence:
Collaboration diagram for yasmin.concurrence.Concurrence:

Public Member Functions

None __init__ (self, List[State] states, str default_outcome, Dict[str, Dict[State, str]] outcome_map={})
 
str execute (self, Blackboard blackboard)
 
None execute_and_save_state (self, State state, int state_id, Blackboard blackboard)
 
None cancel_state (self)
 
str __str__ (self)
 
- Public Member Functions inherited from yasmin.state.State
None __init__ (self, Set[str] outcomes)
 
str __call__ (self, Blackboard blackboard=None)
 
str __str__ (self)
 
bool is_canceled (self)
 
bool is_running (self)
 
Set[str] get_outcomes (self)
 

Protected Attributes

List[State_states = states
 
str _default_outcome = default_outcome
 
dict _outcome_map = {}
 
dict _intermediate_outcomes = {}
 
 _mutex = Lock()
 
- Protected Attributes inherited from yasmin.state.State
Set _outcomes = set()
 A set of valid outcomes for this state.
 
bool _running = False
 A flag indicating whether the state is currently running.
 
bool _canceled = False
 A flag indicating whether the state has been canceled.
 

Detailed Description

Child class of a State that runs multiple other states in parallel threads.

Attributes:
    _states (List[State]): A list of states that will be run in parallel by this state.
    _outcome_map (Dict[str, Dict[int, str]]): A dictionary correlating the outcomes of the concurrent states to
                                              outcomes of this state.
    _default_outcome (str): A default outcome in case none of the correlations in _outcome_map are satisfied.
    _intermediate_outcomes (Dict[str, Optional[str]]): A temporary storage of the parallel states's outcomes.
    _mutex (Lock): A mutex to ensure thread safety of _intermediate_outcomes.

Constructor & Destructor Documentation

◆ __init__()

None yasmin.concurrence.Concurrence.__init__ ( self,
List[State] states,
str default_outcome,
Dict[str, Dict[State, str]] outcome_map = {} )
Initializes the Concurrence instance.

:param default_outcome: A default outcome in case none of the correlations in outcome_map are satisfied.
:param outcome_map: A dictionary correlating the outcomes of the concurrent states to outcomes of this state.
:param states: A list of states that will be run in parallel by this state.

:raises ValueError: If either the provided outcomes set or states set are empty.
:raises ValueError: If the same instance of a state is listed to run concurrently with itself.
:raises KeyError: If an intermediate outcome is not registered with the correlated state.

Member Function Documentation

◆ __str__()

str yasmin.concurrence.Concurrence.__str__ ( self)
Returns a string representation of the concurrence state, listing all states.

Returns:
    str: A string representation of the state machine.

◆ cancel_state()

None yasmin.concurrence.Concurrence.cancel_state ( self)
Cancels the execution of all states.

Reimplemented from yasmin.state.State.

◆ execute()

str yasmin.concurrence.Concurrence.execute ( self,
Blackboard blackboard )
Executes the parallel behavior.

:param blackboard: An instance of Blackboard that provides the context for execution.
:return: The outcome of the execution as a string.

Reimplemented from yasmin.state.State.

◆ execute_and_save_state()

None yasmin.concurrence.Concurrence.execute_and_save_state ( self,
State state,
int state_id,
Blackboard blackboard )
Executes a state and saves its outcome to the intermediate map.

:param state: A state to execute.
:param state_id: The internal state ID associated with the state to execute.
:param blackboard: An instance of Blackboard that provides the context for execution.
:return: None

Member Data Documentation

◆ _default_outcome

str yasmin.concurrence.Concurrence._default_outcome = default_outcome
protected

◆ _intermediate_outcomes

dict yasmin.concurrence.Concurrence._intermediate_outcomes = {}
protected

◆ _mutex

yasmin.concurrence.Concurrence._mutex = Lock()
protected

◆ _outcome_map

dict yasmin.concurrence.Concurrence._outcome_map = {}
protected

◆ _states

yasmin.concurrence.Concurrence._states = states
protected

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