in reply to GP problem with tree structure using hash
For a tree represented as a recursive hash, the crossover and mutation operators are fairly simple.
It looks like you have only binomial operators, so a binary tree. To arrive at a random node, start at the root, $tree, and pick a random key, "left" or right". Then ,e.g., $tree->{left} becomes the new root and pick another random key, etc. Continue walking the hash until you get to a terminal, which you can recognize as a non-reference. Alter that terminal to get a one-point mutation.
For a crossover, each node on the tree is a ref, so you can just exchange references:
For Boolean expression chromosomes, you will want to make sure that mutations and crossovers generate a syntatctically valid expression (I haven't checked your code for this).$temp = $tree->{right}{left}; $tree->{right}{left} = $tree->{right}{right}; $tree->{right}{right} = temp;
That is the general idea. The implementation is left as an exercise :)
-Mark
|
---|
In Section
Seekers of Perl Wisdom