蟻群演算法 C語言程式(已執行)

2021-04-24 00:09:22 字數 1049 閱讀 3020

//

段海濱教授主編的《蟻群演算法原理及其應用》附錄裡的

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 tao[n][n];

double detatao[n][n];

double distance[n][n];

double yita[n][n];

int tabu[m][n];

int route[m][n];

double solution[m];

int bestroute[n];

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)

int i=0;

while( !inxyfile.eof() ) }

另外:你需要建立乙個名為city31.tsp的檔案,存放31個城市的座標。

C 中蟻群優化演算法的實現

include include include define frand double rand double rand max define maxlong 2147483647 double pso optimization int s,int p,int d,int t,double c1,d...

蟻群演算法求解TSP問題的matlab程式

蟻群演算法求解tsp問題的matlab程式 clear all close all clc 初始化蟻群 m 31 蟻群中螞蟻的數量,當m接近或等於城市個數n時,本演算法可以在最少的迭代次數內找到最優解 c 1304 2312 3639 1315 4177 2244 3712 1399 3488 15...

用C 實現蟻群演算法解決TSP問題

using system using system.collections.generic using system.text namespace antsystem 初始化資訊素矩陣 for int i 0 i temp i 改變資訊素矩陣,closed list為較好的路徑 private vo...