免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/basic ant colony algorithm for tsp #include #include #include #include #include #include #include #define n 31 /city size #define m 31 /ant number double inittao=1; double taonn; double detataonn; double distancenn; double yitann; int tabumn; int routemn; double solutionm; int bestrouten; double bestsolution=10000000000; double alfa,beta,rou,q; int ncmax; void initparameter(void); / initialize the parameters of basic aca double evaluesolution(int *a); / evaluate the solution of tsp, and calculate the length of path void incityxy( double x, double y, char *infile ); / input the nodes coordinates of tsp void initparameter(void) alfa=1; beta=5; rou=0.9; q=100; ncmax=200; void main(void) int nc=0; initparameter(); double xn; double yn; incityxy( x, y, city31.tsp ); for(int i=0;in;i+) for(int j=i+1;jn;j+) distanceji=sqrt(xi-xj)*(xi-xj)+(yi-yj)*(yi-yj); distanceij=distanceji; / calculate the heuristic parameters for(i=0;in;i+) for(int j=0;jn;j+) taoij=inittao; if(j!=i) yitaij=100/distanceij; for(int k=0;km;k+) for(i=0;in;i+) routeki=-1; srand(time(null); for(k=0;km;k+) routek0=k%n; tabukroutek0=1; /each ant try to find the optiamal path do int s=1; double partsum; double pper; double drand; /ant choose one whole path while(sn) for(k=0;km;k+) int jrand=rand()%3000; drand=jrand/3001.; partsum=0; pper=0; for(int j=0;jn;j+) if(tabukj=0) partsum+=pow(taorouteks-1j,alfa)*pow(yitarouteks-1j,beta); for(j=0;jdrand) break; tabukj=1; routeks=j; s+; / the pheromone is updated for(i=0;in;i+) for(int j=0;jn;j+) detataoij=0; for(k=0;km;k+) solutionk=evaluesolution(routek); if(solutionkbestsolution) bestsolution=solutionk; for(s=0;sn;s+) bestroutes=routeks; for(k=0;km;k+) for(s=0;sn-1;s+) detataorouteksrouteks+1+=q/solutionk; detataoroutekn-1routek0+=q/solutionk; for(i=0;in;i+) for(int j=0;jn;j+) taoij=rou*taoij+detataoij; if(taoij20) taoij=20; for(k=0;km;k+) for(int j=1;jn;j+) tabukroutekj=0; routekj=-1; nc+; while(ncncmax); /output the calculating results fstream result; result.open(optimal_results.log, ios:app); if(!result) coutcant open the file!n; exit(0); result*-*endl; resultthe initialized parameters of aca are as follows:endl; resultalfa=alfa, beta=beta, rou=rou, q=qendl; resultthe maximum iteration number of aca is:ncmaxendl; resultthe shortest length of the path is:bestsolutionendl; resultthe best route is:endl; for(i=0;in;i+) resultbestroutei ; resultendl; result*-*endlendl; result.close(); coutthe shortest length of the path is:bestsolutionendl; double evaluesolution(int *a) double dist=0; for(int i=0;in-1;i+) dist+=distanceaiai+1; dist+=distanceaia0; return dist; void incityxy( double x, double y, char *infile ) fstream inxyfile( infile, ios:in | ios:nocreate ); if( !inxyfile ) coutcant open the infile file!n; exit(0); int
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026中国游戏研发行业市场竞争现状技术需求分析投资前景规划研究报告
- 2026圣赫勒拿岛通信设备制造业供需格局解析及应用投资评估规划汇刊
- 2026中国智能家居设备行业市场供需形势分析及投资价值评估规划文献
- 2026Fast芯片组行业经销商网络与渠道管理优化报告
- 2026中国工业视觉检测软件算法精度提升与行业渗透率报告
- 2026汽车服务业汽车后市场服务创新模式研究
- 2026汽车轮胎制造行业市场现状供需分析及投资评估规划分析研究报告
- 2026汽车维修保养市场服务类型评估及其汽车电商模式与实体经济竞争分析报告
- 2026人工智能产业链市场深度研究及投资策略与市场前景研究报告
- 2026人工智能芯片工业核心数据供给分析及市场盈利定律规划研究报告
- 词语题型归类-高考语文复习二轮热点题型专项训练(新高考版)
- 新老师做课件的步骤
- 牛蛙饲料配方培训课件
- 宿管员安全管理培训课件
- 2025年春季高考复习必背英语考纲词汇单词
- 小公司财务报销制度及报销流程
- 2024年女性私护品市场调查报告
- 产线物料员培训课件
- 创业过程中的法律风险防范
- 银行司法扣划培训课件
- 劳动保护知识培训课件
评论
0/150
提交评论