Class: Stamina::Command::AbbadingoDfa
- Inherits:
-
Object
- Object
- Stamina::Command::AbbadingoDfa
- Includes:
- Robustness
- Defined in:
- lib/stamina-induction/stamina/command/abbadingo_dfa.rb
Overview
Generates a DFA following Abbadingo’s protocol
SYNOPSIS
#{program_name} #{command_name}
OPTIONS #summarized_options
Instance Attribute Summary collapse
-
#depth_tolerance ⇒ Object
Tolerance on the automaton depth.
-
#output_file ⇒ Object
Where to flush the dfa.
-
#size ⇒ Object
Size of the target automaton.
-
#size_tolerance ⇒ Object
Tolerance on the size.
Instance Method Summary collapse
-
#accept?(dfa) ⇒ Boolean
options.
-
#execute(args) ⇒ Object
Command execution.
Instance Attribute Details
#depth_tolerance ⇒ Object
Tolerance on the automaton depth
22 23 24 |
# File 'lib/stamina-induction/stamina/command/abbadingo_dfa.rb', line 22 def depth_tolerance @depth_tolerance end |
#output_file ⇒ Object
Where to flush the dfa
25 26 27 |
# File 'lib/stamina-induction/stamina/command/abbadingo_dfa.rb', line 25 def output_file @output_file end |
#size ⇒ Object
Size of the target automaton
16 17 18 |
# File 'lib/stamina-induction/stamina/command/abbadingo_dfa.rb', line 16 def size @size end |
#size_tolerance ⇒ Object
Tolerance on the size
19 20 21 |
# File 'lib/stamina-induction/stamina/command/abbadingo_dfa.rb', line 19 def size_tolerance @size_tolerance end |
Instance Method Details
#accept?(dfa) ⇒ Boolean
options
53 54 55 56 |
# File 'lib/stamina-induction/stamina/command/abbadingo_dfa.rb', line 53 def accept?(dfa) (size_tolerance.nil? || (size - dfa.state_count).abs <= size_tolerance) && (depth_tolerance.nil? || ((2*Math.log2(size)-2) - dfa.depth).abs <= depth_tolerance) end |
#execute(args) ⇒ Object
Command execution
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/stamina-induction/stamina/command/abbadingo_dfa.rb', line 59 def execute(args) require 'stamina/abbadingo' # generate it randomizer = Stamina::Abbadingo::RandomDFA.new(size) begin dfa = randomizer.execute end until accept?(dfa) # flush it if output_file File.open(output_file, 'w') do |file| Stamina::ADL.print_automaton(dfa, file) end else Stamina::ADL.print_automaton(dfa, $stdout) end end |