资源简介
里面有几个文档是介绍相关背景,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注册机
相关资源
- bp神经网络源代码,可直接运行
- 仿知乎界面小程序源代码
- 贪吃蛇源代码.fla
- dotnet 写字板 实验 源代码 不好请要不
- 图像二维小波变换的实现源代码
- 八三编码器设计 VHDL代码 简单,包附
- linux应用层的华容道游戏源代码
- 网上拍卖系统完整源代码
- CSMA/CD等动画演示加源代码
- silicon lab公司的收音IC SI47XX全套开发工
- 合同管理系统的源代码(附数据库)
- 用VC 编写的仿QQ聊天室程序源代码
- STM32F103 串口程序(完整版)
- VPC3_DPV1源代码,Profibus
- PB做的托盘程序(最小化后在左下角显
- 透明加密源码及说明
- 排队机叫号 源代码
- 五子棋C 源代码
- CAD LISP24个源代码
- 二叉树基本操作源代码
- 推箱子及人工智能寻路C 源代码
- opengl轮廓字体源代码
- 冈萨雷斯 数字图像处理 源代码(m文
- 直流伺服电机电路原理图(内附单片
- 哈哈冒险岛登入器源代码
- midi电子琴简单设计(附源代码).ra
- PESQ C源代码
- 画图程序MFC/VC/VC CRectTracker 串行化
- 莱卡 全站仪数据格式转换程序,有源
- HEX到Bin文件源代码
评论
共有 条评论