《人工智能》实验报告之产生式系统Word文档下载推荐.docx
《《人工智能》实验报告之产生式系统Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《《人工智能》实验报告之产生式系统Word文档下载推荐.docx(13页珍藏版)》请在冰点文库上搜索。
get{returna_id;
}
set{a_id=value;
privateStringa_condition;
publicStringA_condition
get{returna_condition;
set{a_condition=value;
privateStringa_result;
publicStringA_result
get{returna_result;
set{a_result=value;
②参数设计:
int[]temp=newint[50];
//存储当前所选择的的事实及推导出来的事实编号
string[]factInput=newstring[30];
//存储当前所选择的的事实及推导出来的事实内容
publicstaticstring[]factSelected=newstring[20];
//存储用户选择的事实,方便两个界面传递数据
publicstaticintfactLength;
//存储事实库中的实际数据个数
string[]resultList=newstring[length];
//存储规则库中所有后件
string[][]conditionList=newstring[length][];
//存储规则库中所有前件
③函数说明:
publicList<
Animal>
getAll();
//取出规则库中的所有规则
publicAnimalgetResultByID(inta_id);
//根据ID取出规则的后件
privatevoidCompare(string[]factInput,string[][]conditionList,intj);
//匹配规则和已知事实库
privatevoidInsertRules(Animala);
//将匹配成功的规则显示在界面上
4.系统流程
5.源程序清单
①用户选择界面:
Form1
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usinganimal_IS.data;
namespaceanimal_IS
{
publicpartialclassForm1:
Form
//存?
储洹?
当獭?
前°
所ù
选?
择?
的?
实害?
事?
以?
及°
推?
导?
出?
来ぁ?
publicForm1()
InitializeComponent();
privatevoidbutton1_Click(objectsender,EventArgse)
this.checkBox1.Checked=false;
this.checkBox2.Checked=false;
this.checkBox3.Checked=false;
this.checkBox4.Checked=false;
this.checkBox5.Checked=false;
this.checkBox6.Checked=false;
this.checkBox7.Checked=false;
this.checkBox8.Checked=false;
this.checkBox9.Checked=false;
this.checkBox10.Checked=false;
this.checkBox11.Checked=false;
this.checkBox12.Checked=false;
this.checkBox13.Checked=false;
this.checkBox14.Checked=false;
this.checkBox15.Checked=false;
this.checkBox16.Checked=false;
this.checkBox17.Checked=false;
this.checkBox18.Checked=false;
this.checkBox19.Checked=false;
this.checkBox20.Checked=false;
this.checkBox21.Checked=false;
this.checkBox22.Checked=false;
for(inti=0;
i<
Program.factSelected.Length;
i++)
Program.factSelected[i]=null;
}//重?
置?
有瓺选?
项?
privatevoidbutton2_Click(objectsender,EventArgse)
int[]factNum=newint[20];
intk=0;
for(inti=1;
=22;
CheckBoxche=(CheckBox)this.groupBox1.Controls.Find("
checkBox"
+i,true)[0];
if(che.Checked)
factNum[k]=i;
k++;
//记?
录?
用?
户§
输?
入?
编括?
号?
Program.factLength=k;
for(intj=0;
j<
factNum.Length;
j++)
DBdata=newDB();
stringsql="
selectfactContentfrom[fact]wherefactID="
+factNum[j];
//根ù
据Y编括?
查é
找ò
规?
则ò
键ü
内ú
容╕,?
显?
示?
在ú
textbox中D
DataTabledt=data.query(sql);
if(dt.Rows.Count>
0)
Program.factSelected[j]=dt.Rows[0][0].ToString();
Form2fr=newForm2();
fr.ShowDialog();
}
②结果显示界面:
Form2
usinganimal_IS.business;
usinganimal_IS.entity;
publicpartialclassForm2:
publicForm2()
privatevoidForm2_Load(objectsender,EventArgse)
/**********************将?
数簓据Y库a中D的?
数簓据Y取?
放?
二t维?
数簓组哩?
里?
*******************************/
List<
ls=newList<
();
AnimalOptionaop=newAnimalOption();
ls=aop.getAll();
intlength=ls.Count;
length;
resultList[i]=ls[i].A_result;
conditionList[i]=ls[i].A_condition.Split('
,?
'
);
/************************************************************************************/
/****************读á
取?
并¢放?
数簓组哩actInput*****************/
stringfact=null;
//定¨
义?
存?
已?
知a事?
库a
Program.factSelected.Length;
fact+="
"
+Program.factSelected[i];
factInput[i]=Program.factSelected[i];
this.textBox3.Text=fact;
/**********************************************************************************/
stringstart="
/***********************推?
理え?
开a始?
**********************/\r\n\r\n"
;
textBox1.Text=start;
conditionList.Length;
if(conditionList[j]!
=null)
Compare(factInput,conditionList,j);
if(this.textBox1.Text.Equals(start))
this.textBox1.Text+="
糟?
糕a了?
啥?
也?
没?
。
£o(╯□?
╰)oTryAgain?
"
if(factInput[Program.factLength-1].Equals("
老?
虎¢"
))
this.textBox2.Text="
O(∩é
_∩é
)O~~~老?
return;
豹繿子哩?
)O~~~豹繿子哩?
斑?
马í
)O~~~斑?
长¤
颈±
鹿1"
)O~~~长¤
海£鸟?
)O~~~海£鸟?
企ó
鹅ì
)O~~~企ó
鸵?
鸟?
)O~~~鸵?
else
o_O?
?
小?
才?
疏酣?
学§
浅3没?
见?
过y这a动ˉ物?
你?
丫?
上?
火e星?
去ǎ?
吧悒?
!
privatevoidCompare(string[]factInput,string[][]conditionList,intj)
intflag=0;
//将?
匹¥配?
标括?
志?
个?
数簓
intwidth=conditionList[j].Length;
for(intk=0;
k<
width;
k++)
for(intm=0;
m<
Program.factLength;
m++)
if((conditionList[j][k].Equals(factInput[m])))
flag++;
//一?
旦?
有瓺规?
不?
与?
库a匹¥配?
数簓加ó
1
if(flag==width)//当獭?
一?
条?
中D的?
有瓺前°
都?
时骸?
Animala=newAnimal();
a=aop.getResultByID(j+1);
//获?
该?
stringresult=a.A_result;
得?
完?
全?
后ó
Program.factLength++;
//已?
库afactInput的?
非?
空?
位?
factInput[Program.factLength-1]=result;
知a实害?
库a中D
InsertRules(a);
//讲2该?
privatevoidInsertRules(Animala)
stringcondition=a.A_condition;
intid=a.A_id;
stringrun=null;
run="
使?
第台?
+id+"
:
阰"
+condition+"
╮(╯▽?
╰)╭>
>
+result+"
\r\n\r\n"
this.textBox1.Text+=run;
四、分析讨论
此次试验在建立数据库的过程中斟酌了很久,最终选定前件和后件各为一个属性的办法,最后使用的时候取出放入二维数组,这样既方便取出,又减少了数据冗余。
六、教师评语
签名:
日期:
2013.4
成绩
说明:
实验检查方式(7-8周)
1.系统演示
a)界面显示要求
(1)有若干选择初始事实的选择列表;
(2)显示规则的调用次序及综合数据库的变化过程;
(正向推理中显示每使用一次规则后,产生的新事实。
反向推理中显示新的目标事实有哪些需要证明及哪些已经得到证实);
(3)显示最后的推理结果。
b)代码基本功能的实现要求
初始事实的输入;
规则的存储与载入;
规则匹配、冲突消解、规则执行;
结果输出。
2.提交实验报告