人工智能导论产生式系统解读_第1页
人工智能导论产生式系统解读_第2页
人工智能导论产生式系统解读_第3页
人工智能导论产生式系统解读_第4页
已阅读5页,还剩4页未读, 继续免费阅读

付费下载

下载本文档

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

文档简介

1、( 北京)CHINA UNIVERSITY OF PETROLEUM人工智能导论产生式系统院系名称:地球物理与信息工程学院专业名称:计算机科学与技术学号:姓名:完成日期2015年6月8日实验内容:规则: (rule identify1(if (animal has hair)(then (animal is mammal)(rule identify2(if (animal gives milk)(then (animal is mammal)(rule identify3(if (animal has feathers)(then (animal is bird)(rule identify

2、4(if(animal flies)(animal lays eggs)(then (animal is bird)(rule identify5(if (animal eats meat)(then (animal is carnivore)(rule identify6(if (animal has pointed teeth)(animal has claws)(animal has forward eyes)(then (animal is carnivore)(rule identify7(if (animal is mammal) (animal has hoofs)(then (

3、animal is ungulate)(rule identify8(if(animal is mammal)(animal chews cud)(then (animal is ungulate)(even toed)(rule identify9(if(animal is mammal)(animal is carnivore)(animal has tawny color) (animal has dark spots)(then (animal is cheetah)(rule identify10(if (animal is mammal)(animal is carnivore)(

4、animal has tawny color) (animal has black stripes)(then (animal is tiger)(rule identify11(if (animal is ungulate) (animal has long neck)(animal has log legs) (animal has dark spots)(then (animal is giraffe)(rule identify12(if (animal is ungulate) (animal has black stripes)(then (animal is zebra) )(r

5、ule identify13(if (animal is bird)(animal does not fly)(animal has long neck) (animal has long legs)(animal is black and white)(then (animal is ostrich)(rule identify14(if(animal is bird)(animal does not fly)(animal swims) (animal is black and white)(then (animal is penguin)(rule identify15(if(anima

6、l is bird)(animal flys well)(then (animal is albatross)实验工具:VC+6.0设计思路:将每条语句按顺序编号,然后将规则存在R156数组中,在屏幕上输入所拥有的条件数量并输入规则编号,余下的会自动用 0 占位,将输入的规则序号存入数组get20 中,然后递归调用 Contrast()函数,得出结论,在 Contrast()函数中调用Comparison() 函数来比较每一条规则在输入条件中是否存在,若存在则把条件替换成所含有规则的结论。最后当 get 数组中只含有最后一个非零语句编号时,则为最终结论。详细代码:/ setq_fact.cpp

7、 : Defines the entry point for the console application.#include "stdafx.h"/语句数组 ruleschar rules3330="animal has hair","animal is mammal","animal gives milk","animal has feathers","animal is bird","animal flies","animal lays e

8、ggs","animal eats meat","animal is carnivore","animal has pointed teeth","animal has claws","animal has forward eyes","animal has hoofs","animal is ungulate","animal chews cud","even toed","animal has

9、 tawny color","animal has dark spots","animal ischeetah","animal has black stripes","animal is tiger","animal is ungulate","animal has long neck","animal is giraffe","animal is zebra","animal does not fly"

10、,"animal has long legs","animal is black and white","animal is ostrich","animal swims","animal is penguin","animal flys well","animal is albatross"/规则数组 RintR156=1,0,0,0,0,2,3,0,0,0,0,2,4,0,0,0,0,5,6,7,0,0,0,5,8,0,0,0,0,9,10,11,12

11、,0,0,9,2,13,0,0,0,14,2,15,0,0,0,14,2,9,17,18,0,19,2,9,17,20,0,21,14,18,22,23,0,24,14,20,0,0,0,25,5,22,26,27,28,29,5,26,28,30,0,31,5,32,0,0,0,33;/输入存储数组 getint get20;int all;/函数定义void Sort(); /数组排序void Contrast(); /数组对比int Comparison(int i,int j);/规则比较int main(int argc, char* argv)int i,j,m=100,n;/显示

12、所有条件for(i=0;i<30;i+)printf("%d",i+1);for(j=0;j<30;j+)printf("%c",rulesij);printf("n");printf(" 输入所拥有的条件数 :");/请输入条件数scanf("%d",&all);all-;printf("please put in your fact(change from 133):n");/请输入条件printf("begin: ");i=0;w

13、hile(i<=all-1)/读取输入的条件在get 数组中scanf("%d",&m);geti=m;printf("go on: ");i+;scanf("%d",&m);getall=m;for(i=all+1;i<=19;i+)geti=0;Sort();/排序Contrast();/算法if(get0>=1&&get0<=33&&get1=0)/如果结果存在,输出结论printf("The conclusion is: %d ",ge

14、t0);for(j=0;j<=29;j+)printf("%c",rulesget0-1j);else printf("NO Answer!");/不存在,提示没有结果while(1);return 0;void Sort()/对 get数组内部从小到大排序,相同的数字只保留一个int n;for(int i=0;i<=19;i+)for(int j=i+1;j<=all;j+)if(geti>getj)/排序n=geti;geti=getj;getj=n;else if(geti=getj&&getj!=0) /

15、相同非 0 数只保留一个,其余取 0 getj=0;for(i=0;i<=all;i+)/把 0 放在数组末尾if(get0=0)for(int j=0;j<=all;j+)getj=getj+1;getall=0;void Contrast()/比照 R 数组和 get 数组int i;for(i=0;i<=14;i+)for(int j=0;j<=all;j+)if(Comparison(i,j)=1) Sort();Contrast();/比较每一条规则在 get 数组中是否存在,存在则简化 get 数组 int Comparison(int i,int j)in

16、t m,n,count=0,k5,l5,a=0;for(n=0;n<=4;n+)kn=0;ln=0;for(n=0;n<=j;n+)for(m=0;m<=all;m+)if(Rin=getm)kn=getm; /把可能存在的规则条件存在k 数组中la+=m+1;/把 get数组中可能存在规则的位置记录在l 数组中break;for(m=0;m<=4;m+)if(km=Rim)count+;if(count=5) /如果规则存在for(m=0;m<=4;m+)if(lm!=0)getlm-1=Ri5;/取出规则结果放在get 中return 1;elsereturn 0;运行过程:读书的好处1、行万里路,读万卷书。2、书山有路勤为径,学海无涯苦作舟。3、读书破万卷,下笔如有神。4、我所学到的任何有价值的知识都是由自学中得来的。 达尔文5、少壮不努力,老大徒悲伤。6、黑发不知勤学早,白首方悔读书迟。 颜真卿7、宝剑锋从磨砺出,梅花香自苦寒来。8、读书要三到:心到、眼到、口到

温馨提示

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

评论

0/150

提交评论