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

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

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

   if args["pmut"] <= 0.0:
      return 0
   elements = len(genome)
   mutations = args["pmut"] * elements
   ga_engine = args["ga_engine"]

   gp_terminals = ga_engine.getParam("gp_terminals")
   assert gp_terminals is not None

   gp_function_set = ga_engine.getParam("gp_function_set")
   assert gp_function_set is not None

   if mutations < 1.0:
      mutations = 0
      for i in xrange(len(genome)):
         if Util.randomFlipCoin(args["pmut"]):
            mutations += 1
            rand_node = genome.getRandomNode()
            assert rand_node is not None
            if rand_node.getType() == Consts.nodeType["TERMINAL"]:
               term_operator = rand_choice(gp_terminals)
            else:
               op_len = gp_function_set[rand_node.getData()]
               fun_candidates = []
               for o, l in gp_function_set.items():
                  if l == op_len:
                     fun_candidates.append(o)

               if len(fun_candidates) <= 0:
                  continue

               term_operator = rand_choice(fun_candidates)
            rand_node.setData(term_operator)
   else:
      for it in xrange(int(round(mutations))):
         rand_node = genome.getRandomNode()
         assert rand_node is not None
         if rand_node.getType() == Consts.nodeType["TERMINAL"]:
            term_operator = rand_choice(gp_terminals)
         else:
            op_len = gp_function_set[rand_node.getData()]
            fun_candidates = []
            for o, l in gp_function_set.items():
               if l == op_len:
                  fun_candidates.append(o)

            if len(fun_candidates) <= 0:
               continue

            term_operator = rand_choice(fun_candidates)
         rand_node.setData(term_operator)

   return int(mutations)
def GTreeGPMutatorOperation ( genome , * * args ) : if args [ "pmut" ] <= 0.0 : return 0 elements = len ( genome ) mutations = args [ "pmut" ] * elements ga_engine = args [ "ga_engine" ] gp_terminals = ga_engine . getParam ( "gp_terminals" ) assert gp_terminals is not None gp_function_set = ga_engine . getParam ( "gp_function_set" ) assert gp_function_set is not None if mutations < 1.0 : mutations = 0 for i in xrange ( len ( genome ) ) : if Util . randomFlipCoin ( args [ "pmut" ] ) : mutations += 1 rand_node = genome . getRandomNode ( ) assert rand_node is not None if rand_node . getType ( ) == Consts . nodeType [ "TERMINAL" ] : term_operator = rand_choice ( gp_terminals ) else : op_len = gp_function_set [ rand_node . getData ( ) ] fun_candidates = [ ] for o , l in gp_function_set . items ( ) : if l == op_len : fun_candidates . append ( o ) if len ( fun_candidates ) <= 0 : continue term_operator = rand_choice ( fun_candidates ) rand_node . setData ( term_operator ) else : for it in xrange ( int ( round ( mutations ) ) ) : rand_node = genome . getRandomNode ( ) assert rand_node is not None if rand_node . getType ( ) == Consts . nodeType [ "TERMINAL" ] : term_operator = rand_choice ( gp_terminals ) else : op_len = gp_function_set [ rand_node . getData ( ) ] fun_candidates = [ ] for o , l in gp_function_set . items ( ) : if l == op_len : fun_candidates . append ( o ) if len ( fun_candidates ) <= 0 : continue term_operator = rand_choice ( fun_candidates ) rand_node . setData ( term_operator ) return int ( mutations )