📄 code.m
字号:
function Ret=Code(LenChrom,Opts,Bound)
% In this function ,it converts a set varibles into a chromosome
% LenChrom input : length of chromosome
% Opts input : tag of coding method
% Bound input : boundary of varibles
% Ret output: chromosome
switch Opts
case 'binary' % binary coding
Pick=rand(1,sum(LenChrom));
Bits=ceil(Pick-0.5);
Temp=sum(LenChrom)-1:-1:0;
Ret=sum(Bits.*(2.^Temp));
case 'grey' % grey coding
Pick=rand(1,sum(LenChrom));
Bits=ceil(Pick-0.5);
GreyBits=Bits;
for i=2:length(GreyBits)
GreyBits(i)=bitxor(Bits(i-1),Bits(i));
end
Temp=sum(LenChrom)-1:-1:0;
Ret=sum(GreyBits.*(2.^Temp));
case 'float' % float coding
Pick=rand(1,length(LenChrom));
Ret=Bound(:,1)'+(Bound(:,2)-Bound(:,1))'.*Pick;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -