def cxUniformPartialyMatched(ind1, ind2, indpb):
 size = min(len(ind1), len(ind2))
 (p1, p2) = (([0] * size), ([0] * size))
 for i in xrange(size):
  p1[ind1[i]] = i
  p2[ind2[i]] = i
 for i in xrange(size):
  if (random.random() < indpb):
   temp1 = ind1[i]
   temp2 = ind2[i]
   (ind1[i], ind1[p1[temp2]]) = (temp2, temp1)
   (ind2[i], ind2[p2[temp1]]) = (temp1, temp2)
   (p1[temp1], p1[temp2]) = (p1[temp2], p1[temp1])
   (p2[temp1], p2[temp2]) = (p2[temp2], p2[temp1])
 return (ind1, ind2)

def cxUniformPartialyMatched ( ind1 , ind2 , indpb ) : size = min ( len ( ind1 ) , len ( ind2 ) ) ( p1 , p2 ) = ( ( [ 0 ] * size ) , ( [ 0 ] * size ) ) for i in xrange ( size ) : p1 [ ind1 [ i ] ] = i p2 [ ind2 [ i ] ] = i for i in xrange ( size ) : if ( random . random ( ) < indpb ) : temp1 = ind1 [ i ] temp2 = ind2 [ i ] ( ind1 [ i ] , ind1 [ p1 [ temp2 ] ] ) = ( temp2 , temp1 ) ( ind2 [ i ] , ind2 [ p2 [ temp1 ] ] ) = ( temp1 , temp2 ) ( p1 [ temp1 ] , p1 [ temp2 ] ) = ( p1 [ temp2 ] , p1 [ temp1 ] ) ( p2 [ temp1 ] , p2 [ temp2 ] ) = ( p2 [ temp2 ] , p2 [ temp1 ] ) return ( ind1 , ind2 )
executes a uniform partially matched crossover on the input individuals .