📄 equalcrossover.m
字号:
function [children1,children2]=EqualCrossOver(parent1,parent2)
%采用均匀交叉 例:
%父1:0 1 1 1 0 0 1 1 0 1 0
%父2:1 0 1 0 1 1 0 0 1 0 1
%掩码:0 1 1 0 0 0 1 1 0 1 0
%交叉后新个体:
%子1:1 1 1 0 1 1 1 1 1 1 1
%子2:0 0 1 1 0 0 0 0 0 0 0
L=length(parent1);
hidecode=round(rand(1,L));%随机生成掩码,如hidecode=[0 1 1 0 0 0 1 1 0 1 0];
children1=zeros(1,L);
children2=zeros(1,L);
children1(find(hidecode==1))=parent1(find(hidecode==1));%掩码为1,父1为子1提供基因
children1(find(hidecode==0))=parent2(find(hidecode==0));%掩码为0,父2为子1提供基因
children2(find(hidecode==1))=parent2(find(hidecode==1));%掩码为1,父2为子2提供基因
children2(find(hidecode==0))=parent1(find(hidecode==0));%掩码为0,父1为子2提供基因
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -