Class: Bparity::Formal::LTS
- Inherits:
-
Object
- Object
- Bparity::Formal::LTS
- Defined in:
- lib/bparity/formal/lts.rb
Instance Attribute Summary collapse
-
#initial ⇒ Object
readonly
Returns the value of attribute initial.
-
#transitions ⇒ Object
readonly
Returns the value of attribute transitions.
Class Method Summary collapse
Instance Method Summary collapse
- #alphabet ⇒ Object
- #deterministic? ⇒ Boolean
-
#initialize(initial:, transitions: []) ⇒ LTS
constructor
A new instance of LTS.
- #outgoing(state) ⇒ Object
- #states ⇒ Object
- #step(state, input) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(initial:, transitions: []) ⇒ LTS
Returns a new instance of LTS.
36 37 38 39 40 41 |
# File 'lib/bparity/formal/lts.rb', line 36 def initialize(initial:, transitions: []) @initial = initial @transitions = transitions.map do |transition| transition.is_a?(Transition) ? transition : Transition.new(**transition.transform_keys(&:to_sym)) end end |
Instance Attribute Details
#initial ⇒ Object (readonly)
Returns the value of attribute initial.
34 35 36 |
# File 'lib/bparity/formal/lts.rb', line 34 def initial @initial end |
#transitions ⇒ Object (readonly)
Returns the value of attribute transitions.
34 35 36 |
# File 'lib/bparity/formal/lts.rb', line 34 def transitions @transitions end |
Class Method Details
.from_h(value) ⇒ Object
59 60 61 |
# File 'lib/bparity/formal/lts.rb', line 59 def self.from_h(value) new(initial: value.fetch("initial"), transitions: value.fetch("transitions", [])) end |
Instance Method Details
#alphabet ⇒ Object
44 |
# File 'lib/bparity/formal/lts.rb', line 44 def alphabet = transitions.map(&:input).uniq.sort |
#deterministic? ⇒ Boolean
48 49 50 51 52 |
# File 'lib/bparity/formal/lts.rb', line 48 def deterministic? transitions.group_by { |transition| [transition.from, transition.input] }.values.none? do |items| items.map { |transition| [transition.output, transition.to] }.uniq.length > 1 end end |
#outgoing(state) ⇒ Object
45 |
# File 'lib/bparity/formal/lts.rb', line 45 def outgoing(state) = transitions.select { |transition| transition.from == state } |
#states ⇒ Object
43 |
# File 'lib/bparity/formal/lts.rb', line 43 def states = ([initial] + transitions.flat_map { |transition| [transition.from, transition.to] }).uniq.sort |
#step(state, input) ⇒ Object
46 |
# File 'lib/bparity/formal/lts.rb', line 46 def step(state, input) = outgoing(state).find { |transition| transition.input == input } |
#to_h ⇒ Object
54 55 56 57 |
# File 'lib/bparity/formal/lts.rb', line 54 def to_h { "initial" => initial, "states" => states, "alphabet" => alphabet, "transitions" => transitions.map(&:to_h) } end |