免费预览已结束,剩余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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025广东深圳市优才人力资源有限公司(派至龙岗区某国企 )工作人员招聘1人笔试考试备考题库及答案解析
- 2025年梅州市大埔县辅警招聘考试题库附答案解析
- 2025初级会计实务分录类试题及答案
- 2025年环保工程师考试真题及答案解析
- 2025年会计从业资格考试初级会计实务专项训练试卷
- 2025年山西吕梁市孝义市保安员招聘考试题库附答案解析
- 糖尿病足溃疡VSD治疗多药耐药菌感染方案
- 2025年辽宁省沈阳市沈河区辅警招聘考试题库附答案解析
- 跨境支付便捷性研究-洞察与解读
- 冷热钱包使用偏好-洞察与解读
- 2025年春季高考复习必背英语考纲词汇单词
- 《智慧斑马线 高分子复合材料LED发光地砖》
- 房屋修缮加固工程施工组织设计方案
- 2025年中国邮政集团湖北分公司招聘笔试参考题库含答案解析
- 2025年度豪华酒吧独家艺人合作协议范本3篇
- 高清视频会议系统售后服务及培训计划
- 报关代理协议
- 湖北理工学院《数字逻辑》2022-2023学年期末试卷
- 《毕业生登记表》模板
- (正式版)JBT 3300-2024 平衡重式叉车 整机试验方法
- 石大中油调查报告样本
评论
0/150
提交评论