📄 decode.m
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -