Back to index

python-biopython  1.60
Public Member Functions | Private Attributes
Bio.GA.Crossover.Uniform.UniformCrossover Class Reference

List of all members.

Public Member Functions

def __init__
def do_crossover

Private Attributes

 _crossover_prob
 _uniform_prob

Detailed Description

Perform single point crossover between genomes at some defined rates.

This performs a single crossover between two genomes at some
defined frequency. The location of the crossover is chosen randomly
if the crossover meets the probability to occur.

Definition at line 19 of file Uniform.py.


Constructor & Destructor Documentation

def Bio.GA.Crossover.Uniform.UniformCrossover.__init__ (   self,
  crossover_prob = .1,
  uniform_prob = 0.7 
)
Initialize to do uniform crossover at the specified probability and frequency.

Definition at line 26 of file Uniform.py.

00026 
00027     def __init__(self, crossover_prob = .1, uniform_prob = 0.7):
00028         """Initialize to do uniform crossover at the specified probability and frequency.
00029         """
00030         self._crossover_prob = crossover_prob
00031         self._uniform_prob   = uniform_prob
00032         return
        

Here is the caller graph for this function:


Member Function Documentation

def Bio.GA.Crossover.Uniform.UniformCrossover.do_crossover (   self,
  org_1,
  org_2 
)
Potentially do a crossover between the two organisms.

Definition at line 33 of file Uniform.py.

00033 
00034     def do_crossover(self, org_1, org_2):
00035         """Potentially do a crossover between the two organisms.
00036         """
00037         new_org_1 = org_1.copy()
00038         new_org_2 = org_2.copy()
00039         
00040         # determine if we have a crossover
00041         crossover_chance = random.random()
00042         if crossover_chance <= self._crossover_prob:
00043             minlen = min(len(new_org_1.genome),len(new_org_2.genome))
00044             for i in range( minlen ):
00045                 uniform_chance = random.random()
00046                 if uniform_chance <= self._uniform_prob:
00047                     # cycle element
00048                     temp = new_org_1.genome[i]
00049                     new_org_1.genome[i] = new_org_2.genome[i]
00050                     new_org_2.genome[i] = temp
00051             
00052         return new_org_1, new_org_2

Member Data Documentation

Definition at line 29 of file Uniform.py.

Definition at line 30 of file Uniform.py.


The documentation for this class was generated from the following file: