Python 如何在DFA类中定义增量?
我真的是Python的新手。我想知道如何定义Python 如何在DFA类中定义增量?,python,Python,我真的是Python的新手。我想知道如何定义delta,然后在创建它的实例对象时将它传递给DFA类: class DFA: """This class represents a deterministic finite automaton.""" def __init__(self, states, alphabet, delta, start, accepts): """T
delta
,然后在创建它的实例对象时将它传递给DFA
类:
class DFA:
"""This class represents a deterministic finite automaton."""
def __init__(self, states, alphabet, delta, start, accepts):
"""The inputs to the class are as follows:
-states: a lists containing the states of the DFA
-alphabet: a list containing the symbols in the DFA's alphabet
-delta: a complete function from [states]x[alphabets]->[states].
-start: the state at which the DFA begins operation.
-accepts: a list containing the "accepting" or "final" states of the DFA
Making delta a function rather than a transition table makes it much easier to define certain DFAs.
And if you want to use transition tables, you can just do this:
delta = lambda q,c: transition_table[q][c]
One caveat is that the function should not depend on the value of 'states' or 'accepts', since
these may be modified during minimization.
Finally, the names of states and inputs should be hashable. This generally means strings, numbers,
or tuples of hashables.
"""
self.states = states
self.start = start
self.delta = delta
self.accepts = accepts
self.alphabet = alphabet
self.current_state = start
知道如何创建DFA类的实例吗?注意,我不想使用Github中可用的DFA
的实现版本