资源简介

本文件包括源码,实验说明文档,实验总结PPT Have a happy experiment!

资源截图

代码片段和文件信息

#include
#include
#include
#include

#define NUM_CITY 76

#define NUM_Chromosome 5000

#define NUM_BIRD 30

using namespace std;

double city[NUM_CITY][4]={0};
/*double city[NUM_CITY][4]=
 {
 {5.2941.558}{4.2863.622}{4.7192.774}{4.1852.230}{0.9153.821}
 {4.7716.041}{1.5242.871}{3.4472.111}{3.7183.665}{2.6492.556}
 {4.3991.194}{4.6602.949}{1.2326.440}{5.0360.244}{2.7103.140}
 {1.0723.454}{5.8556.203}{0.1941.862}{1.7622.693}{2.6826.097}
 };
*/

/* double city[NUM_CITY][4] = { {0.4000 0.4439} {0.2439 0.1463} {0.1707 0.2293}
  {0.2293 0.7610} {0.5171 0.9414} {0.8732 0.6536}
  {0.6878 0.5219} {0.8488 0.3609} {0.6683 0.2536}
  {0.6195 0.2634}
  };
*/ 
/*double city[NUM_CITY][4]={
 {38.2420.42}{39.5726.15}{40.5625.32}{36.2623.12}{33.4810.54}
 {37.5612.19}{38.4213.11}{37.5220.44}{41.239.10}{41.1713.05}
 {36.08-5.21}{38.4715.13}{38.1515.35}{37.5115.17}{35.4914.32}
 {39.3619.56}{38.0924.36}{36.0923.00}{40.4413.57}{40.3314.15}
 {40.3714.23} {37.5722.56}
};
*/

void read_file(char a[15])
{
//int i=0;
//char b[15];
//while(a[i]!=‘\0‘)
//{
// b[i]=a[i];
// i++;
//}

FILE *f_read;
cout< f_read=fopen(a“r“);
if(f_read==NULL)
cout<<“can not open“< else
cout<<“can open“< //int a=0;
int pt=0;

while(pt {


unsigned char ch;
int a1[8]={0};
int a2[8]={0};
int i=0j=0k=0;

for(i=0;;)
{
ch=fgetc(f_read);

if(ch==‘\n‘)
break;
while(ch==‘ ‘)
{
ch=fgetc(f_read);
if (ch!=‘ ‘)
i++;
}
if(int(ch)>47&&int(ch)<58)
{
if(i==1)
{
a1[j]=int(ch)-48;
j++;
}
if(i==2)
{
a2[k]=int(ch)-48;
//cout<<“a2[“< k++;
}
}
}

for(i=0;i city[pt][0]+=a1[i]*pow(10.0j-i-1);

for(i=0;i city[pt][1]+=a2[i]*pow(10.0k-i-1);
pt++;
//cout< }
}


double distance (double x1 double y1 double x2 double y2)
{
  return (sqrt ((x1 - x2) * (x1 - x2) + (y2 - y1) * (y2 - y1)));
}

struct city
{
double x[NUM_CITY];
double y[NUM_CITY];
double num[NUM_CITY];
//int flag;
};

struct city_pso
{
int num[NUM_CITY];
//int flag;
};


void GA()
{
FILE *f;
f=fopen(“a1.txt““w“);
if(f==NULL)
cout<<“can not open“< else
cout<<“can open“< int i=0j=0k=0a=0;

for(int i=0;i city[i][2]=i+1;
for(int i=0;i city[i][3]=0;


struct city *city_rand;
struct city *city_rand1;

city_rand =(struct city *)malloc(2*NUM_CITY*NUM_Chromosome*3*sizeof(double));//2*NUM_CITY*NUM_Chromosome*3);
city_rand1=(struct city *)malloc(NUM_CITY*NUM_Chromosome*3*sizeof(double));//NUM_CITY*NUM_Chromosome*3);

for(i=0;i

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      13780  2010-06-13 11:06  代码\GA.cpp

     文件      16622  2010-06-13 11:08  代码\PSO.cpp

     文件       9789  2010-06-13 11:10  代码\SAA.cpp

     文件     452608  2010-06-07 20:54  粒子群优化算法(PSO).ppt

     文件      85342  2010-06-13 12:58  实验说明.pdf

     文件       3537  2010-05-29 12:59  数据集\a280.tsp

     文件        656  2010-05-26 15:11  数据集\att48.tsp

     文件       7791  2010-05-31 10:54  数据集\att532.tsp

     文件        742  2010-05-30 23:32  数据集\eil76.tsp

     文件      15613  2010-05-26 15:27  数据集\pr1002.tsp

     文件        680  2010-05-26 15:09  数据集\st70.tsp

     目录          0  2010-06-13 12:31  代码

     目录          0  2010-06-13 11:01  数据集

----------- ---------  ---------- -----  ----

               607160                    13


评论

共有 条评论