有限状态机(FSM)是表示有限个状态及在这些状态之间的转移和动作等行为的数学模型,在计算机领域有着广泛的应用。通常FSM包含几个要素:状态的管理、状态的监控、状态的触发、状态触发后引发的动作。本文主要阐述一下状态机的几种设计方法。

1:switch case/if else设计方法

curEvent = getEvent();
curState = getCurState();
switch(curState)
{
case state1:
{
switch(curEvent )
{
TODO...
setCurState();
break;
}
break;
}
...
}

这种设计方法最简单,通过一大堆判断来处理,适合小规模的状态切换流程,但如果规模扩大难以扩展和维护。

2:基于表结构的状态机设计方法:建立相应的状态表和动作查询表,根据状态表、事件、动作表定位相应的动作处理函数,执行完成后再进行状态的切换。

一个通用的状态机处理模块的设计如下:

/*状态表注册*/
void FSM_Regist(FSM_T* pFsm,STATE_TABLE_S* pStateTable)
{
pFsm->FsmTable = pStateTable;
return;
}
/*状态迁移*/
void FSM_MoveState(FSM_T* pFsm,int state)
{
pFsm->curState = state;
return;
}
/*事件处理*/
void FSM_EventHandle(FSM_T* pFsm,int event)
{
ACT_TABLE_T* pActTable = NULL;
ActFun eventActFun = NULL;
/*获取当前状态动作表*/
pActTable = FSM_getActTable(pFsm);
/*获取当前动作函数*/
for(int i=;i<MAX_ACT_NUM;i++)
{
if(event == pActTable[i].event)
{
eventActFun = pActTable[i].eventActFun;
break;
}
}
/*动作执行*/
if(eventActFun)
{
eventActFun(pFsm);
}
}

假设我们的状态图如下:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXcAAAEVCAIAAACUnjL4AAAgAElEQVR4nO3d/1fTVh8H8P5xHv6C/vA8P0yeVR57LDtPRKJrI7bHAWrxjI5p2VZO18O2OMscU083QSYdW3ewIGNoHRQ0oYB8aWFFCEMjcJ8fAiUtLbQlyc1NP69fBrWDm9v7eZPcJDcmBAAAajLhbgBCCPE8Pzo6GgwGPR6Pq7CWlpZgMBiNRuPxOO4mA6A1cssET8qk0+lIJOLz+WiaNpvNNE03Njbevn37119/fVrY4ODg7du33W43wzBms5miKK/XGw6Hk8kklq0AQFW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J08yDPPZZ5+xLDs4ODg9PX1IpszNzQ0ODnZ1dfn9foZhLBbL6dOn3W53V1dX5i4BydLSkiAIuDcXaAFSBuSxs7MjCEIqlZqdnX3+/HlfX19nZ6fX67Xb7e+//765sPfee89ut7e1tfn9/r6+PvkxEcdxMzMzyWRyfX19e3sb9yYC7UDKgCNsbW0JgrC8vDw/Pz89Pc2Vguf5+fn5ZDK5trYGS2dWLEgZUJqdnZ3Nzc21tbVDTiG9fv16c3MTzhYByf8BDvW73MDZ84kAAAAASUVORK5CYII=" alt="" />

相应的状态机设置如下:

/*状态1的动作表*/
ACT_TABLE_T state1ActTable[] = {
{EVENT1,state1Event1Fun},
{EVENT3,state1Event3Fun},
};
/*状态2的动作表*/
ACT_TABLE_T state2ActTable[] = {
{EVENT2,state2Event2Fun},
};
/*状态表*/
STATE_TABLE_T FsmTable[] = {
{STATE1,state1ActTable},
{STATE2,state2ActTable},
}; int main(int argc, _TCHAR* argv[])
{
FSM_T fsm;
/*状态表注册*/
FSM_Regist(&fsm,FsmTable);
FSM_MoveState(&fsm,STATE1);
FSM_EventHandle(&fsm,EVENT1);
FSM_EventHandle(&fsm,EVENT2);
return ;
}
/*客户端提供的状态处理函数*/
void state1Event1Fun(void* pFsm)
{
FSM_MoveState((FSM_T*)pFsm,STATE2);
return;
}
void state1Event3Fun(void* pFsm)
{
FSM_MoveState((FSM_T*)pFsm,STATE3);
return;
}
void state2Event2Fun(void* pFsm)
{
FSM_MoveState((FSM_T*)pFsm,STATE3);
return;
}

