Filter löschen
Filter löschen

why in the following code the value of gbest is not updating with each iteration and showing Infinity as a outcome..

1 Ansicht (letzte 30 Tage)
fgbest=Inf;
for j=1:Popsize
% Generate Random Solution
pop(:,j)=randi([500,2000],10,1);
[obj]=objfn(pop,it);
%
% % Evaluation
obj1(j,1) = obj(j,1);%
%
% Update the Personal Best
pbest(:,j) = pop(:,j);% pbest
fpbest(j,1) =obj1(j,1);% objective function
%
% % Update Global Best
if fpbest(j,1) < fgbest
gbest = pbest(:,j);% gbest
end
end
  1 Kommentar
Geoff Hayes
Geoff Hayes am 23 Jul. 2016
sharad - what is your objective function, objfn? Have you stepped through the code to see what is happening and, in particular, what this function is returning? Also, for your condition
if fpbest(j,1) < fgbest
gbest = pbest(:,j);% gbest
end
I think that you want to be using just one of gbest or fgbest. (What is the difference between the two?) Since you are trying to find the global best, you will always want to compare against the last best found solution. So something like
if fpbest(j,1) < fgbest
fgbest = pbest(:,j);
end
may be what you really want.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by