Initial Position of PSO

4 views (last 30 days)
Ali Ali
Ali Ali on 28 Sep 2018
Edited: Ali Ali on 28 Sep 2018
Hi There,
How do I initiate an initial position for PSO when moving from position to another.. I'm using class below to initiate my particles.
classdef sample_particle
properties
swarm = [];
index = 1;
end
methods
function [ obj ] = sample_particle( varargin )
% set the position of the initial swarm
for i = 1 : 8
for j = 1 : 8
obj.swarm(obj.index, 1, 1) = i;
obj.swarm(obj.index, 1, 2) = j;
obj.index = obj.index + 1;
end
end
obj.swarm(:,2,:) = 0; % set initial velocity for particles
obj.swarm(:,4,1) = inf; % set the best value so far
end
end
end
and objective function and end point
function [ z ] = objfcn_02( x )
x1=x(:,1); % starting X position
y1=x(:,2); % starting y position
x2=10; % ending X position
y2=10; % ending y position
z = sqrt((x1-x2).^2+(y1-y2).^2);
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!