资源简介
里面有几个文档是介绍相关背景,threadpool.h和threadpool.c文件包含了简单线程池的库函数,ant_pthread.c是并行蚁群算法的源代码
代码片段和文件信息
#include
#include
#include
#include “threadpool.h“
#define Num_city 30 //number of city
#define Num_ant 30 //number of ant
#define It_max 5000 //maxium number of iteration
double graph[Num_city][Num_city];//matirx saving distance between cities
double phe[Num_city][Num_city];//matrix saving pheromones of every path
double add[Num_city][Num_city];
double yita[Num_city][Num_city];
double alpha = 2 beta = 4 rou = 0.1 alpha1 = 0.1 qzero = 0.01;
double allDistance[Num_city][Num_city];
double Lnn;
pthread_mutex_t phe_lock = PTHREAD_MUTEX_INITIALIZER;
double C[Num_city][2] = {
{2 99}{4 50}{7 64}{13 40}{18 54}{18 40}{22 60}{24 42}{25 62}{25 38}{37 84}{41 94}{41 26}{44 35}{45 21}{54 67}{54 62}{58 35}{58 69}{62 32}{64 60}{68 58}{71 44}{71 71}{74 78}{82 7}{83 46}{83 69}{87 76}{91 38}
};
typedef struct antnode{
int startCity;
int visited[Num_city]; //0 for visited city and 1 for unvisited city
int antPath[Num_city][2];
}Ant;
double calculateDistance(int i int j){
return sqrt(pow((C[i][0] - C[j][0])2.0) + pow((C[i][1] - C[j][1])2.0));
}
void calculateAllDistance(){
for(int i = 0; i < Num_city; i++){
for(int j =0; j < Num_city; j++){
if(i != j){
allDistance[i][j] = calculateDistance(i j);
allDistance[j][i] = allDistance[i][j];
}
}
}
}
double calculateSumOfDistance(int* tour){
double sum = 0;
for(int i = 0; i < Num_city; i++){
int row = *(tour + 2 * i);
int col = *(tour + 2 * i +1);
sum += allDistance[row][col];
}
return sum;
}
void InitParameter(double value){
for(int i = 0; i < Num_city; i++){
for(int j = 0; j < Num_city; j++){
phe[i][j] = value;
phe[j][i] = value;
if(i != j){
yita[i][j] = 1.0 / allDistance[i][j];
yita[j][i] = yita[i][j];
}
}
}
}
int ChooseNextNode(int currentNode int visitedNode[]){
int nextNode = -1;
double shortDistance = 0.0;
for(int i = 0; i < Num_city; i++){
if(1 == visitedNode[i]){
if(shortDistance == 0.0){
shortDistance = allDistance[currentNode][i];
nextNode = i;
}
if(shortDistance < allDistance[currentNode][i]){
nextNode = i;
shortDistance = allDistance[currentNode][i];
}
}
}
return nextNode;
}
double CalAdjacentDistance(int node){
double sum = 0.0;
int visitedNode[Num_city];
int currentNode = node;
int nextNode;
for(int j = 0; j < Num_city; j++)
visitedNode[j] = 1;
do{
nextNode = ChooseNextNode(currentNode visitedNode);
if(nextNode >= 0){
sum += allDistance[currentNode][nextNode];
currentNode = nextNode;
visitedNode[currentNode] = 0;
}
}while(nextNode >= 0);
sum += allDistance[currentNode][node];
return sum;
}
double Transition(int i int j){
if(i != j){
pthread_mutex_lock(&phe_lock);
double temp = pow(phe[i][j] alpha) * pow(yita[i][j] beta);
pthread_mutex_unlock(&phe_lock);
return temp;
}else{
return 0.0;
}
}
void UpdateLocalPathRule(int i int j);
void* search(void* arg){
int
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-06-25 21:44 蚁群算法的简单并行\
文件 7056 2016-06-25 21:42 蚁群算法的简单并行\ant_pthread.c
文件 6161 2016-06-25 21:41 蚁群算法的简单并行\threadpool.c
文件 788 2016-06-25 21:41 蚁群算法的简单并行\threadpool.h
文件 412689 2016-06-25 14:48 蚁群算法的简单并行\一种基于蚁群算法的TSP问题分段求解算法.pdf
文件 271563 2016-06-22 11:04 蚁群算法的简单并行\一种蚁群算法的并行实现.pdf
文件 447917 2016-06-21 15:25 蚁群算法的简单并行\蚁群算法及其应用.docx
文件 695186 2016-06-21 15:23 蚁群算法的简单并行\蚁群算法基本知识.pdf
文件 1851197 2016-06-22 11:21 蚁群算法的简单并行\蚁群算法并行化研究.pdf
- 上一篇:zigbee协议栈中文版
- 下一篇:iar for arm 8.11注册机
相关资源
- 跨域请求解决方案源代码JSONPCORS
- jfreechartDEMO官网demo与源代码
- 比特币bitcoin源代码
- 网络流量实时监控源代码
- 小甲鱼汇编语言课件+源代码
- 微信公众平台开发最佳实践 源代码
- Canny算子源代码
- 蓝牙4.0 协议栈 开源代码
- 基于nrf51822的TSM12触控例程
- 小人吐笑脸案例源代码
- C编译器源代码187076
- 《Spark高级数据分析》源代码
- DSP语音识别教程+源代码
- PCRat远控开源代码
- OpenCV图像处理教程 - 贾志刚 课程配套
- Qt 串口助手增强版带示波器曲线源代
- CANopen协议栈源代码详解
- FPGA数字电子系统设计与开发导航源代
- 北风网_家庭理财系统源代码
- 易买网源代码183685
-
查看基于.netfr
amework编写的exe和dll源 - tcpdump 源代码
- 基于web的图书管理系统(源代码)1
- 在线教学系统网站开发源代码+视屏讲
- 硬连线控制器的常规CPU设计[BUPT]计算
- 一些神经网络经典模型的源代码
- 深度学习框架-pytorch入门与实践源代码
- 数据库课程设计源代码
- 大学生静态个人网站设计(源代码+论
- 室内定位 WIFI Scan 源代码
评论
共有 条评论