人工智能实验三范文.docVIP

  • 10
  • 0
  • 约 11页
  • 2016-11-26 发布于湖北
  • 举报
实 验 报 告 专业: 班级: 学号: 姓名: 课程名称:人工智能原理及其应用 学年:2014 -2015 学期1( /2□ 课程类别:专业必修( 限选□ 任选□ 实践□ 实验时间:201年月日 实验名称:搜索策略与实际问题求解 实验目的和要求 目的 1、理解和掌握解决实际问题的搜索算法或策略; 2、能够用选定的编程语言实现搜索算法; 要求 1、程序需要有必要的注释; 2、编程语言不限,可以采用面向对象的程序设计; 3、画出必要的流程图 4、实验内容任选之一 实验软硬件要求 网络计算机,C++编程环境 3 5 2 1 4 8 7 6 结果 1 2 3 8 4 7 6 5 数据结构: 本实验使用的数据结构是队列,应用队列先进先出的特点来实现对节点的保存和扩展。首先建立一个队列,将初始结点入队,并设置队列头和尾指,然后取出队列(头指针所指)的结点进行扩展,从它扩展出子结点,并将这些结点按扩展的顺序加入队列,然后判断扩展出的新结点与队列中的结点是否重复,如果重复则,否则记录其父结点,并将它加入队列,更新队列尾指针,然后判断扩展出的结点是否是目标结点,如果是则显示路径,程序结束。否则如果队列头的结点可以扩展,直接返回第二步。否则将队列头指针指向下一结点,再返回第二步,知道扩展出的结点是目标结点结束,并显示路径。 代码如下: #include stdio.h #include stdlib.h #include windows.h #include queue #include stack using namespace std; #define HashTableSize 362881 #define NOT ! #define UP 0 #define DOWN 1 #define LEFT 2 #define RIGHT 3 #define Bit char typedef struct maps { Bit detail[9]; int myindex; // 记录自己节点在hash表中的位置 Bit position; // 记录 空格(0)在序列中的位置 }Map,*PMap; Map org; // 初始状态 int EndIndex; //目标,上移 ,下移 , 左移 ,右移 int const derection[4] ={ -3 , 3 , -1 , 1 }; // 可移动的四个方向 int const Factorial[9] = {40320 , 5040 , 720 , 120 , 24 , 6 , 2 , 1 , 1 }; int HashTable[HashTableSize]={0}; //hash表,其中记录的是上一个父节点对应的位置 /****八数码的输入(在这里不做任何输入检查,均认为输入数据是正确的)***/ void input() { int i,j; int sum , count ,index; printf(输入九个数:\n); //必须输入一个0作为空值 for(i = 0;i 9;i ++ ) { scanf(%1d, org.detail[ i ] ); org.detail[ i ] || (org.position = i); } for(i = 0;i 9;i ++ ) //计算逆序 { if( 0 == org.detail[ i ] ) continue; for(j = 0; j i; j ++ ) sum += ( 0 != org.detail[ j ] org.detail[ j ] org.detail[ i ] ); } for( i = 0 , index = 0 ; i 9 ; i ++ ) // 计算初始状态的hash值 { for(j = 0 , count = 0 ; j i ; j ++) count += org.detail[ j ] org.detail[ i ]; index += Factorial[ org.detail[ i ] ] * count; } org.myi

文档评论(0)

1亿VIP精品文档

相关文档