![传教士野人过河问题-两种解法思路_第1页](http://file2.renrendoc.com/fileroot_temp3/2021-5/24/c85741d4-5b53-4956-bca7-b55d2506f1e9/c85741d4-5b53-4956-bca7-b55d2506f1e91.gif)
![传教士野人过河问题-两种解法思路_第2页](http://file2.renrendoc.com/fileroot_temp3/2021-5/24/c85741d4-5b53-4956-bca7-b55d2506f1e9/c85741d4-5b53-4956-bca7-b55d2506f1e92.gif)
![传教士野人过河问题-两种解法思路_第3页](http://file2.renrendoc.com/fileroot_temp3/2021-5/24/c85741d4-5b53-4956-bca7-b55d2506f1e9/c85741d4-5b53-4956-bca7-b55d2506f1e93.gif)
![传教士野人过河问题-两种解法思路_第4页](http://file2.renrendoc.com/fileroot_temp3/2021-5/24/c85741d4-5b53-4956-bca7-b55d2506f1e9/c85741d4-5b53-4956-bca7-b55d2506f1e94.gif)
![传教士野人过河问题-两种解法思路_第5页](http://file2.renrendoc.com/fileroot_temp3/2021-5/24/c85741d4-5b53-4956-bca7-b55d2506f1e9/c85741d4-5b53-4956-bca7-b55d2506f1e95.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、精品好资料学习推荐 14 / 13 实验 传教士野人过河问题 37030602 王世婷 一、实验问题 传教士和食人者问题(The Missionaries and Cannibals Problem)。在河的左岸有3 个传教士、1条船和3个食人者,传教士们想用这条船将所有的成员运过河去,但是受 到以下条件的限制:(1)传教士和食人者都会划船,但船一次最多只能装运两个;(2) 在任何岸边食人者数目都不得超过传教士,否则传教士就会遭遇危险:彼食人者攻击甚 至被吃掉。此外,假定食人者会服从任何一种过河安排,试规划出一个确保全部成员安 全过河的计划。 二、解答步骤 (1) 设置状态变量并确定值域 M为
2、传教士人数,C为野人人数,B为船数,要求MHCJ1M+C = 3, L表示左岸, R表示右岸。 (2) 确定状态组,分别列出初始状态集和目标状态集 用三元组來表示S:(ML , CL , BL)(均为左岸状态) 其中0ML3,0CL 1) (3, 0, 0) J f=2 Qoi 3, 1, 1) + f=4 Pzo n break end 辻node(j, 4)=1 %判断结点是否可扩展 if node (j, 3)=1 %船在左岸 if ( (node(j, 1)=0) I I (node(j, 1)=3) ) end if (node(j, 1)=1 end if (node (j, 1)
3、=1 end if (node (j, l)=0 node (j, 1)=3) end if (node(j, 1)=2 end elseif node (j, 3)=0%船在右岸 if ( (node(j, 1)=0) I (node(j, 1)=3) ) end if (node(j, 1)=2 end if (node (j, 1)=2 end if (node (j, l)=0 node(j, 1)=3) BoatWildNum=node (result (j), 2)-node (result (jT), 2); if node(result(j), 3)=1 fprintf(第%d
4、次:左岸到右岸,传教士过去d人,野人过去d人 n, StepNum, abs(BoatPriNum), abs(BoatWi1dNum); S t epNum= S t epNum*1; end if node(result(j), 3)=0 fprintf(*第%d次:右岸到左岸,传教士过去%d人,野人过去%d人 n, StepNum, abs(BoatPriNum), abs(BoatWi1dNum); StepNum=StepNum+1; end j 二 jT; end pause (0. 2); fprintf(,n); solveNum=solveNum+l; end end fpr
5、intfC问题结束); $从左岸到右岸,船上传教士 x个,野人y个 function =forward(z, x, y) global n; global node; node (n, l)=node (z, l)x; node(n, 2)=node(z, 2)-y; node(n,3)=0; r=search (z); 辻(r) return end node(z, 4)=0; node (n, 4)=1; node(n,5)=z; s=destination(); if s node (n, 4)=_1; end n=n+l; % 觥从右岸到左岸,船上传教士 x个,野人y个 functio
6、n =afterward(z, x, y) global n; global node; node (n, l)=node (z, l)+x; node(n,2)=node(z, 2)+y; node(n, 3)=1; r=search (z); 辻(r) return end node(z, 4)=0; node(n, 4)=1; node (n, 5)=z; s=destination(); if s node (n, 4)=T; end n=n+l; % function r=search(x) global n node; i=x; while node(i, 5)=1 if node
7、(i, 1) =node(n, 1) return end i=node(i, 5); end 弔跟初始节点比较 if node(i, l)=node(n, 1) return end r=l;%均不相同 % function s=destination。 global n node; if node (n, 1)=0 return end s=0; 2.运用启发式函数 % %野人和传教士过河问题 %date:2010/12/15 %author:wang shi ting function =guohe() clear all; close all; global n node open_l
8、ist index; n=2; result=zeros(100,1); node=zeros(100,5); node(l, :) = 3, 3,1, 1,-lJ ;%初始化 沁左岸传教士数2左岸野人数3船(1为左岸,0为右岸) $4是否可扩展(1为可扩展)5父节点号(-1表示无父节点,即为初始节点) index=l; open_list=l, 0. 01J :%节点号 启发函数值 while (1) Erow, 二size(open_list); if row=0 fprintf C all the nodes in open list have been expanded); retur
9、n end for il=l:row open_list(il, 2)=6 01-node(open_list(il, 1), l)-node(open_list(il, 1), 2);% 定义启发函数 if node(open_list (il, 1), 4)=1%如果该结点是目标结点,则打印结果 fprintf (*传教士野人过河问题n); J=l; k=open_list(il, 1); StepNum 二1; while (k=-l) result(j)=k; k=node(k,5); j二j+l; end fprintf(方法如下n); while jl BoatPriNum=nod
10、e(result(j), 1)node(result(jl),1); BoatWildNum=node (result (j), 2)-node (result (jT), 2); if node(result(j), 3)=1 fprintfC第d次:左岸到右岸,传教士过去d人,野人过去d人 n, StepNum, abs(BoatPriNum), abs(BoatWi1dNum); S t epNum= S t epNum*1; end if node(result(j), 3)=0 fprintfC第%d次:右岸到左岸,传教士过去%d人,野人过去%d人 n, StepNum, abs(B
11、oatPriNum), abs(BoatWi1dNum); S t epNum= S t epNum1; end end pause (0.2); fprintfC问题结束n); return end end r_row,=find(open_list(:, 2)=max(open_list (:,2); j=open_list(r_row(l, 1), 1); if node (j, 3)=1 %船在左岸 if ( (node(j, 1)=0)| (node (j, 1)=3) ) end if (node(j, 1)=1 end if (node (j, 1)=1 end if (node
12、 (j, l)=0 node (j, 1)=3) end if (node(j, 1)=2 end elseif node (j, 3)=0%船在右岸 if ( (node (j, 1)=0)| (node (j, 1)=3) ) end if (node(j, 1)=2 end if (node (j, 1)=2 end if (node (j, l)=0 node (j, 1)=3) end if (node (j, 1)=1 end end %display(open_list); open_list(r_row(l),:)=E ; index=indexl; %open 表个数减 1
13、%display (open_list); end % $从左岸到右岸,船上传教士 x个,野人y个 function L=forward(z, x, y) global n; global node open_list index; node (n, l)=node (z, l)x; node(n,2)=node(z, 2)-y; node (n, 3)=0; r=search (z); 辻(F return end node(z, 4)=0; node (n, 4)=1; node (n, 5)=z; s二destination (); if s node (n, 4)=-1; end in
14、dex=index+l; open_list(index, l)=n; n=n+l; % 眦从右岸到左岸,船上传教士 X个,野人y个 function =afterward(z, x, y) global n; global node open_list index; node (n, l)=node (z, l)+x; node(n,2)=node(z, 2)+y; node (n, 3)=1; r=search(z); 辻(F return end node(z, 4)=0; node (n, 4)=1; node(n, 5)=z; s=destination(); if s node (n, 4)=-1; end index=index+l; open_list(index, l)=n; n=n+l; % function r=sear
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 IEC 60764:1983 EN-FR Sound transmission using infra-red radiation
- 【正版授权】 IEC 60763-2:2007+AMD1:2023 CSV EN-FR Amendment 1 - Specification for laminated pressboard - Part 2: Methods of test
- 【正版授权】 IEC 60749-44:2016 EN-FR Semiconductor devices - Mechanical and climatic test methods - Part 44: Neutron beam irradiated single event effect (SEE) test method for semiconductor devices
- 【正版授权】 IEC 60749-11:2002 EN-FR Semiconductor devices - Mechanical and climatic test methods - Part 11: Rapid change of temperature - Two-fluid-bath method
- 【正版授权】 IEC 60747-5-5:2007/AMD1:2013 EN-FR Amendment 1 - Semiconductor devices - Discrete devices - Part 5-5: Optoelectronic devices - Photocouplers
- 【正版授权】 IEC 60747-16-2:2001 EN Semiconductor devices - Part 16-2: Microwave integrated circuits - Frequency prescalers
- 【正版授权】 IEC 60745-2-23:2012 EN-FR Hand-held motor-operated electric tools - Safety - Part 2-23: Particular requirements for die grinders and small rotary tools
- 【正版授权】 IEC 60730-2-17:1997/AMD1:2000 EN-FR Amendment 1 - Automatic electrical controls for household and similar use - Part 2: Particular requirements for electrically operated gas valves,i
- 【正版授权】 IEC 60728-7-3:2009 EN Cable networks for television signals,sound signals and interactive services - Part 7-3: Hybrid fibre coax outside plant status monitoring - Power supply to tra
- 【正版授权】 IEC 60702-1:2002/AMD1:2015 EN-FR Amendment 1 - Mineral insulated cables and their terminations with a rated voltage not exceeding 750 V - Part 1: Cables
- 天津市滨海新区2022-2023学年高二下学期期末检测英语试题(Word版无答案)
- 大型藏族原生态歌舞乐《藏谜》价值取向的开题报告
- 辽宁省沈阳市铁西区2023年五年级数学第二学期期末复习检测试题含解析
- 北京市西城区2022-2023学年五年级数学第二学期期末质量跟踪监视试题含解析
- 盐城幼儿师范高等专科学校辅导员考试题库
- 上海市大学生安全教育(2022级)学习通课后章节答案期末考试题库2023年
- 2023年海南省海口市美兰区六年级数学第二学期期末质量检测试题含解析
- 2023-2024学年广东省东莞市小学语文五年级期末通关试卷详细参考答案解析
- 2022北京西城高二(下)期末英语(教师版)
- 中医医术确有专长人员申请表格
- BS EN ISO 15848-1-2015 工业阀-逸散性排放的测量、试验和鉴定程序(中文)
评论
0/150
提交评论