tree_stringrc.m
来自「一种基于matlab的遗传规划编码程序 其中包含交叉和变异的代码」· M 代码 · 共 32 行
M
32 行
function s = tree_stringrc(tree,ix,symbols)
% Decodes the tree to string
% s = tree_stringrc(tree,ix,symbols)
% s <- the output string
% tree -> the tree
% ix -> index of strating point (the root = 1)
% symbols -> cell arrays of operator and terminator node strings
operator = {'+','-','.*','./','.^'};
ss = '';
if tree.nodetyp(ix)==1 & ix*2+1<=tree.maxsize,
sleft = tree_stringrc(tree,ix*2,symbols); % 左子树
sright = tree_stringrc(tree,ix*2+1,symbols); % 右子树
i = mod(ceil(abs(rand)*100),5)+1;
ss = operator{i};
s = strcat('(',sleft,')',ss,symbols{tree.nodetyp(ix)}{tree.node(ix)}, ...
'(',sright,')');
else
if tree.nodetyp(ix)==2,
s = symbols{tree.nodetyp(ix)}{tree.node(ix)};
else
% if rand<=0.5,
s='x';
% else
% s=unifrnd(0,100);
% end
end
end
return
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?