通过设计一个通用的基于表结构的状态机模块,针对不同的状态图,我们只需要根据状态图得到其状态表结构,然后通过FSM_Regist注册,就可以方便的使用了状态机的功能了。这种机制便于我们添加新的状态流程,并且可以很好的进行分层状态机的设计。

分层状态机的设计:

于状态较多的状态机,通常的设计会维护一个庞大的二维矩阵,所有状态耦合在一起,这往往导致维护困难,由于可能存在许多公共的特性,也会导致许多状态具有
相同的处理函数。针对这些问题我们可以通过设计分层状态机来解决,主要的思想就是根据不同的功能模块设计出多个状态机,各个状态机分布在不同的层次上。上
层状态机调用下层状态机时,上层状态机入栈,下层状态机变为当前处理状态机。通常我们使用堆栈来保存当前状态机的上层状态机信息。

下图描述一个分层状态机设计实现:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAssAAAFGCAIAAAATrEUXAAAgAElEQVR4nO3d7VMbWZ4veP0X/WJj9sVOxMTeuBsdsdExc+P23piOG+uO8Pb0jdiIUUSP566hC1SmkLuQQTJIMiC7wJiHMRiDKCyD1dgl23LZtO3ABRRVpaJKVS5MYUxZRghhSYB4Eg/CQhgsP+S+SJD1jASpPPnw/bypMkpEksk5+dXJk78joQAAAACYJiG9AwAAACBASBgAAADAPCQMAAAAYB4SBgAAADAPCQMAAACYh4QBAAAAzEPCAAAAAOYhYQAAAADzkDAAAACAeUgYAAAAwDwkDAAAAGAeEgYAAAAwDwkDAAAAmIeEAQAAAMxDwhAWT8dhicqyv1cBAHgqWefm6Tgs2YG+j31IGMKSKkNYVGhlACBIibs+iyrc5VlUEsnhDg/LuyV2SBjCkiRh0Dn+sEqFMQwAEKCEXZ9FFREqMIRLABKGsCRLGBaLJ/mrAAD8tnfnFjGeAWxBwhAWzMMAABHaq3PzdBzGTRL2IWEICxIGAIhQys7N03EY4xdEIGEICxIGAIhQ8s7N03EYczxJQcIQFiQMABChVJPc0ekRg4QhLEgYACBCCTs3TL4gDQlDWCLKy9CimhcSBgAIUqKujy4BFAndH8uQMAAAAIB5SBgAAADAPCQMAAAAYB4SBgAAADAPCQMAAACYh4QBAAAAzEPCAAAAAOYhYQAAAADzkDAAAACAeUgYAAAAwDwkDAAAAGAeEgYAAAAwDwkDAAAAmIeEAQAAAMxDwgAAAADmIWEAAAAA85AwAAAAgHlIGAAAAMA8JAwAAABgHhIGAAAAMA8JAwAAAJiHhAEAAADMQ8IAAAAA5iFhAAAAAPOQMAAAAIB5nEgYbrd7dHTUbDY3NTXpkquvrzebzUNDQw6Hg/QuA7ANzYTXVCqVFEAcVC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YII=" alt="" />

如上图所示,假设L1为上层状态机,L1状态机在L1_STATE2中可以通过L1L2_EVENT1事件触发进入L2状态机,L2状态机在L2_STATE2中通过L1L2_EVENT2事件触发返回L1状态机,L1和L2各自维护自己的状态表。

