罗马尼亚度假问题详解.docVIP

  • 63
  • 0
  • 约1.15万字
  • 约 15页
  • 2016-08-31 发布于湖北
  • 举报
二、详细代码 测试类: /**Main类,打印各个算法的结果 * @author dyl * */ classMain{ int?result; int?xiabiao[]=null;//访问的下标 publicstaticvoid?main(String[]?args){ Graph?graph=newGraph(); System.out.println(----------------罗马尼亚问题---------------); System.out.println(1、深度优先搜索); DFS dfs=new?DFS(); dfs.DF_Search(graph,0,12); System.out.println(2、迭代加深的搜索); IDS ids=new?IDS(); ids.IDS_Search(graph,0,12,15);//深度设15 System.out.println(3、一致代价搜索); UCS ucs=new?UCS(graph,0,12); System.out.println(4、A*搜索); AXing?aXing=newAXing(); aXing.A_Search(graph,?graph.H,0,15);//0-15即Arad到达Hirsova } /**打印 * @param g:图 * @param stack:栈 */ publicvoid?show(Graph?g,Stack?stack){ if(stack.size()==0){ System.out.println(路径搜索失败); return; } result=0; System.out.print(访问的下标: ); for(int?i?=0;?i??stack.size();?i++){ System.out.print(--+stack.get(i)); } System.out.print(\n访问过程: ); xiabiao=newint[stack.size()]; if(stack.isEmpty()){ System.out.println(搜索失败); }else{ for(int?i?=0;?i??stack.size();?i++){ System.out.print(--+g.cities[(Integer)?stack.get(i)]); } for(int?i?=0;?i??stack.size()-1;?i++){ result+=g.path[(Integer)?stack.get(i)][(Integer)?stack.get(i+1)]; } System.out.println(\n总长度为:+result+\n); g.markInit();//清空访问 } } } /**图类 * @author dyl * */ publicclassGraph{ publicint?path[][]=newint[][]{{0,75,10000,118,140,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}, {75,0,71,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}, {10000,71,0,10000,151,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}, {118,10000,10000,0,10000,111,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}, {140,10000,151,10000,0,10000,80,99,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}, {10000,10000,10000,111,10000,0,10000,10000,70,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000,10000}, {10000,10000,10000,10000,80,10000,0,10000,10000,10000,146,97,10000,100

文档评论(0)

1亿VIP精品文档

相关文档