aalpy.automata.MooreMachine

View Source
from aalpy.base import Automaton, AutomatonState


class MooreState(AutomatonState):
    """
    Single state of a Moore machine. Each state has an output value.
    """

    def __init__(self, state_id, output):
        super().__init__(state_id)
        self.output = output


class MooreMachine(Automaton):

    def __init__(self, initial_state: AutomatonState, states: list):
        super().__init__(initial_state, states)

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

        Args:

            letter: single input that is looked up in the transition function leading to a new state

        Returns:

            the output of the reached state

        """
        self.current_state = self.current_state.transitions[letter]
        return self.current_state.output
View Source
class MooreState(AutomatonState):
    """
    Single state of a Moore machine. Each state has an output value.
    """

    def __init__(self, state_id, output):
        super().__init__(state_id)
        self.output = output

Single state of a Moore machine. Each state has an output value.

#   MooreState(state_id, output)
View Source
    def __init__(self, state_id, output):
        super().__init__(state_id)
        self.output = output

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 MooreMachine(aalpy.base.Automaton.Automaton):
View Source
class MooreMachine(Automaton):

    def __init__(self, initial_state: AutomatonState, states: list):
        super().__init__(initial_state, states)

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

        Args:

            letter: single input that is looked up in the transition function leading to a new state

        Returns:

            the output of the reached state

        """
        self.current_state = self.current_state.transitions[letter]
        return self.current_state.output

Abstract class representing an automaton.

#   MooreMachine( self, initial_state: aalpy.base.Automaton.AutomatonState, states: list )
View Source
    def __init__(self, initial_state: AutomatonState, states: list):
        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 Moore machines outputs depend on the current state.

        Args:

            letter: single input that is looked up in the transition function leading to a new state

        Returns:

            the output of the reached state

        """
        self.current_state = self.current_state.transitions[letter]
        return self.current_state.output

In Moore machines outputs depend on the current state.

Args:

letter: single input that is looked up in the transition function leading to a new state

Returns:

the output of the reached state