資源簡介
采用C++語言編寫,用蟻群算法解決旅行商問題

代碼片段和文件信息
#include
#include
#include
#include?“a.h“
void?main()
{?
??int?ij;
??srand((unsigned)time(?NULL?));
??network();?????????????????????????????//?generate?a?random?network
??
a:printf(“Set?the?source?node:“);????????//?set?source?node?and?destation?node?
??scanf(“%d“&sour_n);
??printf(“\n“);
??printf(“Set?the?destation?node:“);
??scanf(“%d“&dest_n);
??printf(“\n“);
??if(sour_n>=n||dest_n>=n||sour_n==dest_n)
?{printf(“Input?error!\nInput?again?please:\n“);
??????goto?a;
?}
??
??if(dv[dest_n]>Jw)???????????????????????//??pass?over?the?problem?of?delay?jitter??
?????{printf(“system?error!/n“);
??return;
?????}
??
??for(i=1;ink?whose?bandwidth?is?not?enough?
??for(j=1;j ?????????if(bw[i][j] {link[i][j]=0;
?????????????cost[i][j]=0;
?????????????ldl[i][j]=0;
?????????????bw[i][j]=0;
}
???for(i=1;i ??for(j=1;j ?????????if(link[i][j]==1)
????????????phero[i][j]=constant;
?????????else??phero[i][j]=0;
???printf(“The?initialization??of?pheromone?are:\n“);
???for(i=1;i {for(j=1;j ?????printf(“%-7.4f??“phero[i][j]);
?????printf(“\n“);
}
???
???rout();
}
void?network()??????????????//?randomly?generate?a?network
{int?ijm;
?n=rand()%(N-5)+7;??????????//?set?the?number?of?node?range?from??6?to?N
?printf(“The?number?of?nodes?is%4d\n“n-1);
?for(i=1;i {ndl[i]=rand()%2+1;????//the?delay?of?nodes?range?from?1?to?2
?????dv[i]=rand()%4;???????//the?delay?variration?of?nodes?range?from?0?to?3
?????m=rand()%3+6;??????????
?????lr[i]=exp(m);?????????//the?loss?rate?of?nodes?range?from?1e-6?to?1e-8
? }
?printf(“The?delay?of?nodes?are:\n“);
?for(i=1;i ?printf(“%4d“ndl[i]);
?printf(“\n“);
?printf(“The?delay?variration?of?nodes?are:\n“);
?for(i=1;i ?printf(“%4d“dv[i]);
?printf(“\n“);?
?printf(“The?loss?rate?of?nodes?are:\n“);
?for(i=1;i ?printf(“%7.6f??“lr[i]);
?printf(“\n“);
?
?for(i=1;i ?for(j=i;j ?????????if(i!=j)?
{link[i][j]=rand()%2;
?????cost[i][j]=(rand()%2+1)*link[i][j];???//the?cost?of?links?range?from?1?to?2
?bw[i][j]=(rand()%8+8)*10*link[i][j];??//the?bandwidth?of?links?range?from?80?to?150
?????????????ldl[i][j]=(rand()%3+1)*link[i][j];????//the?delay?of?links?range?from?1?to?3
}
?????????else?link[i][j]=0;
?for(i=1;i ?for(j=1;j {link[i][j]=link[j][i];
?????????cost[i][j]=cost[j][i];
?bw[i][j]=bw[j][i];
?ldl[i][j]=ldl[j][i];
}
?printf(“\nThe?links?of?network?are:\n“);
?for(i=1;i {for(j=1;j ????????printf(“%6d“link[i][j]);
????printf(“\n“);
}
?printf(“\nThe?cost?of?links?are:\n“);
?for(i=1;i {for(j=1;j ????????printf(“%6d“cost[i][j]);
?printf(“\n“);
}
?printf(“\nThe?bandwidth?of?links?are:\n“);
?for(i=1;i {for(j=1;j ????????print
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????1039??2004-05-19?08:40??蟻群并行\并行\a.h
?????文件???????3365??2004-05-19?08:28??蟻群并行\并行\ant.dsp
?????文件????????529??2004-05-19?08:33??蟻群并行\并行\ant.dsw
?????文件??????50176??2011-04-08?22:38??蟻群并行\并行\ant.ncb
?????文件????????731??2011-04-08?22:37??蟻群并行\并行\ant.plg
?????文件???????4315??2004-05-16?15:00??蟻群并行\并行\ant4.dsp
?????文件????????531??2004-05-16?14:22??蟻群并行\并行\ant4.dsw
?????文件??????41984??2011-04-08?23:12??蟻群并行\并行\ant4.ncb
?????文件??????33792??2011-04-08?23:03??蟻群并行\并行\Debug\vc60.idb
?????文件??????45056??2011-04-08?22:37??蟻群并行\并行\Debug\vc60.pdb
?????文件?????225392??2011-04-08?22:37??蟻群并行\并行\Debug\ant.pch
?????文件??????22627??2011-04-08?22:37??蟻群并行\并行\Debug\ant.obj
?????文件?????221500??2011-04-08?22:37??蟻群并行\并行\Debug\ant.ilk
?????文件?????221273??2011-04-08?22:37??蟻群并行\并行\Debug\ant.exe
?????文件?????418816??2011-04-08?22:37??蟻群并行\并行\Debug\ant.pdb
?????文件?????221664??2011-04-08?23:03??蟻群并行\并行\Debug\ant4.ilk
?????文件?????221274??2011-04-08?23:03??蟻群并行\并行\Debug\ant4.exe
?????文件?????418816??2011-04-08?23:03??蟻群并行\并行\Debug\ant4.pdb
?????文件??????48640??2011-04-08?22:38??蟻群并行\并行\ant.opt
?????文件????????878??2011-04-08?23:03??蟻群并行\并行\ant4.plg
?????文件???????6504??2011-04-08?23:11??蟻群并行\并行\ant.cpp
?????文件??????48640??2011-04-08?23:12??蟻群并行\并行\ant4.opt
?????目錄??????????0??2011-04-08?22:36??蟻群并行\并行\Debug
?????目錄??????????0??2005-05-17?10:19??蟻群并行\并行
?????目錄??????????0??2011-04-08?22:31??蟻群并行
-----------?---------??----------?-----??----
??????????????2257542????????????????????25
- 上一篇:C++判斷點是否在多邊形內
- 下一篇:閾值分割和區域生長vc++代碼
評論
共有 條評論