struct FSM_S
{
int curState; //当前状态机状态
int curFsmTableSize; //当前状态机查询表大小
STATE_TABLE_T* curFsmTable; //当前状态机查询表
FSM_STACK_T stack[MAX_FSM_STACK_DEP];//状态机堆栈
int curStackTop; //栈顶
FSM_REGIST_T registFsm[MAX_FSM_NUM]; //注册状态机
int registFsmNum; //注册状态机个数
};

1:通过堆栈数据结构维护上层状态机信息。

2:保存所有可以注册状态机信息。

3:记录当前运行状态机信息。

主要接口:

void FSM_Init(FSM_T* pFsm);
void FSM_Regist(FSM_T* pFsm,STATE_TABLE_S* pStateTable,int FsmId,int curFsmTableSize);
void FSM_Begin(FSM_T* pFsm,int FsmId);
void FSM_MoveState(FSM_T* pFsm,int state);
void FSM_EventHandle(FSM_T* pFsm,int event);
void FSM_Push(FSM_T* pFsm);void FSM_Pop(FSM_T* pFsm);

1:FSM_Regist 对所有的状态机信息进行注册

void FSM_Regist(FSM_T* pFsm,STATE_TABLE_S* pStateTable,int FsmId, int curFsmTableSize)
{
pFsm->registFsm[pFsm->registFsmNum].fsmId = FsmId;
pFsm->registFsm[pFsm->registFsmNum].FsmTable = pStateTable;
pFsm->registFsm[pFsm->registFsmNum].fsmTableSize = curFsmTableSize; pFsm->registFsmNum++;
return;
}

2:FSM_Begin 用于开始一个新的状态机流程,切换状态表信息。

void FSM_Begin(FSM_T* pFsm,int FsmId)
{
for(int i=;i<pFsm->registFsmNum;i++)
{
if(FsmId == pFsm->registFsm[i].fsmId)
{
pFsm->curFsmTable = pFsm->registFsm[i].FsmTable;
pFsm->curFsmTableSize = pFsm->registFsm[i].fsmTableSize;
break;
}
}
return;
}

3:FSM_Push/FSM_Pop 用于状态机切换的出入堆栈操作。

void FSM_Push(FSM_T* pFsm)
{
if(pFsm->curStackTop < MAX_FSM_STACK_DEP)
{
pFsm->curStackTop++;
pFsm->stack[pFsm->curStackTop].state = pFsm->curState;
pFsm->stack[pFsm->curStackTop].pFsmTable = pFsm->curFsmTable;
pFsm->stack[pFsm->curStackTop].fsmTableSize = pFsm->curFsmTableSize;
} return;
} void FSM_Pop(FSM_T* pFsm)
{
if(pFsm->curStackTop > -)
{
pFsm->curState = pFsm->stack[pFsm->curStackTop].state;
pFsm->curFsmTable = pFsm->stack[pFsm->curStackTop].pFsmTable;
pFsm->curFsmTableSize = pFsm->stack[pFsm->curStackTop].fsmTableSize;
pFsm->curStackTop--;
} return;
}

接口的使用:

