aalpy.automata.MealyMachine

View Source
from aalpy.base import Automaton, AutomatonState


class MealyState(AutomatonState):
    """
    Single state of a Mealy machine. Each state has an output_fun dictionary that maps inputs to outputs.
    """
    def __init__(self, state_id):
        super().__init__(state_id)
        self.output_fun = dict()


class MealyMachine(Automaton):

    def __init__(self, initial_state: MealyState, states):
        super().__init__(initial_state, states)

    def step(self, letter):
        """
        In Mealy machines, outputs depend on the input and the current state.

            Args:

                letter: single input that is looked up in the transition and output functions

            Returns:

                output corresponding to the input from the current state
        """
        output = self.current_state.output_fun[letter]
        self.current_state = self.current_state.transitions[letter]
        return output
View Source
class MealyState(AutomatonState):
    """
    Single state of a Mealy machine. Each state has an output_fun dictionary that maps inputs to outputs.
    """
    def __init__(self, state_id):
        super().__init__(state_id)
        self.output_fun = dict()

Single state of a Mealy machine. Each state has an output_fun dictionary that maps inputs to outputs.

#   MealyState(state_id)
View Source
    def __init__(self, state_id):
        super().__init__(state_id)
        self.output_fun = dict()

Single state of an automaton. Each state consists of a state id, a dictionary of transitions, where the keys are inputs and the values are the corresponding target states, and a prefix that leads to the state from the initial state.

Args:

state_id(Any): used for graphical representation of the state. A good practice is to keep it unique.
#   class MealyMachine(aalpy.base.Automaton.Automaton):
View Source
class MealyMachine(Automaton):

    def __init__(self, initial_state: MealyState, states):
        super().__init__(initial_state, states)

    def step(self, letter):
        """
        In Mealy machines, outputs depend on the input and the current state.

            Args:

                letter: single input that is looked up in the transition and output functions

            Returns:

                output corresponding to the input from the current state
        """
        output = self.current_state.output_fun[letter]
        self.current_state = self.current_state.transitions[letter]
        return output

Abstract class representing an automaton.

#   MealyMachine(initial_state: aalpy.automata.MealyMachine.MealyState, states)
View Source
    def __init__(self, initial_state: MealyState, states):
        super().__init__(initial_state, states)

Args:

initial_state (AutomatonState): initial state of the automaton
states (list) : list containing all states of the automaton
#   def step(self, letter):
View Source
    def step(self, letter):
        """
        In Mealy machines, outputs depend on the input and the current state.

            Args:

                letter: single input that is looked up in the transition and output functions

            Returns:

                output corresponding to the input from the current state
        """
        output = self.current_state.output_fun[letter]
        self.current_state = self.current_state.transitions[letter]
        return output

In Mealy machines, outputs depend on the input and the current state.

Args:

    letter: single input that is looked up in the transition and output functions

Returns:

    output corresponding to the input from the current state