Why to write a PSO as a function ?
文件目录:
main.m
PSO.m
OurTableDesignProblem.m
main.m
clear
clc
%Problem preparation
problem.nVar = 2;
problem.ub = [7,7];
problem.lb = [2,2];
problem.fobj = @OurTableDesignProblem;
%PSO parameters
noP = 5;
maxIter = 20;
visFlag = 1;
disp('PSO if optimizing the objective')
[GBEST,cgCurve] = PSO(noP,maxIter, problem, visFlag);
disp('End of the optimization process')
PSO.m
function[GBEST,cgCurve] = PSO(noP,maxIter, problem,dataVis)
%Define the details of the fobj
nVar = problem.nVar;
ub = problem.ub;
lb = problem.lb;
fobj = problem.fobj;
%Define the PSO's parametres
wMax = 0.9;
wMin = 0.