#NEWLINE# @ crossover #NEWLINE# def arithmetic_crossover( random , mom , dad , args ) : #NEWLINE# #INDENT# "Return the offspring of arithmetic crossover on the candidates.\n\n    This function performs arithmetic crossover (AX), which is similar to a \n    generalized weighted averaging of the candidate elements. The allele\n    of each parent is weighted by the *ax_alpha* keyword argument, and\n    the allele of the complement parent is weighted by 1 - *ax_alpha*.\n    This averaging is only done on the alleles listed in the *ax_points*\n    keyword argument. If this argument is ``None``, then all alleles\n    are used. This means that if this function is used with all default\n    values, then offspring are simple averages of their parents.\n    This function also makes use of the bounder function as specified \n    in the EC's ``evolve`` method.\n\n    .. Arguments:\n       random -- the random number generator object\n       mom -- the first parent candidate\n       dad -- the second parent candidate\n       args -- a dictionary of keyword arguments\n\n    Optional keyword arguments in args:\n    \n    - *crossover_rate* -- the rate at which crossover is performed \n      (default 1.0)\n    - *ax_alpha* -- the weight for the averaging (default 0.5)\n    - *ax_points* -- a list of points specifying the alleles to\n      recombine (default None)\n    \n    " #NEWLINE# ax_alpha = args . setdefault ( 'ax_alpha' , 0.5 ) #NEWLINE# ax_points = args . setdefault ( 'ax_points' , None ) #NEWLINE# crossover_rate = args . setdefault ( 'crossover_rate' , 1.0 ) #NEWLINE# bounder = args [ '_ec' ] . bounder #NEWLINE# children = [ ] #NEWLINE# if ( random . random ( ) < crossover_rate ) : #NEWLINE# #INDENT# bro = copy . copy ( dad ) #NEWLINE# sis = copy . copy ( mom ) #NEWLINE# if ( ax_points is None ) : #NEWLINE# #INDENT# ax_points = list ( range ( min ( len ( bro ) , len ( sis ) ) ) ) #NEWLINE# #UNINDENT# for i in ax_points : #NEWLINE# #INDENT# bro [ i ] = ( ( ax_alpha * mom [ i ] ) + ( ( 1 - ax_alpha ) * dad [ i ] ) ) #NEWLINE# sis [ i ] = ( ( ax_alpha * dad [ i ] ) + ( ( 1 - ax_alpha ) * mom [ i ] ) ) #NEWLINE# #UNINDENT# bro = bounder ( bro , args ) #NEWLINE# sis = bounder ( sis , args ) #NEWLINE# children . append ( bro ) #NEWLINE# children . append ( sis ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# children . append ( mom ) #NEWLINE# children . append ( i ) #NEWLINE# #UNINDENT# return children