Back to index

python-biopython  1.60
Public Member Functions | Private Member Functions
Bio.GA.Crossover.GeneralPoint.InterleaveCrossover Class Reference
Inheritance diagram for Bio.GA.Crossover.GeneralPoint.InterleaveCrossover:
Inheritance graph
[legend]
Collaboration diagram for Bio.GA.Crossover.GeneralPoint.InterleaveCrossover:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def do_crossover

Private Member Functions

def _generate_locs
def _crossover

Detailed Description

Demonstration class for Interleaving crossover.

Interleaving:  AbCdEfG, aBcDeFg

Definition at line 160 of file GeneralPoint.py.


Constructor & Destructor Documentation

def Bio.GA.Crossover.GeneralPoint.InterleaveCrossover.__init__ (   self,
  crossover_prob = 0.1 
)

Definition at line 165 of file GeneralPoint.py.

00165 
00166     def __init__(self,crossover_prob=0.1):
00167         GeneralPointCrossover.__init__(self,0,crossover_prob)
    

Here is the caller graph for this function:


Member Function Documentation

def Bio.GA.Crossover.GeneralPoint.InterleaveCrossover._crossover (   self,
  x,
  no,
  locs 
) [private]
Generalized Crossover Function:
    
   arguments: 
       x (int)        - genome number [0|1]
       no (organism,organism)
              - new organisms
       locs (int list, int list)
              - lists of locations, 
                [0, +n points+, bound]
                for each genome (sync'd with x)

    return type: sequence (to replace no[x])

Reimplemented from Bio.GA.Crossover.GeneralPoint.GeneralPointCrossover.

Definition at line 171 of file GeneralPoint.py.

00171 
00172     def _crossover( self, x, no, locs ):
00173         s = no[ x ].genome[ 0:1 ]
00174         for n in range(1,self._npoints+2):
00175             mode = ( x+n )%2
00176             s += no[ mode ].genome[ n:n+1 ]
00177         return s+no[mode].genome[self._npoints+3:]
Generalized Location Generator:
    
   arguments:
       bound (int)   - upper bound 
    
   returns: [0]+x_0...x_n+[bound]
     where n=self._npoints-1
       and 0 < x_0 < x_1 ... < bound

Reimplemented from Bio.GA.Crossover.GeneralPoint.GeneralPointCrossover.

Definition at line 168 of file GeneralPoint.py.

00168 
00169     def _generate_locs(self,bound):
00170         return range(-1,bound+1)
    
def Bio.GA.Crossover.GeneralPoint.GeneralPointCrossover.do_crossover (   self,
  org_1,
  org_2 
) [inherited]
Potentially do a crossover between the two organisms.

Definition at line 55 of file GeneralPoint.py.

00055 
00056     def do_crossover(self, org_1, org_2):
00057         """Potentially do a crossover between the two organisms.
00058         """
00059         new_org = ( org_1.copy(), org_2.copy() )
00060         
00061         # determine if we have a crossover
00062         crossover_chance = random.random()
00063         if crossover_chance <= self._crossover_prob:
00064             
00065             # pre-compute bounds (len(genome))
00066             bound  = (len(new_org[0].genome), len(new_org[1].genome))
00067             
00068             mbound = min(bound)
00069             # can't have more than 0,x_0...x_n,bound locations
00070             if (self._npoints == 0 or self._npoints > mbound-2):
00071                 self._npoints = mbound-2
00072                 
00073             y_locs = []
00074             # generate list for the shortest of the genomes
00075             x_locs = self._generate_locs( mbound )
00076 
00077             if (self._sym != 0):  
00078                 y_locs = x_locs
00079             else:
00080                 # figure out which list we've generated 
00081                 # for, and generate the other
00082                 if (mbound == bound[0]):
00083                     y_locs = self._generate_locs( bound[1] )
00084                 else:
00085                     y_locs = x_locs
00086                     xlocs  = self._generate_locs( bound[0] )
00087               
00088             # copy new genome strings over
00089             tmp = self._crossover(0, new_org, (x_locs,y_locs))
00090             new_org[1].genome = self._crossover(1, new_org, (x_locs,y_locs))
00091             new_org[0].genome = tmp
00092 
00093         return new_org

Here is the call graph for this function:


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