标准粒子群优化算法源代码2006版

分类:代码, 博客 标签:

C语言实现的标准粒子群优化算法源代码下载

标准粒子群优化算法经常是改进算法的参考标准,这里给出采用C语言的一个标准PSO算法的实现版本,除了可以作为参考也可以作为改进的基础。
里面有不少常用的测试函数
0 Parabola (Sphere)
1 De Jong’ f4
2 Griewank
3 Rosenbrock (Banana)

4 Step
6 Foxholes 2D
7 Polynomial fitting problem 9D
8 Alpine
9 Rastrigin
10 Ackley
13 Tripod 2D
17 KrishnaKumar
18 Eason 2D

#include "stdio.h"
#include "math.h"
#include 
#include 

#define	D_max 100  // Max number of dimensions of the search space
#define	S_max 100 // Max swarm size
#define R_max 200 // Max number of runs

// Structures
struct velocity
{
  int size;
  double v[D_max];
};

struct position
{
  int size;
  double x[D_max];
  double f;
};

// Sub-programs
double alea( double a, double b );
int alea_integer( int a, int b );
double perf( int s, int function ); // Fitness evaluation

// Global variables
int best; // Best of the best position (rank in the swarm)
int D; // Search space dimension
double E; // exp(1). Useful for some test functions
double f_min; // Objective(s) to reach
int LINKS[S_max] [S_max]; // Information links
int nb_eval; // Total number of evaluations
double pi; // Useful for some test functions
struct position P[S_max]; // Best positions found by each particle
int S; // Swarm size
struct velocity V[S_max]; // Velocities
struct position X[S_max]; // Positions
double xmin[D_max], xmax[D_max]; // Intervals defining the search space

// File(s)
FILE * f_run;

// =================================================
int main()
{
  double c; // Second onfidence coefficient
  int d; // Current dimension
  double eps; // Admissible error
  double eps_mean; // Average error
  double error; // Error for a given position
  double error_prev; // Error after previous iteration
  int eval_max; // Max number of evaluations
  double eval_mean; // Mean number of evaluations
  int function; // Code of the objective function
  int g; // Rank of the best informant
  int init_links; // Flag to (re)init or not the information links
  int i;
  int K; // Max number of particles informed by a given one
  int m;
  double mean_best[R_max];
  double min; // Best result through several runs
  int n_exec, n_exec_max; // Nbs of executions
  int n_failure; // Number of failures
  int s; // Rank of the current particle
  double t1, t2;
  double variance;
  double w; // First confidence coefficient
  //未列出所有代码,太长了,源代码请在下面的链接自行下载

点击下载:标准粒子群优化算法源代码 starndard pso 2006 (2792)



分类:代码, 博客 标签:

发表评论

You must be logged in to post a comment.