资源简介
遗传算法求解CHN144城市的TSP 问题

代码片段和文件信息
#include
#include
#include
#include “math.h“
#include
#include
#include
int randomi(int a int b);
double randomf(double a double b);
int randomi(int a int b)
{
int c=rand()%(b-a+1)+a;
return c;
}
double randomf(double a double b)
{
double c = (double)(rand()%((int)b-(int)a)) + a + (double)(rand()/(RAND_MAX + 1.0));
return c;
}
class TSP_GA
{
public:
TSP_GA();
void generate();
void calculate();
bool accept();
void TSP_SA();
void onechain();
void twochain();
void threechain();
void firstgeneration();
void nextgeneration();
void crossone();
void crosstwo();
void TSP_GAA();
bool noIN(int aint b[]int iint c);
void test();
protected:
private:
int r;
double d[144][144];
int point[144][2];
int p[144];
int c1;
int c2;
int c3;
double distance;
double df;
bool change;
int s;
int L;
int n;
double t;
double dt;
bool acc;
int pcurrent[100][144];
int pnext[200][144];
double distcurrent[100];
double distnext[200];
int nextnum;
int currentnum;
};
TSP_GA::TSP_GA()
{
int ij;
FILE * fp;
if((fp=fopen(“CHN144.TXT““r“))==NULL)
return;
fscanf(fp“%d“&n);
for (i=0;i<144;i++)
{
for (j=0;j<2;j++)
{
fscanf(fp“%d“&point[i][j]);
}
}
fclose(fp);
for (i=0;i<144;i++)
{
for (j=0;j<144;j++)
{
d[i][j]=sqrt((point[i][0]-point[j][0])*(point[i][0]-point[j][0])+(point[i][1]-point[j][1])*(point[i][1]-point[j][1]));
// cout< }
// cout< }
for (i=0;i {
p[i]=i;
}
distance=0;
for (i=0;i {
j=i+1;
distance+=d[i][j];
}
distance +=d[n-1][0];
change=false;
df=0;
s=1;
L=2000;
t=500;
dt=0.9;
c1=0;
c2=0;
r=0;
currentnum=50;
}
void TSP_GA::firstgeneration()
{
int ij;
// cout< for (i=0;i {
TSP_SA();
// cout< distcurrent[i]=distance;
for (j=0;j {
pcurrent[i][j]=p[j];
}
}
}
void TSP_GA::nextgeneration()
{
int i;
int jk;
nextnum=0;
crossone();
// crosstwo();
for (i=0;i {
for (j=0;j {
if (distnext[i] {
distcurrent[j]=distnext[i];
for (k=0;k {
pcurrent[j][k]=pnext[i][k
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2184 2011-07-03 08:44 遗传算法求解TSP\CHN143.TXT
文件 1710 2011-06-10 18:13 遗传算法求解TSP\CHN144.TXT
文件 9608 2011-07-01 08:26 遗传算法求解TSP\GA.cpp
文件 49664 2011-07-20 09:42 遗传算法求解TSP\报告.doc
目录 0 2011-11-02 11:21 遗传算法求解TSP
----------- --------- ---------- ----- ----
63166 5
- 上一篇:Agilent33250ALabview驱动
- 下一篇:文件加密解密系统
相关资源
- 连续hopfield神经网络解决TSP问题
- QGA 量子遗传算法
- 基于遗传算法的排课系统
- 遗传算法的M文件
- 遗传算法PPT(Genetic_Algorithms.ppt)
- 用8位spi实现16位spi
- 遗传算法的堆石料非线性本构模型参
- TSP问题城市数据及最优解
- onvif协议视频转码推流网页播放
- 流媒体相关协议标准RTP/RTSP/RTCP PDF文档
- 遗传算法越野小车unity5.5
- 车间布局遗传算法
- Hopfield神经网络解决 TSP问题
- 遗传算法论文11篇
- 基于遗传算法的立体车库车位调度研
- H264实时编码RTSP直播
- 三种解决TSP问题的近似算法的实现
- TSP城市问题145个城市数据及其相应的
- 遗传算法解决TSP旅行商问题程序开源
- 基于GA-ELM的瓦斯涌出量预测
- 将rtsp转码为flv格式用于h5播放前端使
- 5种多旅行商问题(MTSP)的遗传算法
- 人工智能和遗传算法的结合推荐必读
- 遗传算法0-1背包问题论文
- 改进的k_均值聚类排挤小生境遗传算法
- rtsp-h264.zip
- 免疫算法求解TSP问题详解
- websocket-rtsp-proxy-test.zip
- 基于遗传优化的无刷直流电机模糊控
- TSP问题测试数据集
评论
共有 条评论