/*L1 状态机定义*/
ACT_TABLE_T L1state1ActTable[] = {
{L1_EVENT1,L1state1_Event1Fun},
{L1_EVENT3,L1state1_Event3Fun},
};
ACT_TABLE_T L1state2ActTable[] = {
{L1_EVENT2,L1state2_Event2Fun},
{L1_L2_EVENT1,L1state2_L1L2EventFun},
};
STATE_TABLE_T L1FsmTable[] = {
{L1_STATE1,sizeof(L1state1ActTable)/sizeof(ACT_TABLE_T),L1state1ActTable},
{L1_STATE2,sizeof(L1state2ActTable)/sizeof(ACT_TABLE_T),L1state2ActTable},
};
/*L2 状态机定义*/
ACT_TABLE_T L2state1ActTable[] = {
{L2_EVENT1,L2state1_L2Event1Fun},
};
ACT_TABLE_T L2state2ActTable[] = {
{L1_L2_EVENT2,L2state2_L1L2EvenFun},
};
STATE_TABLE_T L2FsmTable[] = {
{L2_STATE1,sizeof(L2state1ActTable)/sizeof(ACT_TABLE_T),L2state1ActTable},
{L2_STATE2,sizeof(L2state2ActTable)/sizeof(ACT_TABLE_T),L2state2ActTable},
}; int main(int argc, _TCHAR* argv[])
{
FSM_T pFsm; FSM_Init(&pFsm);
/*状态机注册*/
FSM_Regist(&pFsm,L1FsmTable,FSM_L1,sizeof(L1FsmTable)/sizeof(STATE_TABLE_T));
FSM_Regist(&pFsm,L2FsmTable,FSM_L2,sizeof(L2FsmTable)/sizeof(STATE_TABLE_T));
/*开始L1状态机*/
FSM_Begin(&pFsm,FSM_L1);
FSM_MoveState(&pFsm,L1_STATE1);
FSM_EventHandle(&pFsm,L1_EVENT1);
/*push 状态机*/
FSM_EventHandle(&pFsm,L1_L2_EVENT1);
/*L2状态机处理*/
FSM_EventHandle(&pFsm,L2_EVENT1);
/*pop 状态机*/
FSM_EventHandle(&pFsm,L1_L2_EVENT2);
/*L1状态机处理*/
FSM_EventHandle(&pFsm,L1_EVENT2);
return ;
}

1:首先通过FSM_Regist注册所有的状态机。

2:FSM_EventHandle(&pFsm,L1_L2_EVENT1)中的动作处理函数中进行压栈操作同时进入L2状态机。

void L1state2_L1L2EventFun(void* pFsm)
{
FSM_Push((FSM_T*)pFsm);
FSM_Begin((FSM_T*)pFsm,FSM_L2);
FSM_MoveState((FSM_T*)pFsm,L2_STATE1); return;
}

3:FSM_EventHandle(&pFsm,L1_L2_EVENT2)中的动作处理函数中进行出栈操作返回到L1状态机。

void L2state2_L1L2EvenFun(void* pFsm)
{
FSM_Pop((FSM_T*)pFsm); return;
}

结论:

通过分层状态机的设计,各个功能实体维护自身的强相关的一套状态机,可以有效的减小状态机的复杂度,通过构建公共流程状态机,可以减小规模。综上所述:在针对规模较大、流程复杂的状态机设计,我们考虑使用分层的设计方法。

转载请注明原始出处:http://www.cnblogs.com/chencheng/archive/2012/06/28/2564336.html

