![](https://csdnimg.cn/release/download_crawler_static/86679577/bg1.jpg)
附录 1、标准微粒群算法源程序
/*该程序用于计算 Goldstein-Price 函数
)]361431419()1(1[)(
2
2212
2
11
2
211
xxxxxxxxxf ++−+−+++=
)]273648123218()32(30[
2
2212
2
11
2
21
xxxxxxxx +−++−−+×
2,2
21
≤
≤
−
xx
的函数最小值 */
//库文件
#include"stdio.h"
#include"stdlib.h"
#include"time.h"
#include"math.h"
//随机数定义
#define rdint(i) (rand()%(int)(i))
#define rdft() (float)((double)rdint(16384)/(16383.0))
#define rnd(a,b) (rdint((int)(b)-(int)(a)+1)+(int)(a))
//宏定义
#define POPSIZE 20
#define DIMENSION 2
//全局变量定义
float W=1.0;
float C1=1.8;
float C2=1.8;
float VMAX=2;
float XMIN=-2.0;
float XMAX=2.0;
float P[DIMENSION];
float PBEST;
struct indi
{
float number[DIMENSION];
float best[DIMENSION];
float bestfitness;
float fitness;
float speed[DIMENSION];
}individual[POPSIZE];
void initiate(void);
116