猴子摘香蕉实验报告(含代码).doc_第1页
猴子摘香蕉实验报告(含代码).doc_第2页
猴子摘香蕉实验报告(含代码).doc_第3页
猴子摘香蕉实验报告(含代码).doc_第4页
猴子摘香蕉实验报告(含代码).doc_第5页
已阅读5页,还剩11页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

华中科技大学人工智能与模式识别 实验报告 院 系: 电子与信息工程系 班 级: 姓 名: 同 组 人: 指导老师: 电 话: 邮 箱: 日 期: 2013年12月24日 1、 实验内容利用一阶谓词逻辑求解猴子摘香蕉问题:房内有一个猴子,一个箱子,天花板上挂了一串香蕉,其位置如图所示,猴子为了拿到香蕉,它必须把箱子搬到香蕉下面,然后再爬到箱子上。请定义必要的谓词,列出问题的初始化状态(即下图所示状态),目标状态(猴子拿到了香蕉,站在箱子上,箱子位于位置b)。(附加:从初始状态到目标状态的谓词演算过程。)2、 实验平台vc6.03、 实验分析1. 定义描述环境状态的谓词。at(x,w):x在t处,个体域:xmonkey,wa,b,c,box;hold(x,t):x手中拿着t,个体域:tbox,banana;empty(x):x手中是空的;on(t,y):t在y处,个体域:yb,c,ceiling;clear(y):y上是空的;box(u):u是箱子,个体域:ubox;banana(v):v是香蕉,个体域:vbanana;2. 使用谓词、连结词、量词来表示环境状态。问题的初始状态可表示为:so:at(monkey,a)empty(monkey)on(box,c)on(banana,ceiling)clear(b)box(box)banana(banana)要达到的目标状态为:sg:at(monkey,box)hold(monkey,banana)on(box,b)clear(ceiling)clear(c)box(box)banana(banana)3. 从初始状态到目标状态的转化, 猴子需要完成一系列操作, 定义操作类谓词表示其动作。walk(m,n):猴子从m走到n处,个体域:m,na,b,c;carry(s,r):猴子在r处拿到s,个体域:rc,ceiling,sbox,banana;climb(u,b):猴子在b处爬上u;这3个操作也可分别用条件和动作来表示。条件直接用谓词公式表示,是为完成相应操作所必须具备的条件;当条件中的事实使其均为真时,则可激活操作规则,于是可执行该规则中的动作部分。动作通过前后状态的变化表示,即通过从动作前删除或增加谓词公式来描述动作后的状态。walk(m,n):猴子从m走到n处条件:at(monkey,m)动作:carry(s,r):猴子在r处拿到s条件:at(monkey,r)empty(monkey)on(s,r)box(box)banana(banana)动作:climb(u,b):猴子在b处爬上u条件:at(monkey,b)hold(monkey,u)clear(b)box(box)banana(banana)动作:4. 按照行动计划, 一步步进行状态替换, 直至目标状态。at(monkey,a)empty(monkey)on(box,c)on(banana,ceiling)clear(b)box(box)banana(banana)at(monkey,c)empty(monkey)on(box,c)on(banana,ceiling)clear(b)box(box)banana(banana)at(monkey,c)hold(monkey,box)on(banana,ceiling)clear(b)clear(c)box(box)banana(banana)at(monkey,b)hold(monkey,box)on(banana,ceiling)clear(b)clear(c)box(box)banana(banana)at(monkey,box)empty(monkey)on(box,b)on(banana,ceiling)clear(c)box(box)banana(banana)at(monkey,box)hold(monkey,banana)on(box,b)clear(ceiling)clear(c)box(box)banana(banana)(目标得解)猴子行动的规则序列是:walk(a,c)carry(c,box)walk(c,b)climb(box,b)carry(banana,ceiling)在上述过程中,我们应该注意,当猴子执行某一个操作之前,需要检查当前状态是否可使所要求的条件得到满足,即证明当前状态是否蕴涵操作所要求的状态的过程。在行动过程中, 检查条件的满足性后才进行变量的代换。代入新条件后的新状态如果是目标状态,则问题解决;否则看是否满足下面的操作,如果不满足或即使满足却又回到了原来的状态,那么代入无效。4、 源代码#include struct stateint monkey; /*-1:monkey at a;0: monkey at b;1:monkey at c;*/ int box; /*-1:box at a;0:box at b;1:box at c;*/ int banana; /*banana at b,banana=0*/ int monbox; /*-1: monkey on the box;1: monkey the box;*/;struct state states 150;char* routesave150; /*function monkeygoto,it makes the monkey goto the other place*/void monkeygoto(int b,int i) int a;a=b;if (a=-1)routesavei=monkey go to a;statesi+1=statesi;statesi+1.monkey=-1;else if(a=0)routesavei=monkey go to b;statesi+1=statesi;statesi+1.monkey=0;else if(a=1)routesavei=monkey go to c;statesi+1=statesi;statesi+1.monkey=1;else printf(parameter is wrong);/*end function monkeyygoto*/ /*function movebox,the monkey move the box to the other place*/void movebox(int a,int i) int b;b=a;if(b=-1)routesavei=monkey move box to a;statesi+1=statesi;statesi+1.monkey=-1;statesi+1.box=-1;else if(b=0)routesavei = monkey move box to b;statesi+1=statesi;statesi+1.monkey=0;statesi+1.box=0;else if(b=1)routesavei = monkey move box to c;statesi+1=statesi;statesi+1.monkey=1;statesi+1.box=1;elseprintf(parameter is wrong);/*end function movebox*/ /*function climbonto,the monkey climb onto the box*/void climbonto(int i)routesavei=monkey climb onto the box;statesi+1=statesi;statesi+1.monbox=1;/*function climbdown,monkey climb down from the box*/void climbdown(int i) routesavei=monkey climb down from the box;statesi+1=statesi;statesi+1.monbox=-1;/*function reach,if the monkey,box,and banana are at the same place,the monkey reach banana*/void reach(int i) routesavei=monkey reach the banana;/*output the solution to the problem*/void showsolution(int i) int c; printf (%s n, result to problem:); for(c=0; c=150) printf(%s n, steplength reached 150,have problem ); return; for (c=0; ci; c+) /*if the current state is same to previous,retrospect*/ if(statesc.monkey=statesi.monkey&statesc.box=statesi.box&statesc.banana=statesi.banana&statesc.monbox=statesi.monbox) return; if(statesi.monbox=1&statesi.monkey=0&statesi.banana=0&statesi.box=0) showsolution(i);printf(press any key to continue n);getchar();/*to save screen for user,press any key to continue*/return; j=i+1; if(statesi.monkey=0) if(statesi.box=0)if(statesi.monbox=-1)climbonto(i);reach(i+1);nextstep(j);/*monkeygoto(-1,i);nextstep(j);monkeygoto(0,i);nextstep(j);movebox(-1,i);nextstep(j);movebox(0,i);nextstep(j);*/elsereach(i+1);nextstep(j);/*climbdown(i);nextstep(j);*/ else if(statesi.box=1)/*monkeygoto(-1,i);nextstep(j);*/monkeygoto(1,i);nextstep(j);movebox(0,i);nextstep(j);climbonto(i);reach(i+1);nextstep(j);else /*box=-1*/monkeygoto(-1,i);nextstep(j);movebox(0,i);nextstep(j);climbonto(i);reach(i+1);nextstep(j); /*end if*/if(statesi.monkey=-1) if(statesi.box=-1)if(statesi.monbox=-1) movebox(0,i);nextstep(j);climbonto(i);reach(i+1);nextstep(j);elseclimbdown(i);nextstep(j);movebox(0,i);nextstep(j);climbonto(i);reach(i+1);nextstep(j);else if(statesi.box=0) monkeygoto(0,i);nextstep(j);climbonto(i);reach(i+1);nextstep(j);elsemonkeygoto(1,i);nextstep(j);movebox(0,i);nextstep(j);climbonto(i);reach(i+1);nextstep(j);/*end if*/if(statesi.monkey=1) if (statesi.box=1)if(statesi.monbox=-1) movebox(0,i);nextstep(j);climbonto(i);reach(i+1);nextstep(j);elseclimbdown(i);nextstep(j);movebox(0,i);nextstep(j);climbonto(i);reach(i+1);nextstep(j); else if(statesi.box=-1) monkeygoto(-1,i);nextstep(j);movebox(0,i);nextstep(j); move

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论