simulation.src.simulation_evaluation.src.state_machine.state_machines.state_machine module

Base class StateMachine.

Summary

Classes:

StateMachine

Base class for all state machines.

Reference

class StateMachine(state_machine: simulation.src.simulation_evaluation.src.state_machine.state_machines.state_machine.StateMachine, initial_state: simulation.src.simulation_evaluation.src.state_machine.states.state.State, callback: Callable[], None])[source]

Bases: object

Base class for all state machines.

This class handels state changes for a StateMachine. It also adds the methods’s info, value and msg which return properties of the current state. Additionally, it defines a property which returns all states and a method which creates a graph with all states.

state_machine

State machine used for all operations

Type

StateMachine

state

Current state

Type

State

callback

Function which gets executed when the state changes

Type

method

callback_on_state_change()[source]

Decorator which executes self.callback when the state of state machine has changed.

Parameters

func – Function to wrap

Returns

Result of func

run(*args, **kwargs)[source]
info() → str[source]

Get human-readable description of current state.

Returns

String of current description

value() → int[source]

Get value of current state.

Returns

Integer of current value

msg() → simulation_evaluation.msg._State.State[source]

Get message of current state.

Returns

StateMsg of current state

property all_states

Property which gives all available states inherting from State in current StateMachine.

set(*args, **kwargs)[source]
generate_graph(messages: Type[simulation_evaluation.msg._State.State], directory: str = '', filename: str = 'graph', accent_color: str = 'grey', shape: str = 'oval', shape_failure: str = 'rect', view: bool = False, save_to_file: bool = True) → str[source]

Generate Graph for current StateMachine.

Parameters
  • messages – Object of all messages

  • directory – Directory where the output file should be saved

  • filename – Name of output file

  • accent_color – Accent color of graph

  • shape – Default node shape

  • shape_failure – Failure node shape

  • view – If the graph should be shown to the user

  • save_to_file – If the graph should be saved to a svg file

Returns

A string of the generated source code of the graph

Note

You can find documentation on graphviz on their homepage and on readthedocs.