(genome, **args)
Allele initialization function of GTree

    To use this initializator, you must specify the *allele* genome parameter with the
    :class:`GAllele.GAlleles` instance.

    .. warning:: the :class:`GAllele.GAlleles` instance **must** have the homogeneous flag enabled

    .. versionadded:: 0.6
       The *GTreeInitializatorAllele* function.
Allele initialization function of GTree
Allele initialization function of GTree
def GTreeInitializatorAllele(genome, **args):
    """ Allele initialization function of GTree

    To use this initializator, you must specify the *allele* genome parameter with the
    :class:`GAllele.GAlleles` instance.

    .. warning:: the :class:`GAllele.GAlleles` instance **must** have the homogeneous flag enabled

    .. versionadded:: 0.6
       The *GTreeInitializatorAllele* function.
    """
    max_depth = genome.getParam("max_depth", 5)
    max_siblings = genome.getParam("max_siblings", 2)
    method = genome.getParam("method", "grow")

    allele = genome.getParam("allele", None)
    if allele is None:
        Util.raiseException("to use the GTreeInitializatorAllele, you must specify the 'allele' parameter")

    if not allele.homogeneous:
        Util.raiseException("to use the GTreeInitializatorAllele, the 'allele' must be homogeneous")

    if method == "grow":
        root = GTree.buildGTreeGrow(0, allele[0].getRandomAllele, max_siblings, max_depth)
    elif method == "full":
        root = GTree.buildGTreeFull(0, allele[0].getRandomAllele, max_siblings, max_depth)
    elif method == "ramped":
        if Util.randomFlipCoin(0.5):
            root = GTree.buildGTreeGrow(0, allele[0].getRandomAllele, max_siblings, max_depth)
        else:
            root = GTree.buildGTreeFull(0, allele[0].getRandomAllele, max_siblings, max_depth)
    else:
        Util.raiseException("Unknown tree initialization method [%s] !" % method)

    genome.setRoot(root)
    genome.processNodes()
    assert genome.getHeight() <= max_depth
def GTreeInitializatorAllele ( genome , * * args ) : max_depth = genome . getParam ( "max_depth" , 5 ) max_siblings = genome . getParam ( "max_siblings" , 2 ) method = genome . getParam ( "method" , "grow" ) allele = genome . getParam ( "allele" , None ) if allele is None : Util . raiseException ( "to use the GTreeInitializatorAllele, you must specify the 'allele' parameter" ) if not allele . homogeneous : Util . raiseException ( "to use the GTreeInitializatorAllele, the 'allele' must be homogeneous" ) if method == "grow" : root = GTree . buildGTreeGrow ( 0 , allele [ 0 ] . getRandomAllele , max_siblings , max_depth ) elif method == "full" : root = GTree . buildGTreeFull ( 0 , allele [ 0 ] . getRandomAllele , max_siblings , max_depth ) elif method == "ramped" : if Util . randomFlipCoin ( 0.5 ) : root = GTree . buildGTreeGrow ( 0 , allele [ 0 ] . getRandomAllele , max_siblings , max_depth ) else : root = GTree . buildGTreeFull ( 0 , allele [ 0 ] . getRandomAllele , max_siblings , max_depth ) else : Util . raiseException ( "Unknown tree initialization method [%s] !" % method ) genome . setRoot ( root ) genome . processNodes ( ) assert genome . getHeight ( ) <= max_depth