#NEWLINE# @ crossover #NEWLINE# def uniform_crossover( random , mom , dad , args ) : #NEWLINE# #INDENT# "Return the offspring of uniform crossover on the candidates.\n\n    This function performs uniform crossover (UX). For each element \n    of the parents, a biased coin is flipped to determine whether \n    the first offspring gets the 'mom' or the 'dad' element. An \n    optional keyword argument in args, ``ux_bias``, determines the bias.\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    - *ux_bias* -- the bias toward the first candidate in the crossover \n      (default 0.5)\n    \n    " #NEWLINE# ux_bias = args . setdefault ( 'ux_bias' , 0.5 ) #NEWLINE# crossover_rate = args . setdefault ( 'crossover_rate' , 1.0 ) #NEWLINE# children = [ ] #NEWLINE# if ( random . random ( ) < crossover_rate ) : #NEWLINE# #INDENT# bro = copy . copy ( dad ) #NEWLINE# sis = copy . copy ( mom ) #NEWLINE# for ( i , ( m , d ) ) in enumerate ( zip ( mom , dad ) ) : #NEWLINE# #INDENT# if ( random . random ( ) < ux_bias ) : #NEWLINE# #INDENT# bro [ i ] = m #NEWLINE# sis [ i ] = d #NEWLINE# #UNINDENT# #UNINDENT# children . append ( bro ) #NEWLINE# children . append ( sis ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# children . append ( mom ) #NEWLINE# children . append ( dad ) #NEWLINE# #UNINDENT# return children