简体   繁体   English

确定性有限自动机模式

[英]Deterministic Finite Automata pattern

I'm trying to solve this problem using Deterministic Finite Automata : 我正在尝试使用Deterministic Finite Automata来解决这个问题:

inputs:     {a,b}
conditions: 
a. must have exactly 2 a  
b. have more than 2 b

so a correct input should be like this abbba or bbbaa or babab 所以正确的输入应该像这个abbbabbbaababab

now my question is, "is there a pattern to solve this things?" 现在我的问题是,“有没有解决这个问题的模式?”

Yes there is a pattern. 是的,有一种模式。 You can take each statement and deduct pre-states from them. 您可以从中获取每个语句并从中扣除预先状态。 Then you take the cross-product of those pre-states, which will comprise the final states. 然后你采用那些包含最终状态的前置状态的交叉积。 In this example: 在这个例子中:

a. 一种。 will yield states: 0a, 1a, 2a, 2+a (you've seen 0 a, 1 a, 2 as or more than 2 as) b. 将产生状态:0a,1a,2a,2 + a(你已经看到0 a,1 a,2或2或2)b。 will yield states: 0b, 1b, 2b, 2+b (you've seen 0 b, 1 b, 2 bs or more than 2 bs) 将产生状态:0b,1b,2b,2 + b(你已经看到0 b,1b,2 bs或超过2 bs)

The cross product of these states result in 4x4=16 states. 这些状态的叉积导致4x4 = 16个状态。 You'll start from {0a,0b} states. 你将从{0a,0b}州开始。 The inputs can be 3 types: a, b or something else. 输入可以是3种类型:a,b或其他类型。 From that you should be able to go. 从那以后你应该可以去。 Do you need more help? 你需要更多帮助吗?

(Are we solving homework?) (我们在解决作业吗?)

Always draw such things first. 总是先画这些东西。

Feel free to give states any meanings. 随意给各州任何意义。 What you need here is states like: q2: (1 b, 2 a's) . 你需要的是像: q2: (1 b, 2 a's) Draw states like this, until the accept state and connect them with lines. 绘制这样的状态,直到接受状态并用线连接它们。 The accept state is qx: 2 a's 3 b's . 接受状态是qx: 2 a's 3 b's

After reaching the accept state, if input is "b" that line goes to itself, the accept state. 在达到接受状态后,如果输入为“b”,则该行进入自身,即接受状态。 If the input is "a", draw a new state, that will get into an endless loop and goes into itself no matter what the input is. 如果输入是“a”,则绘制一个新状态,无论输入是什么,它都将进入无限循环并进入自身。

(are we helping for an exam here?) (我们在这里帮助考试吗?)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM