how to do partial mapped crossover in matlab.

1 vue (au cours des 30 derniers jours)
Ruly Mulya
Ruly Mulya le 19 Nov 2018
how to do partial mapped crossover in matlab.
i have a matriks
A = [1 2;3 4;5 6;7 8;7 6;6 3]
B = [1 2;5 6;3 4;7 8;6 3;7 6]

Réponses (1)

pengfei ZHAO
pengfei ZHAO le 6 Mai 2022
%use in large problems size
clc;
clear;
P1 = randperm(200,200) %[4 7 1 6 5 2 3] % Fist Vector Needed to be Cross
P2 = randperm(200,200) %[1 2 3 4 5 6 7] %Second Vector Needed to be Cross
child1 = zeros(1,size(P1,2));
child2 = zeros(1,size(P1,2));
for k=1:10 %replace 10 and increase number if here infinity if problem d=0;
fC1=find(P2);
for i=1:10 %%replace 10 and increase number if here infinity if problem with r1==r2
r=randi([2,size(P2,2)-1],1,2);
lo=min(r);
up=max(r);
if lo==up
continue
else
break
end
end
for i=lo:up
child1(i)=P2(fC1(i));
end
for i= lo:up
a=P1(i);%2
b=child1(i);%5
G=find(a==child1);
if isempty(G)&& a~=b
Z=find(b==P1);
if child1(Z)==0
child1(Z)=a;
else
t=P2(Z);%7
Z=find(t==P1);%3
child1(Z)=a;
end
end
end
d=find(child1==0);%here deal with matrix size and also embed if the position is already occupied.....
if (d==0)
continue
else
break
end
end
for i=1:size(d,2)
child1(d(i))=P1(d(i));
end
child1
fC2=find(P1);
for k=1:10
for i=lo:up
child2(i)=P1(fC2(i));
end
for i= lo:up
a=P2(i);%7
b=child2(i);%5
G=find(a==child2);
if isempty(G)&& a~=b
Z=find(b==P2);
if child2(Z)==0
child2(Z)=a;
else
t=P1(Z);%7
Z=find(t==P2);%3
child2(Z)=a;
end
end
end
d=find(child2==0);%here deal with matrix size and also embed if the position is already occupied.....
if (d==0)
continue
else
break
end
end
for i=1:size(d,2)
child2(d(i))=P2(d(i));
end
child2

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by