跪求tsp问题的蚁群算法,要vc++写的
来源:百度知道 编辑:UC知道 时间:2024/09/23 07:07:51
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <cassert>
using namespace std;
const int DIMENSION=535;//城市个数
const int PERSONS=1000;//种群个数
const int crosspob=0.75;//决定是否交叉的概率
const double mute=0.03;//变异概率
const int iternum=100000;//计划迭代次数
ofstream out("res100000.txt");
int nmutations;
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
struct chrom
{
unsigned int gene[DIMENSION-1];//固定第一个城市
int fitness;//该路径的长度
};//表征每个染色体特征
struct Population
{
struct chrom person[PERSONS];//有这么多个染色体
double fitsum;//适应值之和
int minfit; //最小适应度的下标
};//种群的一些属性
//function declare here*********************************
int select(Population* p);
bool Flip(float prob);
void