Info

此问题已关闭。 请重新打开它进行编辑或回答。

parfor loop , how should i use

1 次查看(过去 30 天)
Hassan
Hassan 2019-3-22
关闭: MATLAB Answer Bot 2021-8-20
Hi,
this is part of my code, it is my frist time to use par for.
the first question, how to fix this error such that The variable Evaluation in a parfor cannot be classified.
second shoud i use parfor loop for eac for loop or that one time as my code?
Thanks in advance.
parfor i=1:iteration
for k=1:swarm_size
zz=1;
for j=1 :centers
[fbest,best]=min(Evaluation);
gbest= swarm(best,:);
new_pos =swarm(k,:);
v(k,zz:zz+1)=v(k,zz:zz+1)+c1*rand*(Pbest(k,zz:zz+1)-swarm(k,zz:zz+1))+c2*rand*(gbest(1,zz:zz+1)-swarm(k,zz:zz+1));
new_pos(1,zz:zz+1)=swarm(k,zz:zz+1)+v(k,zz:zz+1);
zo=1; lo=1;
for Io=1: centers
C3C(:,Io) = f(Invpoints(:,1), new_pos(1,zo),Invpoints(:,2), new_pos(1,zo+1));
zo=zo+2;
end
fnewpos= sum(min(C3C,[],2));
for go=1: centers
C4C(:,go) = f(Invpoints(:,1), swarm(k,lo),Invpoints(:,2), swarm(k,lo+1));
lo=lo+2;
end
fswarm = sum(min(C4C,[],2));
zz=zz+2;
end
end
min(Evaluation)
end
  16 个评论
Hassan
Hassan 2019-3-25
Swarm Size=100
Iterations = 100
Dimensions = 5 : 100
Walter Roberson
Walter Roberson 2019-3-25
I am not sure what Dimensions corresponds to in your code?
What kind of value does centers have?
Your code appears to run j=1:centers and within that loop runs for Io = 1:centers, and also for go=1:centers . That suggests a run time on the order of swarm_size * centers^2 -- or possibly more as it is not clear whether f is a function or a 4D array being indexed.
Your code would really benefit from comments; it is difficult to understand what you are doing and why.

回答(0 个)

此问题已关闭。

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by