Back to index

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

List of all members.

Public Member Functions

def __init__
def do_crossover

Private Attributes

 _crossover
 _accept_less_percent
 _accept_less_rand

Detailed Description

Perform crossovers, but do not allow decreases in organism fitness.

This doesn't actually do any crossover work, but instead relies on
another class to do the crossover and just checks that newly created
organisms do not have less fitness. This is useful for cases where
crossovers can 

Definition at line 12 of file General.py.


Constructor & Destructor Documentation

def Bio.GA.Crossover.General.SafeFitnessCrossover.__init__ (   self,
  actual_crossover,
  accept_less = 0.0 
)
Initialize to do safe crossovers.

Arguments:

o actual_crossover - A Crossover class which actually implements
crossover functionality.

o accept_less - A probability to accept crossovers which
generate less fitness. This allows you to accept some
crossovers which reduce fitness, but not all of them.

Definition at line 20 of file General.py.

00020 
00021     def __init__(self, actual_crossover, accept_less = 0.0):
00022         """Initialize to do safe crossovers.
00023 
00024         Arguments:
00025 
00026         o actual_crossover - A Crossover class which actually implements
00027         crossover functionality.
00028 
00029         o accept_less - A probability to accept crossovers which
00030         generate less fitness. This allows you to accept some
00031         crossovers which reduce fitness, but not all of them.
00032         """
00033         self._crossover = actual_crossover
00034         self._accept_less_percent = accept_less
00035         self._accept_less_rand = random.Random()

Here is the caller graph for this function:


Member Function Documentation

def Bio.GA.Crossover.General.SafeFitnessCrossover.do_crossover (   self,
  org_1,
  org_2 
)
Perform a safe crossover between the two organism.

Definition at line 36 of file General.py.

00036 
00037     def do_crossover(self, org_1, org_2):
00038         """Perform a safe crossover between the two organism.
00039         """
00040         new_org_1, new_org_2 = self._crossover.do_crossover(org_1, org_2)
00041 
00042         return_orgs = []
00043 
00044         for start_org, new_org in ((org_1, new_org_1),
00045                                    (org_2, new_org_2)):
00046             new_org.recalculate_fitness()
00047 
00048             # if the starting organism has a better fitness,
00049             # keep it, minding the acceptance of less favorable change policy
00050             if start_org.fitness > new_org.fitness:
00051                 accept_change = self._accept_less_rand.random()
00052                 if accept_change <= self._accept_less_percent:
00053                     return_orgs.append(new_org)
00054                 else:
00055                     return_orgs.append(start_org)
00056             else:
00057                 return_orgs.append(new_org)
00058 
00059         assert len(return_orgs) == 2, "Should have two organisms to return."
00060 
00061         return return_orgs

Member Data Documentation

Definition at line 33 of file General.py.

Definition at line 34 of file General.py.

Definition at line 32 of file General.py.


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