问题为:30城市TSP问题(d*=423.741 by D B Fogel)TSP Benchmark 问题
城市坐标:
41 94;37 84;54 67;25 62;7 64;2 99;68 58;71 44;5462;83 69;64 60;18 54;2260;83 46;91 38;25 38;2442;58 69;71 71;74 78;8776;18 40;13 40;82 7;62 32;58 35;45 21;41 26;44 35;4 50
程序为:
采用轮盘赌选择、基于位置交叉PBX、两点互换变异
#include<iostream>
#include<ctime>
#include<cstdlib>
#include<cmath>
#include<cstdio>
using namespace std;
const int M=100,T=500,N=30;//种群大小和迭代次数和城市个数
const double pc=0.6,pm=0.05;//交叉率、变异率
int condition[30][2]={
{41,94},{37,84},{54,67},{25,62},{7,64},{2,99},{68,58},{71,44},{54,62},{83,69},
{64,60},{18,54},{22,60},{83,46},{91,38},{25,38},{24,42},{58,69},{71,71},{74,78},
{87,76},{18,40},{13,40},{82,7},{62,32},{58,35},{45,21},{41,26},{44,35},{4,50}
};//30个城市的坐标
struct chromo//构造染色体
{
int code[N];
double fit;
double sumfit;
}