資源簡(jiǎn)介
從那三個(gè)txt文檔讀出數(shù)據(jù),然后根據(jù)自己寫的算法,從正向和反向推理來的識(shí)別用戶所描述是什么動(dòng)物。

代碼片段和文件信息
#include
#include
#include
#include
#define?MAXNUM?50
typedef?struct
{
int?xuh;
char?valu[50];
}Node;
typedef?struct
{
int?stat;//0:還未訪問???1:至少用過一次???2:沒用過但不沖突
int?xuh;
}NFact;
typedef?struct
{
int?snum;//開始時(shí)的事實(shí)數(shù)
int?curnum;//目前的事實(shí)數(shù)
int?notEnoughFlag;//當(dāng)最后若所有未用過的條件支持一個(gè)結(jié)論,但條件不足時(shí),置1
NFact?cod[MAXNUM];
}Fact;
typedef?struct
{
int?rslt;
int?codNum;//記載前提的個(gè)數(shù)
int?cod[10];//記載前提的序號(hào)
int?used;//記載是否已匹配成功
}Nrule;
typedef?struct
{
int?codXuh;
int?stat;
double?weight;
int?rslt;
//int?codNum;
}bQueueNode;
typedef?struct
{
int?head;
int?tail;
bQueueNode?bNode[MAXNUM];
}bQueue;
typedef?struct
{
int?canReachTime;
int?havReached;
}Reach;
typedef?struct
{
int?lastCodXuhInQueue;
int?myXuh;
//int?mycodNum;
int?myRslt;
double myweight;
}CloseNode;
typedef?struct
{
int?head;
int?tail;
CloseNode?node[MAXNUM];?
}Close;
int?codnum=28;
int?goalnum=7;
int?rulenum=0;
Node?goal[20];
Node?cod[50];
Nrule?rule[50];
Fact?inpCod;
bQueue?bqueue;
Reach?recReach[MAXNUM];
Close?close;
void?readGoal()
{
FILE??*fp;
int?i;
if((fp=fopen(“goal.txt““r“))==NULL)
{
printf(“cannot?open?goal\n“);
exit(0);
}
i=0;
while((fscanf(fp“%d?%s“&goal[i].xuh&goal[i++].valu))!=EOF);
fclose(fp);
}//readGoal
void?readRule()
{
FILE??*fp;
int?i;
int?tempxuhtempcodn;
char?ch;
if((fp=fopen(“rules.txt““r“))==NULL)
{
printf(“cannot?open?data\n“);
exit(0);
}
i=0;
rule[i].codNum=0;
while((ch=fgetc(fp))!=EOF)
{
if(i==14)
i=i;
tempcodn=0;
while(ch!=‘\n‘&&ch!=EOF) //每一條規(guī)則
{
tempxuh=0;
while(ch<=‘9‘&&ch>=‘0‘)
{
tempxuh=tempxuh*10+ch-‘0‘;
ch=fgetc(fp);
}
rule[i].cod[tempcodn++]=tempxuh;
tempxuh=0;
if(ch==‘-‘)//下一個(gè)是結(jié)論
{
ch=fgetc(fp);
ch=fgetc(fp);
while(ch<=‘9‘&&ch>=‘0‘)
{
tempxuh=tempxuh*10+ch-‘0‘;
ch=fgetc(fp);
}
rule[i].rslt=tempxuh;
}//if
else?if(ch==‘*‘)
{
ch=fgetc(fp);
}
rule[i].codNum++;
}
i++;
}
rulenum=i;
fclose(fp);
}//readCod
void?readCod()
{
FILE??*fp;
int?i;
if((fp=fopen(“data.txt““r“))==NULL)
{
printf(“cannot?open?data\n“);
exit(0);
}
i=0;
while((fscanf(fp“%d?%s“&cod[i].xuh&cod[i++].valu))!=EOF);
fclose(fp);
}//readCod
void?readFiles()
{
//char?fname[100];
readGoal();
readCod();
readRule();
}//reaFiles
int?inputCod()
{
int?retflag=1;
int?temp;
int?i;
i=0;
do
{
scanf(“%d“&temp);
inpCod.cod[i++].xuh=temp;
if(temp>=codnum)
{
printf(“特征序號(hào)不能大于%d請(qǐng)重新輸入:\n“codnum-1);
fflush(stdin);
retflag=0;
}
}while(temp!=-1&&temp inpCod.snum=i-1;
inpCod.curnum=inpCod.snum;
/*inpCod.snum=5;
inpCod.curnum=inpCod.snum;
inpCod.cod[0].xuh=1;
inpCod.cod[1].xuh=5;
inpCod.cod[2].xuh=10;
inpCod.cod[3].xuh=15;
inpCod.cod[4].xuh=16;*/
return?retflag;
}//inputCod()
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????292??2009-12-17?18:16??產(chǎn)生式系統(tǒng)?正向和反向\data.txt
?????文件?????????58??2009-12-13?21:24??產(chǎn)生式系統(tǒng)?正向和反向\goal.txt
?????文件????????179??2009-12-17?18:16??產(chǎn)生式系統(tǒng)?正向和反向\rules.txt
?????文件??????14355??2009-12-26?00:11??產(chǎn)生式系統(tǒng)?正向和反向\產(chǎn)生式系統(tǒng)?正向和反向?finnal.c
?????目錄??????????0??2010-01-09?16:14??產(chǎn)生式系統(tǒng)?正向和反向
-----------?---------??----------?-----??----
????????????????14884????????????????????5
- 上一篇:C語言windows庫函數(shù)
- 下一篇:C++ AVI播放器
評(píng)論
共有 條評(píng)論