Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
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 commentaire
Geoff Hayes
Geoff Hayes le 23 Juil 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.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by