Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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 comentario
Geoff Hayes
Geoff Hayes el 23 de Jul. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by