Undefined operator '==' for input arguments of type 'cell'?

i got an error
Undefined operator '==' for input arguments of type 'cell'.
Error in GeneratePopulation (line 143)
pt=find(p1==1); %cycle value utk p1
what can i do to fix it?
%% parent selection
cp=0.4; % Crossover Percentage
np=2*round(cp*r/2); % Number of Offsprings (Parents)
% np=cp*r
valp=np/2;
v=valp;
n1=length(RS(:,1));
PP=RS([1:v,n1-v+1:end],3:end);
P=cell(1,np); % preallocate
for i=1:np
P{i} = PP(i,:);
end
%celldisp(P);
%vertcat(P{:}); % double array
%% CYCLE CROSSOVER
szcld = size(P,2); % p
n2=length(P(:,1));
c1=zeros(1,szcld);
c2=zeros(1,szcld);
p1= P(1:v);
p2= P(1:n2-v+1:end);
pt=find(p1==1); %cycle value utk p1
for i=1:P
while (c1(pt)==0)
c1(pt)=p1(pt);
pt=find(p1==p2(pt));
end
left=find(c1==0);
c1(left)=p2(left)
pt=find(p4==1); %cycle value utk p1
while (c2(pt)==0)
c2(pt)=p4(pt);
pt=find(p2==p1(pt));
end
left=find(c2==0);
c2(left)=p1(left);
end

Answers (1)

P=vertcat(P{:}); % double array %% uncomment this line

10 Comments

