资源简介
人工鱼群 求解tsp 14城

代码片段和文件信息
#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 14\Debug\
文件 56832 2014-08-12 11:16 14\Debug\testbook.exe
文件 422916 2014-08-12 11:16 14\Debug\testbook.ilk
文件 715776 2014-08-12 11:16 14\Debug\testbook.pdb
目录 0 2014-08-12 11:16 14\testbook\
文件 2567168 2014-08-12 11:16 14\testbook.ncb
文件 890 2014-05-26 10:20 14\testbook.sln
文件 66560 2014-08-12 11:16 14\testbook.suo
文件 5222 2014-08-12 10:21 14\testbook\AF.h
目录 0 2014-08-12 11:16 14\testbook\Debug\
文件 7372 2014-08-12 11:16 14\testbook\Debug\BuildLog.htm
文件 73713 2014-08-12 11:16 14\testbook\Debug\main.obj
文件 69 2014-08-12 11:16 14\testbook\Debug\mt.dep
文件 663 2014-07-17 21:46 14\testbook\Debug\testbook.exe.em
文件 728 2014-07-17 21:46 14\testbook\Debug\testbook.exe.em
文件 621 2014-08-12 11:16 14\testbook\Debug\testbook.exe.intermediate.manifest
文件 158720 2014-08-12 11:16 14\testbook\Debug\vc90.idb
文件 233472 2014-08-12 11:16 14\testbook\Debug\vc90.pdb
文件 238 2014-07-13 09:35 14\testbook\eil14.tsp
文件 497 2006-05-11 12:48 14\testbook\eil51.tsp
文件 2902 2014-08-12 11:16 14\testbook\main.cpp
文件 4177 2014-08-12 11:16 14\testbook\testbook.vcproj
文件 1411 2014-07-04 00:34 14\testbook\testbook.vcproj.DELL-PC.DELL.user
文件 1403 2014-08-12 11:16 14\testbook\testbook.vcproj.ZJX.Administrator.user
- 上一篇:等保制度模板.zip
- 下一篇:广义逼近信息传递算法
相关资源
- 连续hopfield神经网络解决TSP问题
- 用8位spi实现16位spi
- TSP问题城市数据及最优解
- onvif协议视频转码推流网页播放
- 流媒体相关协议标准RTP/RTSP/RTCP PDF文档
- Hopfield神经网络解决 TSP问题
- H264实时编码RTSP直播
- 三种解决TSP问题的近似算法的实现
- TSP城市问题145个城市数据及其相应的
- 遗传算法解决TSP旅行商问题程序开源
- 将rtsp转码为flv格式用于h5播放前端使
- 5种多旅行商问题(MTSP)的遗传算法
- rtsp-h264.zip
- 免疫算法求解TSP问题详解
- websocket-rtsp-proxy-test.zip
- TSP问题测试数据集
- MP4v2录制rtsp流存为MP4文件
- rtsp摄像头推流上云使用浏览器播放
- Gprint 条码机 TSPL 中文编程手册蓝牙打
- PocketSphinxDemo
-
ijkpla
yer 最新rtsp .ts so库 - rtsp大全
- rtsp视频组帧(tcp和udp)
- TSP问题的数模论文合集
- TSP问题测试数据和最优结果含100多组
-
能够播放rtsp的ijkpla
yer动态库 - 离散数学实验TSP旅行商问题的代码实
- qt5.8实现rtsp流播放
- TSPLIB数据集、使用方法及最优解
- Setup for TheBestSpinner
评论
共有 条评论