资源简介
烟花优化算法(c语言版)
代码片段和文件信息
#include
#include
#include
#include
#include “FWA.h“
#include “utilities.h“
double FWA(double* x)
{
double **fireworks*fitnesses
**positions*vals;
double *Rs;
double *As;
int *nums;
int *flags;
//allocate memory
fireworks = (double **)calloc(Nsizeof(double*));
int ijk;
for (i = 0;i < N;i++)
{
fireworks[i] = (double *)calloc(DIMENSIONsizeof(double));
}
fitnesses = (double *)calloc(Nsizeof(double));
int buffer = (N+MM+N*BM);
positions = (double **)calloc(buffersizeof(double*));
for (i = 0;i < buffer;i++)
{
positions[i] = (double*)calloc(DIMENSIONsizeof(double));
}
vals = (double *)calloc(buffersizeof(double));
As = (double *)calloc(Nsizeof(double));
nums = (int *)calloc(Nsizeof(int));
flags = (int*)calloc(DIMENSIONsizeof(int));
Rs = (double *)calloc(buffersizeof(double));
initilize_rng();
for (i = 0;i < N;i++)
{
for (j = 0;j < DIMENSION;j++)
{
fireworks[i][j] = lea(LBOUNDUBOUND);
}
fitnesses[i] = evaluate(fireworks[i]DIMENSION);
}
double minmaxsum;
int counteridx;
int nncountindex;
int iter;
for (iter = 0;iter < MAX_ITERATION;iter++)
{
min = max = fitnesses[0];
for(i = 1;i < N;i++)
{
if(min > fitnesses[i])
{
min = fitnesses[i];
}
if (max < fitnesses[i])
{
max = fitnesses[i];
}
}
sum = 0;
for (i = 0;i < N;i++)
{
sum += (max - fitnesses[i]);
}
counter = N+MM;
for(i = 0;i < N;i++)
{
nums[i] = (int)(M*((max - fitnesses[i] + EPS)/(sum+EPS)));
if (nums[i] < AM)
{
nums[i] = AM;
}else if(nums[i] > BM)
{
nums[i] = BM;
}
counter += nums[i];
}
sum = 0;
for (i = 0;i < N;i++)
{
sum += (fitnesses[i] - min);
}
for(i = 0;i < N;i++)
{
As[i] = A*((fitnesses[i]-min+EPS)/(sum+EPS));
}
for (idx = 0;idx < N;idx++)
{
memcpy(positions[idx]fireworks[idx]sizeof(double)*DIMENSION);
vals[idx] = fitnesses[idx];
}
for (i = 0;i < MM;i++)
{
memset(flags0sizeof(int)*DIMENSION);
nn = rand()%DIMENSION+1;
count = 0;
while (count < nn)
{
index = rand()%DIMENSION;
if (flags[index] != 1)
{
flags[index] = 1;
count++;
}
}
int id = rand()%N;
double g = randn(11);
for (j = 0;j < DIMENSION;j++)
{
if (flags[j] == 1)
{
positions[idx][j] = fireworks[id][j]*g;
if (positions[idx][j] {
double tt = abs(positions[idx][j]);
while(tt > 0)
{
tt -= (UBOUND-LBOUND);
}
tt += (UBOUND-LBOUND);
positions[idx][j] = LBOUND + tt;
}else if (positions[idx][j]>UBOUND)
{
double tt = abs(positions[idx][j]);
while(tt > 0)
{
tt -= (UBOUND-LBOUND);
}
tt += (UBOUND-LBOUND);
positions[idx][j] = LBOUND + tt;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2013-10-22 22:22 FWA-C-Codes\
文件 5657 2011-12-07 09:42 FWA-C-Codes\FWA.c
文件 1381 2011-12-06 20:45 FWA-C-Codes\FWA.dev
文件 1376 2011-12-07 09:44 FWA-C-Codes\FWA.h
文件 1396 2011-12-07 09:31 FWA-C-Codes\main.c
文件 923 2011-12-07 09:45 FWA-C-Codes\Makefile.win
文件 203 2011-12-06 21:21 FWA-C-Codes\readme.txt
文件 2006 2011-12-06 20:37 FWA-C-Codes\utilities.c
文件 497 2011-12-06 21:02 FWA-C-Codes\utilities.h
- 上一篇:电力系统潮流计算-牛顿拉夫逊法
- 下一篇:8位竞赛抢答器的课程设计报告.docx
相关资源
- c++常用游戏算法及数据结构设计
- 深度学习算法地图
- 扫描线多边形填充算法实现
- 基于改进的fcm算法的图像分割vc++
- TLV解析算法
- 《Data Structures and Algorithm Analysis in C
- TOA/AOA定位算法C语言代码
- 算法帝国pdf
- 算法_C语言的实现完整版
- 数值分析算法程序设计 C++实现
- FFT算法c语言代码
- VC++实现RSA加密算法
- AAM算法实现
- 算法竞赛入门经典 第二版刘汝佳著含
- 基于极大似然估计的三维定位算法
- snappy压缩,解压算法
- C语言实现的银行家算法 做了界面
- C++模拟存储器的分配与回收算法实现
- 欧式距离实现的聚类算法
- “背景建模技术”库37种算法
- C++实现RSA加密解密算法
- 圆检测 用霍夫变换算法实现
- AES-128-CBC算法C语言源码已经修改,可
- 页面置换算法(fifolruopt) C语言编写
- 数据结构各种算法实现(C++模板),
- 正则表达式(regex)C语言源码,超强
- 扩展欧几里德算法c++代码
- 常用算法程序集C语言描述 第三版pd
- 经典开源A星算法含完整运行程序
- VC++数字图像处理典型算法及实现
评论
共有 条评论