Class: Automata::StateDiagram

Inherits:
Object
  • Object
show all
Defined in:
lib/automata/state_diagram.rb

Overview

A generic state diagram class represented as a 5-tuple.

Direct Known Subclasses

DFA, NFA, Turing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ StateDiagram

Note:

The :transitions hash structure will vary Different machines will require different transition structures. Please refer to the wiki for details regarding each machine type.

Initialize and build a StateDiagram object.

Parameters:

  • params (Hash) (defaults to: {})

    the parameters to build the machine with.

  • [String] (Hash)

    a customizable set of options

  • [Array<String>] (Hash)

    a customizable set of options

  • [Hash] (Hash)

    a customizable set of options



23
24
25
26
27
28
29
30
31
32
# File 'lib/automata/state_diagram.rb', line 23

def initialize(params={})
  yaml = {}
  yaml = YAML::load_file(params[:file]) if params.has_key? :file
  @states = yaml['states'] || params[:states]
  @alphabet = yaml['alphabet'] || params[:alphabet]
  @start = yaml['start'] || params[:start]
  @accept = yaml['accept'] || params[:accept]
  @transitions = yaml['transitions'] || params[:transitions]
  @transitions = Hash.keys_to_strings(@transitions)
end

Instance Attribute Details

#acceptObject

Returns the value of attribute accept.



4
5
6
# File 'lib/automata/state_diagram.rb', line 4

def accept
  @accept
end

#alphabetObject

Returns the value of attribute alphabet.



4
5
6
# File 'lib/automata/state_diagram.rb', line 4

def alphabet
  @alphabet
end

#startObject

Returns the value of attribute start.



4
5
6
# File 'lib/automata/state_diagram.rb', line 4

def start
  @start
end

#statesObject

Returns the value of attribute states.



4
5
6
# File 'lib/automata/state_diagram.rb', line 4

def states
  @states
end

#transitionsObject

Returns the value of attribute transitions.



4
5
6
# File 'lib/automata/state_diagram.rb', line 4

def transitions
  @transitions
end