有限状态机(FSM)的设计与实现的更多相关文章

  1. 有限状态机FSM(自动售报机Verilog实现)

    有限状态机FSM(自动售报机Verilog实现) FSM 状态机就是一种能够描述具有逻辑顺序和时序顺序事件的方法. 状态机有两大类:Mealy型和Moore型. Moore型状态机的输出只与当前状态有 ...

  2. cocos2d-x 游戏开发之有限状态机(FSM) (二)

    cocos2d-x 游戏开发之有限状态机(FSM)  (二) 1 状态模式

  3. 有限状态机FSM

    有限状态机(Finite-state machine)又称有限状态自动机,是表示有限个状态以及在这些状态之间的转移和动作等行为的数学模型.常用与:正则表达式引擎,编译器的词法和语法分析,游戏设计,网络 ...

  4. 有限状态机FSM详解及其实现

    有限状态机,也称为FSM(Finite State Machine),其在任意时刻都处于有限状态集合中的某一状态.当其获得一个输入字符时,将从当前状态转换到另一个状态,或者仍然保持在当前状态.任何一个 ...

  5. Atitit. 有限状态机 fsm 状态模式

    Atitit. 有限状态机 fsm 状态模式 1. 有限状态机 1 2. "状态表"和"状态轮换表" 1 3. 有限状态机概念(状态(State)事件(Even ...

  6. cocos2d-x 游戏开发之有限状态机(FSM) (四)

    cocos2d-x 游戏开发之有限状态机(FSM) (四) 虽然我们了解了FSM,并且可以写自己的FSM,但是有更好的工具帮我们完成这个繁琐的工作.SMC(http://smc.sourceforge ...

  7. cocos2d-x 游戏开发之有限状态机(FSM) (三)

    cocos2d-x 游戏开发之有限状态机(FSM) (三) 有限状态机简称FSM,现在我们创建一个专门的FSM类,负责管理对象(Monkey)的状态.然后Monkey类就实现了行为与状态分离.Monk ...

  8. cocos2d-x 游戏开发之有限状态机(FSM) (一)

    cocos2d-x 游戏开发之有限状态机(FSM) (一) 参考:http://blog.csdn.net/mgphuang/article/details/5845252<Cocos2d-x游 ...

  9. [原创][FPGA]有限状态机FSM学习笔记(一)

    1. 概述--何为有限状态机FSM? 有限状态机-Finite State Machine,简写为FSM,是表示有限个状态及在这些状态之间的转移和动作等行为的数学模型,在计算机领域有着广泛的应用.通常 ...

  10. Linux编程之有限状态机FSM的理解与实现

    有限状态机(finite state machine)简称FSM,表示有限个状态及在这些状态之间的转移和动作等行为的数学模型,在计算机领域有着广泛的应用.FSM是一种逻辑单元内部的一种高效编程方法,在 ...

随机推荐

  1. java中两个map比较

    一 /** * 用map的keySet()的迭代器(性能效率较低) * */ public void compareMap1 (){ Map<String, String> m1 = ne ...

  2. Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html

    操作数据库的时候,老是提示:Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your ow ...

  3. Node.js 历史

    Node.js 是在 2009年5月份创建的,是属于典型的 Git 和 GitHub 时代最初孕育的项目.另外需要先说明一点,那就是回顾 Node.js 的历史,并不是仅仅为了给大家回味,而是想找到在 ...

  4. 1、http简介

    HTTP 简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的传 ...

  5. win10 vm 11 桥接模式配置

    1 保证你Vmware里面的虚拟机是关机状态 2 在本地连接 属性中 卸载VM 桥接协议 3 管理员身份运行VM ,编辑>虚拟网络编辑器 删除所有网卡,并且重新配置网络适配器 4 配置完成后,选 ...

  6. iOS VIPER架构(二)

    第一篇文章对VIPER进行了简单的介绍,这篇文章将从VIPER的源头开始,比较现有的几种VIPER实现,对VIPER进行进一步的职责剖析,并对各种细节实现问题进行挖掘和探讨.最后给出两个完整的VIPE ...

  7. 重写strcat函数,以实现strcat的功能

    char * strcatTest(char *dst,const char *src);Action(){ char a[]="come on"; char b[]=" ...

  8. sqlserver中计算某个特殊字符在字符串中出现的位置

    -- ============================================= -- Author: Evan -- Create date: 2018年3月15日10:: -- D ...

  9. python基础教程总结4—基本语句

    一.print 和 import 的更多信息 print 打印多个表达式也是可行的,只要将它们用逗号隔开就好: >>> print('Age:' , 42) Age: 42 可以看到 ...

  10. 如何使用TensorFlow Hub和代码示例

    任何深度学习框架,为了获得成功,必须提供一系列最先进的模型,以及在流行和广泛接受的数据集上训练的权重,即与训练模型. TensorFlow现在已经提出了一个更好的框架,称为TensorFlow Hub ...