def crossover(self, chromosome, point1, point2=None):
assert self.length == chromosome.length<EOL>if point2 is None:<EOL><INDENT>new_dna = self.dna[:point1] + chromosome.dna[point1:]<EOL>other_new_dna = chromosome.dna[:point1] + self.dna[point1:]<EOL>self.dna = new_dna<EOL>chromosome.dna = other_new_dna<EOL><DEDENT>else:<EOL><INDENT>assert point2 > point1<EOL>self_substr = self.dna[point1:point2 + <NUM_LIT:1>]<EOL>other_substr = chromosome.dna[point1:point2 + <NUM_LIT:1>]<EOL>self.dna = self.dna[:point1] + other_substr + self.dna[point2 + <NUM_LIT:1>:]<EOL>chromosome.dna = chromosome.dna[:point1] + self_substr + chromosome.dna[point2 + <NUM_LIT:1>:]<EOL><DEDENT>
Exchange DNA with another chromosome of equal length at one or two common points.

For example, consider chromosomes:
  1. 11110000
  2. 00001111

If the crossover point is 4, the exchange results in a new DNA arrangement:
  1. 11111111
  2. 00000000

If 2 points are used--3 and 6--this happens:

  1. 11001100
  2. 00110011

chromosome:  other ``Chromosome`` to exchange DNA with
point1:  zero-based index used for the first (and possibly only) crossover point
point2:  zero-based index used for the second (optional) crossover point; must be > point1