(genome, **args)
return int(mutations)
The mutator of GTreeGP, Subtree Mutator

   This mutator will recreate random subtree of the tree using the grow algorithm.

   .. versionadded:: 0.6
      The *GTreeGPMutatorSubtree* function
The mutator of GTreeGP, Subtree Mutator
The mutator of GTreeGP Subtree Mutator
def GTreeGPMutatorSubtree(genome, **args):
   """ The mutator of GTreeGP, Subtree Mutator

   This mutator will recreate random subtree of the tree using the grow algorithm.

   .. versionadded:: 0.6
      The *GTreeGPMutatorSubtree* function
   """

   if args["pmut"] <= 0.0:
      return 0
   ga_engine = args["ga_engine"]
   max_depth = genome.getParam("max_depth", None)
   mutations = 0

   if max_depth is None:
      Util.raiseException("You must specify the max_depth genome parameter !", ValueError)

   if max_depth < 0:
      Util.raiseException("The max_depth must be >= 1, if you want to use GTreeGPMutatorSubtree crossover !", ValueError)

   branch_list = genome.nodes_branch
   elements = len(branch_list)

   for i in xrange(elements):

      node = branch_list[i]
      assert node is not None

      if Util.randomFlipCoin(args["pmut"]):
         depth = genome.getNodeDepth(node)
         mutations += 1

         root_subtree = GTree.buildGTreeGPGrow(ga_engine, 0, max_depth - depth)
         node_parent = node.getParent()

         if node_parent is None:
            genome.setRoot(root_subtree)
            genome.processNodes()
            return mutations
         else:
            root_subtree.setParent(node_parent)
            node_parent.replaceChild(node, root_subtree)
         genome.processNodes()

   return int(mutations)
def GTreeGPMutatorSubtree ( genome , * * args ) : if args [ "pmut" ] <= 0.0 : return 0 ga_engine = args [ "ga_engine" ] max_depth = genome . getParam ( "max_depth" , None ) mutations = 0 if max_depth is None : Util . raiseException ( "You must specify the max_depth genome parameter !" , ValueError ) if max_depth < 0 : Util . raiseException ( "The max_depth must be >= 1, if you want to use GTreeGPMutatorSubtree crossover !" , ValueError ) branch_list = genome . nodes_branch elements = len ( branch_list ) for i in xrange ( elements ) : node = branch_list [ i ] assert node is not None if Util . randomFlipCoin ( args [ "pmut" ] ) : depth = genome . getNodeDepth ( node ) mutations += 1 root_subtree = GTree . buildGTreeGPGrow ( ga_engine , 0 , max_depth - depth ) node_parent = node . getParent ( ) if node_parent is None : genome . setRoot ( root_subtree ) genome . processNodes ( ) return mutations else : root_subtree . setParent ( node_parent ) node_parent . replaceChild ( node , root_subtree ) genome . processNodes ( ) return int ( mutations )