2022年2022年基本蚁群算法代码C .pdf
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2022年2022年基本蚁群算法代码C .pdf》由会员分享,可在线阅读,更多相关《2022年2022年基本蚁群算法代码C .pdf(6页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、基本蚁群算法代码C 版/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;/启发函数,其值yitaij=1/distanceij int
2、tabuMN;/禁忌表,tabuij=1表示蚂蚁 i 已经走过了j 城市?int routeMN;/保存蚂蚁 k 的路径的数组为routekN double solutionM;int BestRouteN;double BestSolution=10000000000;double alfa,beta,rou,Q;/Pijk(t)表示 t 时刻蚂蚁k 由城市 i 转移到城市j 的状态转移概率,/alfa 是信息启发式因子,表示轨迹的相对重要性,反映蚂蚁在运动过程中所积累的信息在蚂蚁运动时所起的作用,其值越大,则该蚂蚁越倾向于选择其他蚂蚁经过的路径,蚂蚁之间的协作性越强/beta 是期望启发式
3、因子,表示能见度的相对重要性,反映在运动过程中启发信息在蚂蚁选择路径中的受重视程度,其值越大,则该状态转移概率越接近于贪心规则/rou 是信息残留因子(与书上不同,书上用rou 表示信息挥发系数,而用1-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 len
4、gth 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)名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 6 页 -int NC=0;initparameter();double xN;double yN;InCityXY(x,y,city31.tsp);/初始化距离矩阵for(int
5、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;/the dividend should be 1 here yitaij=1/distanceij;for(int k=0;kM;k+)for(i=0;iN;i
6、+)routeki=-1;srand(time(NULL);for(k=0;kM;k+)routek0=k%N;/设置初始城市tabukroutek0=1;/设置初始城市被访问标记/each ant try to find the optimal path do int s=1;double partsum;double pper;double drand;/ant choose one whole path while(sN)/开始计算第k 只蚂蚁的路径for(k=0;kM;k+)名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 6 页 -int jrand=rand()%300
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022年2022年基本蚁群算法代码C 2022 基本 算法 代码
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内