ahmedluss

40 Reputation

4 Badges

16 years, 19 days

MaplePrimes Activity


These are answers submitted by ahmedluss

Dear,

   I want to used these codes for optimiziation by using  Partical Swarm Optimization (POS) algorithm,

Algorithm:

 

Original PSO.D dimensions in the search space.loop

3: For each particle, evaluate the desired optimization fitness function in

4: Compare particle’s fitness evaluation with its

5: Identify the particle in the neighborhood with the best success so far, and assign itsindex to the variable g.

D variables.pbesti . If current value is better than pbesti, then set pbesti equal to the current value, and pi equal to the current location xi in D-dimensional space.

6: Change the velocity and position of the particle according to the following equation(see notes below):

 

 

vi vi + U(01)( pi xi )+ U(02)( pg xi ),

 

7: If a criterion is met (usually a sufficiently good fitness or a maximum number ofiterations), exit loop.

8:

xi xi + vi .                                                          (1)end loop

 the Codes in Matlab

 

% THE
% MATLAB

function [xmin, fxmin, iter] = PSO

%%%
success = 0;      

PopSize = 20;        
MaxIt = 5000;        
iter = 0;           

fevals = 0;      
maxw = 1.2;        

minw = 0.1;      

weveryit = floor(0.75*MaxIt); 
c1 = 0.5; 
c2 = 0.5; 
inertdec = (maxw-minw)/weveryit;
w = maxw;                    
f = “DeJong”;               
dim = 2;                     

upbnd = 5;                    

wbnd = –5;       
GM = 0;             
ErrGoal = 1e–3;                

% Initializing 
popul = rand(dim, PopSize)*(upbnd-lwbnd) + lwbnd;
vel = rand(dim, PopSize);

%Evaluate 
for i = 1:PopSize,
fpopul(i) = feval(f, popul(:,i));
fevals = fevals + 1;
end

% Initializing 
% values
bestpos = popul;
fbestpos = fpopul;

% Finding
[fbestpart,g] = min(fpopul);
lastbpf = fbestpart;

% SWARM EVOLUTION LOOP ? START ?
while (success == 0) & (iter < MaxIt),
iter = iter + 1;
% Update the value of the inertia weight w
if (iter<=weveryit)
w = maxw – (iter–1)?inertdec;
end

% VELOCITY UPDATE
for i=1:PopSize,
A(:,i) = bestpos(:,g);
end
R1 = rand(dim, PopSize);
R2 = rand(dim, PopSize);
vel = w?vel + c1?R1.?(bestpos-popul) + c2?R2.?(A-popul);

%

popul = popul + vel;

% Evaluate the new swarm
for i = 1:PopSize,
fpopul(i) = feval(f,popul(:, i));
fevals = fevals + 1;
end

% Updating 
changeColumns = fpopul < fbestpos;
fbestpos = fbestpos.*(~changeColumns) + fpopul.*changeColumns;
bestpos(:, find(changeColumns)) = popul(:, find(changeColumns));

% Updating
[fbestpart, g] = min(fbestpos);

% Checking 
%if 
if abs(fbestpart-GM) <= ErrGoal
success = 1;
else
lastbpf = fbestpart;
end
end
%  LOOP ? END ?
% Output
xmin = popul(:,g);
fxmin = fbestpos(g);

function DeJong=DeJong(x)
DeJong = sum(x.?2);
 




How can rewrite these codes  in Maple because I used Maple only .

I am waiting youres replay.

Thank you so much

Ahmed










 

1: Initialize a population array of particles with random positions and velocities on

2:

dear Sir,

 

     Iam waiting yours replay.

 

Thanks.

Ahmed

Page 1 of 1