[Tree-hh] Help needed with a copy constructor.

Stefan Koshiw stefankoshiw306 at gmail.com
Fri Dec 4 00:55:08 GMT 2009


Hi,

Thank you for that, it does work, in that it copies the tree root; but.. it
doesn't copy the value of the node iterators. I hadn't thought of this
previously, seems very obvious now.
The simplest thing to do would be to copy the node iterators across, one by
one... before i go on i'll give a bit more background information about my
project.

I'm using a paradigm of Artificial Life called Genetic Programming (GP) to
evolve Lindenmayer systems (L-Systems) (Bracketed D0L-Systems to be
specific), which is a parallel rewriting grammar used to describe plant
structures and fractals.

My specific area of research is in how i could utilise measurements for the
complexity of each individual and the neutrality - read similarity - between
individuals in order to evolve different species of L-Systems.

The flow of genetic programming is like so:
1) initialise a population of random individuals
2) measure their fitness (think survival of the fitter)
3) found the right result y/n?
   - if yes then terminate
4) select the ones you want
5) breed a new population via crossover
6) Mutate
7) go to number 2

I'm using tree.hh to represent my genomes which in tree form look like this:

L-System
|
|__Axiom
|    |___"F"
|
|___Production_Rules
    |
    |___Production_Rule_1
    |    |___Left
    |    |    |_____F
    |    |
    |    |___Right
    |        |_____F
    |        |
    |        |_____X
    |
    |___Production_Rule_2
        |___Left
        |    |_____X
        |
        |___Right
            |_____F
            |
            |_____Stack
                    |
                    |_F
                    |_F


Now in the initialization of the population each individual has to be of a
random breadth and depth up to certain limits. There is a predetermined
basic hierarchical structure to these trees. The tree root node "L-System"
and its children "Axiom" and "Production_Rules" are the fundamental
structure of a genome. Each Genome can have multiple production rules, and
each production rule consists of a left node and a right node. The terminals
of the left and right nodes of each production rule and the "Axiom" is where
variation between each genome is.
The "Right" node of  each production rule can have many terminals and it can
also have a stack node which in turn can have many terminals including
another stack node.

This is where i get a bit lost.

I've come up with a possible solution to this, in the initialization of the
"Right" node in each production rule, this recursive function could be
called.

tree<string>* Initialization::CreateStack()
{
    //new tree
    //choose the number of terminals
    //create each terminal choosing the value from the alphabet (F,+,-...
Stack)
        //if Stack
            //then call this->createstack
    // return the tree
}

The returned tree could then be merged with the "Right" node from which it
was first called.

This solution would be perfectly fine if... it is possible to manipulate a
tree without knowing all of its nodes.

THEREFORE...  Is it possible to search a tree to find its nodes?


Thank you for having read this far


Stefan Koshiw




2009/12/3 Kasper Peeters <kasper.peeters at aei.mpg.de>

> Hi Stefan,
>
> > class Genome
> > {
> > private:
> >     int m_Identity, m_Generation;
> >     tree<string> *tr;  //Tree root
>
> First of all, why don't you just put the tree in directly? I.e.
>
>   tree<string> tr;
>
> Then copy constructing will be automatic.
>
> If you cannot do this (perhaps you want to share the same tree among
> multiple Genome objects), then you can copy-construct a tree with
>
>   tr = new tree<string>( *othertree );
>
> where 'othertree' is a pointer to a tree<string>. This will make a
> copy of the other tree, and store that copy in the location pointed to
> by 'tr'.
>
> Hope this helps.
>
> Cheers,
> Kasper
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.hepforge.org/lists-archive/tree-hh/attachments/20091204/dc88f3c8/attachment.htm 


More information about the Tree-hh mailing list