decode.m

来自「简单遗传算法matlab文件?虻ヒ糯惴╩atlab文件」· M 代码 · 共 25 行

M
25
字号
function Ret=Decode(LenChrom,Bound,Code,Opts)
% In this function ,it deCode chromosome 
% LenChrom   input : length of chromosome
% Opts       input : tag of coding method
% Bound      input : Boundary of varibles
% Ret        output: value of varibles
switch Opts
    case 'binary' % binary coding
        for i=length(LenChrom):-1:1
        data(i)=bitand(Code,2^LenChrom(i)-1);
        Code=(Code-data(i))/(2^LenChrom(i));
        end
        Ret=Bound(:,1)'+data./(2.^LenChrom-1).*(Bound(:,2)-Bound(:,1))';
    case 'grey'   % grey coding
        for i=sum(LenChrom):-1:2
            Code=bitset(Code,i-1,bitxor(bitget(Code,i),bitget(Code,i-1)));
        end
        for i=length(LenChrom):-1:1
        data(i)=bitand(Code,2^LenChrom(i)-1);
        Code=(Code-data(i))/(2^LenChrom(i));
        end
        Ret=Bound(:,1)'+data./(2.^LenChrom-1).*(Bound(:,2)-Bound(:,1))';
    case 'float'  % float coding
        Ret=Code;
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?