没有合适的资源?快使用搜索试试~ 我知道了~
并行遗传算法的程序源代码
5星 · 超过95%的资源 需积分: 24 147 下载量 38 浏览量
2010-08-17
16:26:52
上传
评论 9
收藏 14KB TXT 举报
温馨提示
试读
16页
这是一个简单的并行遗传算法源代码,由Denis Cormier (North Carolina State University)的串行程序修改得到的
资源推荐
资源详情
资源评论
并行遗传算法源程序(主从式)最新修改2009-02-25 11:06//这是一个简单的并行遗传算法源代码,由Denis Cormier (North Carolina State University)的
//串行程序修改得到的
#define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料
#include <stdio.h>
#include <tchar.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <iostream>
#include <mpi.h>
#include <windows.h>
#pragma comment(lib,"Wininet.lib")
#pragma comment(lib,"mpi.lib")
#pragma comment(lib,"cxx.lib")
#define POPSIZE 6 /* 群体大小,其实就是基因总数*/
#define MAXGENS 10 /* 进化代数 */
#define NVARS 3 /* 问题变量数,即基因的长度*/
#define PXOVER 0.8 /* 交叉概率 */
#define PMUTATION 0.15 /* 变异概率 */
#define TRUE 1
#define FALSE 0
int generation; /* 记录当前已经进化的代数 */
int cur_best; /* 最优个体 */
FILE *galog; /* 日志文件*/
struct genotype /* 基因类型*/
{
//串行程序修改得到的
#define WIN32_LEAN_AND_MEAN // 从 Windows 头中排除极少使用的资料
#include <stdio.h>
#include <tchar.h>
#include <stdlib.h>
#include <malloc.h>
#include <math.h>
#include <iostream>
#include <mpi.h>
#include <windows.h>
#pragma comment(lib,"Wininet.lib")
#pragma comment(lib,"mpi.lib")
#pragma comment(lib,"cxx.lib")
#define POPSIZE 6 /* 群体大小,其实就是基因总数*/
#define MAXGENS 10 /* 进化代数 */
#define NVARS 3 /* 问题变量数,即基因的长度*/
#define PXOVER 0.8 /* 交叉概率 */
#define PMUTATION 0.15 /* 变异概率 */
#define TRUE 1
#define FALSE 0
int generation; /* 记录当前已经进化的代数 */
int cur_best; /* 最优个体 */
FILE *galog; /* 日志文件*/
struct genotype /* 基因类型*/
{
double gene[NVARS]; /* 染色体字符串*/
double upper[NVARS]; /* 每个基于的上界*/
double lower[NVARS]; /* 每个基因的下界*/
double fitness; /* 个体适应度*/
double rfitness; /* 相对适应度*/
double cfitness; /* 累积适应度*/
};
struct genotype population[POPSIZE+1]; /* 种群*/
struct genotype newpopulation[POPSIZE+1]; /* 新种群*/
void initialize(void); /* 种群初始化函数*/
double randval(double, double); /* 随机函数*/
void keep_the_best(void); /*寻找最优个体*/
void elitist(void); /* 保持最优*/
void select(void); /* 选择算子*/
void crossover(void); /* 交叉算子*/
void Xover(int,int); /* 交叉操作*/
void swap(double *, double *); /* 交换*/
void evaluate(void); /* 个体适应度评价*/
void worker(genotype *,int ) /* 从处理器操作,突变和适应度评价*/
void report(void); /* 记录*/
/**************************************************************
初始化基因值,适应值。从gadata.txt中读入每
个变量的上下限,然后随机产生。
**************************************************************/
void initialize(void)
{
FILE *infile;
int i, j;
double lbound, ubound;
double upper[NVARS]; /* 每个基于的上界*/
double lower[NVARS]; /* 每个基因的下界*/
double fitness; /* 个体适应度*/
double rfitness; /* 相对适应度*/
double cfitness; /* 累积适应度*/
};
struct genotype population[POPSIZE+1]; /* 种群*/
struct genotype newpopulation[POPSIZE+1]; /* 新种群*/
void initialize(void); /* 种群初始化函数*/
double randval(double, double); /* 随机函数*/
void keep_the_best(void); /*寻找最优个体*/
void elitist(void); /* 保持最优*/
void select(void); /* 选择算子*/
void crossover(void); /* 交叉算子*/
void Xover(int,int); /* 交叉操作*/
void swap(double *, double *); /* 交换*/
void evaluate(void); /* 个体适应度评价*/
void worker(genotype *,int ) /* 从处理器操作,突变和适应度评价*/
void report(void); /* 记录*/
/**************************************************************
初始化基因值,适应值。从gadata.txt中读入每
个变量的上下限,然后随机产生。
**************************************************************/
void initialize(void)
{
FILE *infile;
int i, j;
double lbound, ubound;
剩余15页未读,继续阅读
xrq918
- 粉丝: 2
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页