云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 人工智能实验报告

人工智能实验报告

  • 62 次阅读
  • 3 次下载
  • 2025/12/12 5:31:43

}

///////////////////////////

// the two states exchange

void Eight::move(state des, state src) { for(int row = 0; row

/////////////////////////

// extend other states

void Eight::genNewState(state oldState) { int row,col; int temp;//保存状态转换数组中的值 state newState; findZeroPostion(row,col,oldState);//find zero position if(row +1 < N)//0向下移动 { //move(newState, oldState); newState = oldState; newState.depth = oldState.depth +1; newState.parent = oldState.nID; newState.nID = nAutoIncrease++;//对ID自动编号 //switch temp = newState.arrState[row][col]; newState.arrState[row][col] = newState.arrState[row+1][col]; newState.arrState[row+1][col] = temp; newState.value = w(newState.arrState) + newState.depth; //newState.value = f(newState); //push newState to open genToOpen(newState); } if(row - 1 > -1)//0向上移动 {

}

newState = oldState;

newState.depth = oldState.depth +1; newState.parent = oldState.nID;

newState.nID = nAutoIncrease++;//对ID自动编号

//switch

temp = newState.arrState[row][col];

newState.arrState[row][col] = newState.arrState[row-1][col]; newState.arrState[row-1][col] = temp;

newState.value = w(newState.arrState) + newState.depth; //newState.value = f(newState); //push newState to open genToOpen(newState);

if(col +1 < N)//0向右移动 { newState = oldState; newState.depth = oldState.depth +1; newState.parent = oldState.nID; newState.nID = nAutoIncrease++;//对ID自动编号 }

//switch

temp = newState.arrState[row][col];

newState.arrState[row][col] = newState.arrState[row][col+1]; newState.arrState[row][col+1] = temp;

newState.value = w(newState.arrState) + newState.depth; //newState.value = f(newState); //push newState to open genToOpen(newState);

if(col -1 > -1)//0向左移动 { newState = oldState; newState.depth = oldState.depth +1; newState.parent = oldState.nID; newState.nID = nAutoIncrease++;//对ID自动编号 //switch temp = newState.arrState[row][col]; newState.arrState[row][col] = newState.arrState[row][col-1]; newState.arrState[row][col-1] = temp;

newState.value = w(newState.arrState) + newState.depth; //newState.value = f(newState); //push newState to open genToOpen(newState); } }

/////////////////////////////////////

//把open表中已访问的state放到closed表中 void Eight::moveToClosed(state s) { int i = ++closedIndex; closed[i] = s; //delete from open table for(int j = 0;j < openIndex-1; j++) open[j]=open[j+1]; //open length-1 openIndex--; }

/////////////////////////////////////

//把扩展的状态放入open表中 void Eight::genToOpen(state s) { if(IsInOpen(s)) { //show(s); //cout<<\该状态已存在open表中!\ nAutoIncrease--; return; } if(IsInClosed(s)) { //show(s); //cout<<\该状态已存在closed表中!\ nAutoIncrease--; return; } int i = ++openIndex; open[i] = s;

open[i].depth = s.depth; open[i].parent = s.parent; open[i].value = s.value; }

////////////////////////////

// current state compare to goal state bool Eight::compare(state s) { for(int i=0; i

////////////////////////////

// Is current state in closed table bool Eight::IsInClosed(state s) { for(int k = 0; k <= closedIndex; k++) { if(closed[k] == s) return true; } return false; }

////////////////////////////

// Is current state in open table bool Eight::IsInOpen(state s) { for(int k = 0; k <= openIndex; k++) { if(open[k] == s) return true; } return false; }

void Eight::heuristicSearch() {

搜索更多关于: 人工智能实验报告 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

} /////////////////////////// // the two states exchange void Eight::move(state des, state src) { for(int row = 0; row

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com