里面有几个文档是介绍相关背景,threadpool.h和threadpool.c文件包含了简单线程池的库函数,ant_pthread.c是并行蚁群算法的源代码
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-06-25 21:44 蚁群算法的简单并行
文件 7056 2016-06-25 21:42 蚁群算法的简单并行ant_pthread.c
文件 6161 2016-06-25 21:41 蚁群算法的简单并行 hreadpool.c
文件 788 2016-06-25 21:41 蚁群算法的简单并行 hreadpool.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
#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 蚁群算法的简单并行 hreadpool.c
文件 788 2016-06-25 21:41 蚁群算法的简单并行 hreadpool.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
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)