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

1 次查看(过去 30 天)
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 个评论
Geoff Hayes
Geoff Hayes 2016-7-23
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by