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

📄 tree_stringrc.m

📁 一个遗传规划的源程序
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -