Module: TreeInsertNodeMutator

Defined in:
lib/charlie/tree/tree.rb

Overview

replaces a random node x by a new operator node having x as one of its children. When inserting a binary operator the other node will be a terminal.

Instance Method Summary collapse

Instance Method Details

#mutate!Object



235
236
237
238
239
240
241
242
243
# File 'lib/charlie/tree/tree.rb', line 235

def mutate!
  st = random_subtree
  if rand < 0.5 || unary_ops.nil?
    st.replace [binary_ops.at_rand, st.dup, generate_random_tree_full(0)]
  else
    st.replace [unary_ops.at_rand, st.dup]
  end
  self
end