Sha256: 2595827379f05e98bd523d6f45e55b824b513f58a5b5f738ef04e12f7d2f3330

Contents?: true

Size: 961 Bytes

Versions: 2

Compression:

Stored size: 961 Bytes

Contents

module Stamina
  class Automaton

    # Implements the equivalence relation commonly used on canonical DFAs
    class Equivalence < TransitionSystem::Equivalence

      def equivalent_systems?(s, t)
        (s.state_count == t.state_count) &&
        (s.edge_count  == t.edge_count)  &&
        (s.alphabet    == t.alphabet)    &&
        (s.data        == t.data)
      end

      def equivalent_states?(s, t)
        (s.initial?   == t.initial?) &&
        (s.accepting? == t.accepting?) &&
        (s.error?     == t.error?)
      end

      def equivalent_edges?(e, f)
        e.symbol == f.symbol
      end

    end # class Equivalence

    #
    # Checks if this automaton is equivalent to another one.
    #
    # Automata must be both minimal and complete to guarantee that this method
    # works.
    #
    def equivalent?(other)
      Equivalence.new.call(self, other)
    end
    alias :<=> :equivalent?

  end # class Automaton
end # module Stamina

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stamina-core-0.6.1 lib/stamina-core/stamina/automaton/equivalence.rb
stamina-core-0.6.0 lib/stamina-core/stamina/automaton/equivalence.rb