12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/stamina-induction/stamina/abbadingo/random_dfa.rb', line 12
def execute(state_count = 64,
accepting_ratio = 0.5,
options = {})
options = DEFAULT_OPTIONS.merge(options)
dfa = Automaton.new
(state_count.to_f * 5.0 / 4.0).to_i.times do
dfa.add_state(:initial => false,
:accepting => (Kernel.rand <= accepting_ratio),
:error => false)
end
dfa.each_state do |source|
["0", "1"].each do |symbol|
target = dfa.ith_state(Kernel.rand(dfa.state_count))
dfa.connect(source, target, symbol)
end
end
dfa.ith_state(Kernel.rand(dfa.state_count)).initial!
case options[:minimize]
when :hopcroft
Stamina::Automaton::Minimize::Hopcroft.execute(dfa)
when :pitchies
Stamina::Automaton::Minimize::Pitchies.execute(dfa)
else
dfa
end
end
|