Back to index

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

List of all members.

Public Member Functions

def do_crossover

Private Member Functions

def _generate_locs
def _crossover

Detailed Description

Helper class for Two Point crossovers.

Offers more efficient replacements to the GeneralPoint framework
for single pivot crossovers

Definition at line 139 of file GeneralPoint.py.


Member Function Documentation

def Bio.GA.Crossover.GeneralPoint.TwoCrossover._crossover (   self,
  x,
  no,
  locs 
) [private]
Replacement crossover
 
   see GeneralPoint._crossover documentation for details

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

Definition at line 152 of file GeneralPoint.py.

00152 
00153     def _crossover( self, x, no, locs ):
00154         """Replacement crossover
00155          
00156            see GeneralPoint._crossover documentation for details
00157         """
00158         y = (x+1)%2
00159         return no[x].genome[ : locs[x][1] ] + no[y].genome[ locs[y][1] : ]

def Bio.GA.Crossover.GeneralPoint.TwoCrossover._generate_locs (   self,
  bound 
) [private]
Replacement generation.
 
See GeneralPoint._generate_locs documentation for details

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

Definition at line 145 of file GeneralPoint.py.

00145 
00146     def _generate_locs(self, bound):
00147         """Replacement generation.
00148          
00149         See GeneralPoint._generate_locs documentation for details
00150         """
00151         return [0, random.randint(1,bound-1), bound]
    
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: