Logo Search packages:      
Sourcecode: python-biopython version File versions

def test_GAQueens::QueensCrossover::_find_best_region (   self,
  genome,
  make_best_larger = 1 
) [private]

Find the best region in the given genome.

Arguments:

o genome -- A MutableSeq object specifying the genome of an organism

o make_best_larger -- A flag to determine whether the best region
we should search for should be the larger region of the split
caused by crossover or the smaller region. This makes it easy
to split two genomes, recombine them, and get a solution that
makes sense.

Returns:
o Two MutableSeq objects. They are both half of the size of the passed
genome. The first is the highest fitness region of the genome and the
second is the rest of the genome.

Definition at line 304 of file test_GAQueens.py.

00304                                                              :
        """Find the best region in the given genome.

        Arguments:

        o genome -- A MutableSeq object specifying the genome of an organism

        o make_best_larger -- A flag to determine whether the best region
        we should search for should be the larger region of the split
        caused by crossover or the smaller region. This makes it easy
        to split two genomes, recombine them, and get a solution that
        makes sense.

        Returns:
        o Two MutableSeq objects. They are both half of the size of the passed
        genome. The first is the highest fitness region of the genome and the
        second is the rest of the genome.
        """
        first_region = max(len(genome) / 2, self._max_crossover_size)
        second_region = len(genome) - first_region
        
        if make_best_larger:
            region_size = max(first_region, second_region)
        else:
            region_size = min(first_region, second_region)

        # loop through all of the segments and find the best fitness segment
        
        # represent best_fitness as a three tuple with the coordinates of
        # the start and end as the first two elements, and the fitness of
        # the region as the last element. Start with a value that
        # will overridden right away
        best_fitness = [0, 0, -1]
        for start_index in range(len(genome) - region_size):
            region_fitness = \
             self._fitness_calc(genome[start_index: start_index + region_size])

            if region_fitness > best_fitness[2]:
                best_fitness = [start_index, start_index + region_size,
                                region_fitness]

        # get the the two regions and return 'em
        best_region = genome[best_fitness[0]:best_fitness[1]]
        rest_region = genome[0:best_fitness[0]] + genome[best_fitness[1]:]

        return best_region, rest_region
            

class QueensMutation:


Generated by  Doxygen 1.6.0   Back to index