可以运行,有详细步骤说明
initmap();
m_dLength=10e9; //初始化蚁群能走过的最大长度
ifstream in("eil51.tsp");
struct city
{
int num;
int x;
int y;
}cc[iCityCount]; //定义一个结构体变量的城市数组
for (int i=0;i<iCityCount;i++)
{
in>>cc[i].num>>cc[i].x>>cc[i].y;
besttour[i]=0; //走过路径的城市号初始化为0
}
int j;
for(int i=0;i<iCityCount;i++)
for (j=0;j<iCityCount;j++)
{
{
Map.distance[i][j]=sqrt(pow((double)(cc[i].x-cc[j].x),2)+pow((double)(cc[i].y-cc[j].y),2)); }
}
}
void project::GetAnt()
{
//randomly put ant into map
int i=0;
int city;
srand( (unsigned)time( NULL ) +rand());
for (i=0;i<iAntCount;i++)
{
city=rnd(iCityCount);
ants[i].addcity(city);
}
}
void project::StartSearch()
{
//begin to find best solution
int max=0;//every ant tours times