def cxTwoPoint(ind1, ind2):
 size = min(len(ind1), len(ind2))
 cxpoint1 = random.randint(1, size)
 cxpoint2 = random.randint(1, (size - 1))
 if (cxpoint2 >= cxpoint1):
  cxpoint2 += 1
 else:
  (cxpoint1, cxpoint2) = (cxpoint2, cxpoint1)
 (ind1[cxpoint1:cxpoint2], ind2[cxpoint1:cxpoint2]) = (ind2[cxpoint1:cxpoint2], ind1[cxpoint1:cxpoint2])
 return (ind1, ind2)

def cxTwoPoint ( ind1 , ind2 ) : size = min ( len ( ind1 ) , len ( ind2 ) ) cxpoint1 = random . randint ( 1 , size ) cxpoint2 = random . randint ( 1 , ( size - 1 ) ) if ( cxpoint2 >= cxpoint1 ) : cxpoint2 += 1 else : ( cxpoint1 , cxpoint2 ) = ( cxpoint2 , cxpoint1 ) ( ind1 [ cxpoint1 : cxpoint2 ] , ind2 [ cxpoint1 : cxpoint2 ] ) = ( ind2 [ cxpoint1 : cxpoint2 ] , ind1 [ cxpoint1 : cxpoint2 ] ) return ( ind1 , ind2 )
executes a two-point crossover on the input :term:sequence individuals .