⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 code.m

📁 简单遗传算法matlab文件?虻ヒ糯惴╩atlab文件
💻 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 + -