If you do that then you might as well use PP instead of PP since PP is in matrix form and for some reason is being deliberately broken out into rows.
True sir Walter completely missed that part , OP has to clarify further more and indeed he needs to provide the missing datas to run the code.
left is not a variable in the code you posted so we have no idea what it is set to.
this is my full coding.. could you help me
%% read data
clc
clear
%global f d;
%flow
f=[ 0 90 10 23 43 0 0 0 0 0 0 0
90 0 0 0 0 88 0 0 0 0 0 0
10 0 0 0 0 0 26 16 0 0 0 0
23 0 0 0 0 0 0 0 0 0 0 0
43 0 0 0 0 0 0 0 0 0 0 0
0 88 0 0 0 0 0 0 1 0 0 0
0 0 26 0 0 0 0 0 0 0 0 0
0 0 16 0 0 0 0 0 0 96 0 0
0 0 0 0 0 1 0 0 0 0 29 0
0 0 0 0 0 0 0 96 0 0 0 37
0 0 0 0 0 0 0 0 29 0 0 0
0 0 0 0 0 0 0 0 0 37 0 0];
%distance
d=[ 0 36 54 26 59 72 9 34 79 17 46 95
36 0 73 35 90 58 30 78 35 44 79 36
54 73 0 21 10 97 58 66 69 61 54 63
26 35 21 0 93 12 46 40 37 48 68 85
59 90 10 93 0 64 5 29 76 16 5 76
72 58 97 12 64 0 96 55 38 54 0 34
9 30 58 46 5 96 0 83 35 11 56 37
34 78 66 40 29 55 83 0 44 12 15 80
79 35 69 37 76 38 35 44 0 64 39 33
17 44 61 48 16 54 11 12 64 0 70 86
46 79 54 68 5 0 56 15 39 70 0 18
95 36 63 85 76 34 37 80 33 86 18 0];
[r,c]=size(f);
max_i=r;
max_j=r;
max_k=r;
max_q=r;
MaxIt=12;
% % % Create Empty Structure
% empty_individual.P1=[];
% empty_individual.P2=[];
% Create Population Matrix (Array)
% pop=repmat(empty_individual,r,1);
%% calculate fitness function
for no=1:MaxIt
ID=randperm(r); %PERMUTATION r NOMBOR ..r = 3, 1 2 3, 1 3 2...
x=zeros(r,r);
n=length(ID);
x1=ID;
for i=1:n
for j=1:r
x(j,x1(j))=1;
B(no).mat=x; % utk simpan memori bila buat 0,1 permuation tu dlm (i),BINARY UNTUK RELATION
end
x=zeros(r,r);
end
z=0;xa=B(no).mat;
for i=1:max_i
for j=1:max_j
for k=1:max_k
for q=1:max_q
z= z+ f(i,k).*d(j,q).*xa(i,j).*xa(k,q);
end
end
end
end
no;
% G(no,:)=[no z]; %STOR SEMUA VALUE Z 1 HINGGA MaxI DLM MATRIX G
F(no,:)=[no z ID]; %STOR SEMUA VALUE Z dan ID 1 HINGGA MaxIt DLM MATRIX F
end
%end
format compact % Suppresses the display of blank lines.
%
zmin=min(F(:,2));
zmax=max(F(:,2));
% ii=find(F(:,2)==zmin) ;
% x_initial = B(ii).mat;
%xbin= B(ii).mat % xbin = initial value for facility location for minimun z
%Iter_zvalue = F %matrix F ada no iter..col 1 dan z
Iter_zvalue = F; %matrix F ada no iter, z dan ID
% K = G %matrix F ada no iter, z dan ID
% %permutation untuk min value..
% b=find(F(:,2)==zmin);
% ID_for_minz=F(b,:)
%
%% Rank Selection.
RS = sortrows(F,2);
RS(:,1) = 1:size(F,1);
%% parent selection
cp=0.4; % Crossover Percentage
np=2*round(cp*r/2); % Number of Offsprings (Parents)
% np=cp*r
valp=np/2;
v=valp;
n1=length(RS(:,1));
PP=RS([1:v,n1-v+1:end],3:end);
P=cell(1,np); % preallocate
for i=1:np
P{i} = PP(i,:);
end
celldisp(P);
P=vertcat(P{:});% double array
%% CYCLE CROSSOVER (long)
szcld = size(P,2); % p
n2=length(P(:,1));
c1=zeros(1,szcld);
c2=zeros(1,szcld);
p1= P(1:v);
p2= P(1:n2-v+1:end);
pt=find(p1==1); %cycle value utk p1
for i=1:P
while (c1(pt)==0)
c1(pt)=p1(pt);
pt=find(p1==p2(pt));
end
left=find(c1==0);
c1(left)=p2(left)
pt=find(p2==1); %cycle value utk p1
while (c2(pt)==0)
c2(pt)=p2(pt);
pt=find(p2==p1(pt));
end
left=find(c2==0);
c2(left)=p1(left);
end
Your PP matrix is 2d. Exactly what part of the 2d array should be tested for value equal 1?
each line in PP represent the result that i get from iteration and i want to used the result to make a crossover..
for example
result 1 = 4 8 3 1 2 11 12 7 6 10 9 5
result 2= 11 4 7 5 12 3 9 1 2 8 6 10
result 3= 7 6 12 3 10 8 11 5 4 1 2 9
result 4= 5 2 6 4 9 8 12 11 7 1 10 3
so i eant to used result 1 as p1 and result 4 as p2 in the crssover and repeated untill it used all the result in PP.. however i didnt want to do it manually.. thats why i want to make it as array so that (i) can automatically change in the loop variable
Why result1 and result4 ? You look like you are doing a traveling salesman problem in which every row is a permutation of 1:12, so all of the rows will contain a 1 . I do not understand what you expect
pt=find(p1==1);
to return?
i didnt do TSP..im doing quadrattic assignment problem..its a little bit different but still to find a minimum result..
im trying to do cycle crossover..
pt=find(p1==1);
im tying to fine the cycle value on p1..
So you want to find all the linear indices in p1 at which the value is 1? Not the column number in each row?
when u said it like that.. its seem that my coding is wrong.. i want to find a linear indices in p1 but i dont want all the value is equal to 1.
and i want to read PP not as matrix but as an answer .. each row is an answer / parent

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!