人工鱼群 求解tsp 14城
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-07-25 10:42 14
目录 0 2014-08-12 11:16 14Debug
文件 56832 2014-08-12 11:16 14Debug estbook.exe
文件 422916 2014-08-12 11:16 14Debug estbook.ilk
文件 715776 2014-08-12 11:16 14Debug estbook.pdb
目录 0 2014-08-12 11:16 14 estbook
文件 2567168 2014-08-12 11:16 14 estbook.ncb
文件 890 2014-05-26 10:20 14 estbook.sln
文件 66560 2014-08-12 11:16 14 estbook.suo
文件 5222 2014-08-12 10:21 14 estbookAF.h
目录 0 2014-08-12 11:16 14 estbookDebug
文件 7372 2014-08-12 11:16 14 estbookDebugBuildLog.htm
文件 73713 2014-08-12 11:16 14 estbookDebugmain.obj
文件 69 2014-08-12 11:16 14 estbookDebugmt.dep
文件 663 2014-07-17 21:46 14 estbookDebug estbook.exe.embed.manifest
文件 728 2014-07-17 21:46 14 estbookDebug estbook.exe.embed.manifest.res
文件 621 2014-08-12 11:16 14 estbookDebug estbook.exe.intermediate.manifest
文件 158720 2014-08-12 11:16 14 estbookDebugvc90.idb
文件 233472 2014-08-12 11:16 14 estbookDebugvc90.pdb
文件 238 2014-07-13 09:35 14 estbookeil14.tsp
文件 497 2006-05-11 12:48 14 estbookeil51.tsp
文件 2902 2014-08-12 11:16 14 estbookmain.cpp
文件 4177 2014-08-12 11:16 14 estbook estbook.vcproj
文件 1411 2014-07-04 00:34 14 estbook estbook.vcproj.DELL-PC.DELL.user
文件 1403 2014-08-12 11:16 14 estbook estbook.vcproj.ZJX.Administrator.user
#include
#include “time.h“
#include “math.h“
#include “AF.h“
//#include “MMAS.h“
#include
#include
#include //内存泄露检测
using namespace std;
#define ITER_NUM 50 //最多迭代次数
#define NAN 100
#define CITY_NUMBER 14
double edge[CITY_NUMBER][CITY_NUMBER];
extern double g_Trial[CITY_NUMBER][CITY_NUMBER]; //两两城市间信息素
int g_bestway[CITY_NUMBER];
double g_bestvalue;
struct city
{
int num;
float x;
float y;
};
city city_position[CITY_NUMBER];
void read_data()
{
ifstream in(“eil14.tsp“);
for (int i=0;i {
in>>city_position[i].num>>city_position[i].x>>city_position[i].y;
}
}
void claculate_edge()
{
for (int i=0;i {
for (int j=0;j {
if(i==j) edge[i][j]=NAN;
else
{
edge[i][j]=sqrt((double)(city_position[i].x-city_position[j].x)*(city_position[i].x-city_position[j].x)+(double)(city_position[i].y-city_position[j].y)*(city_position[i].y-city_position[j].y));
}
}
}
}
int main(){
//读取城市坐标信息
read_data();
//计算任意两点之间距离
claculate_edge();
//fish F[FISH_NUMBER];
Artificial_fish AF;
//生成随机数组并将随机数组赋值给鱼群对象
for (int i=0;i {
for (int j=0;j {
AF.F[i].road[j]=city_position[j].num-1; //num是否要减一?按不减算
}
}
static int tt=(unsigned)time(NULL);
srand((unsigned)time(NULL)+tt++); //随机数生成种子
for (int l=0;l {
for (int n=1;n {
int a;
int randnum=rand()%(CITY_NUMBER-1)+1;
a=AF.F[l].road[n];
AF.F[l].road[n]=AF.F[l].road[randnum];
AF.F[l].road[randnum]=a;
}
cout<<“鱼编号:“< for (int j=0;j {
cout< if (j!=CITY_NUMBER-1) cout<<“->“;
}
cout< AF.F[l].evaluate(AF.F[l]);
cout<<“适应度估计值为:“< }
//开始迭代、路径寻优
for (int iter=0;iter {
for(int m=0;m {
//评估人工鱼的状态,分别进行...操作
int ans_follow = AF.follow(AF.F[m]AF.Fm); //追尾、成功返回0
if (ans_follow)
{
int ans_prey =AF.prey(AF.F[m]AF.Fm); //成功返回0
if (ans_prey)
{
int ans_swarm=AF.swarm(AF.F[m]AF.Fm); //聚群、成功返回0
}
}
if (AF.F[m].fitness AF.updatabullet(AF.F[m]);//如果小于公告板,更新信息
}
cout<<“第“< }
g_bestvalue=AF.bulletin;
cout<<“最优路径:“< for (int i=0;i<14;i++) //最优路径存取
{
g_bestway[i]=AF.best_road[i]+1;
cout< }
cout<
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-07-25 10:42 14
目录 0 2014-08-12 11:16 14Debug
文件 56832 2014-08-12 11:16 14Debug estbook.exe
文件 422916 2014-08-12 11:16 14Debug estbook.ilk
文件 715776 2014-08-12 11:16 14Debug estbook.pdb
目录 0 2014-08-12 11:16 14 estbook
文件 2567168 2014-08-12 11:16 14 estbook.ncb
文件 890 2014-05-26 10:20 14 estbook.sln
文件 66560 2014-08-12 11:16 14 estbook.suo
文件 5222 2014-08-12 10:21 14 estbookAF.h
目录 0 2014-08-12 11:16 14 estbookDebug
文件 7372 2014-08-12 11:16 14 estbookDebugBuildLog.htm
文件 73713 2014-08-12 11:16 14 estbookDebugmain.obj
文件 69 2014-08-12 11:16 14 estbookDebugmt.dep
文件 663 2014-07-17 21:46 14 estbookDebug estbook.exe.em
文件 728 2014-07-17 21:46 14 estbookDebug estbook.exe.em
文件 621 2014-08-12 11:16 14 estbookDebug estbook.exe.intermediate.manifest
文件 158720 2014-08-12 11:16 14 estbookDebugvc90.idb
文件 233472 2014-08-12 11:16 14 estbookDebugvc90.pdb
文件 238 2014-07-13 09:35 14 estbookeil14.tsp
文件 497 2006-05-11 12:48 14 estbookeil51.tsp
文件 2902 2014-08-12 11:16 14 estbookmain.cpp
文件 4177 2014-08-12 11:16 14 estbook estbook.vcproj
文件 1411 2014-07-04 00:34 14 estbook estbook.vcproj.DELL-PC.DELL.user
文件 1403 2014-08-12 11:16 14 estbook estbook.vcproj.ZJX.Administrator.user
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)