def mutNodeReplacement(individual, pset):
 if (len(individual) < 2):
  return (individual,)
 index = random.randrange(1, len(individual))
 node = individual[index]
 if (node.arity == 0):
  term = random.choice(pset.terminals[node.ret])
  if isclass(term):
   term = term()
  individual[index] = term
 else:
  prims = [p for p in pset.primitives[node.ret] if (p.args == node.args)]
  individual[index] = random.choice(prims)
 return (individual,)

def mutNodeReplacement ( individual , pset ) : if ( len ( individual ) < 2 ) : return ( individual , ) index = random . randrange ( 1 , len ( individual ) ) node = individual [ index ] if ( node . arity == 0 ) : term = random . choice ( pset . terminals [ node . ret ] ) if isclass ( term ) : term = term ( ) individual [ index ] = term else : prims = [ p for p in pset . primitives [ node . ret ] if ( p . args == node . args ) ] individual [ index ] = random . choice ( prims ) return ( individual , )
replaces a randomly chosen primitive from *individual* by a randomly chosen primitive with the same number of arguments from the :attr:pset attribute of the individual .