ó
X<c           @   s9   d  Z  d d l Z d d l m Z d d d „  ƒ  YZ d S(   sŽ   General functionality for crossover that doesn't apply.

This collects Crossover stuff that doesn't deal with any specific
type of crossover.
iÿÿÿÿN(   t   Organismt   SafeFitnessCrossoverc           B   s#   e  Z d  Z d d „ Z d „  Z RS(   s4  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 
    g        c         C   s%   | |  _  | |  _ t j ƒ  |  _ d S(   sg  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.
        N(   t
   _crossovert   _accept_less_percentt   randomt   Randomt   _accept_less_rand(   t   selft   actual_crossovert   accept_less(    (    s‹   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/GA/Crossover/General.pyt   __init__   s    		c   	      C   sÓ   |  j  j | | ƒ \ } } g  } x | | f | | f f D]s \ } } | j ƒ  | j | j k r  |  j j ƒ  } | |  j k r | j | ƒ q­ | j | ƒ q: | j | ƒ q: Wt | ƒ d k sÏ t	 d ƒ ‚ | S(   s;   Perform a safe crossover between the two organism.
        i   s$   Should have two organisms to return.(
   R   t   do_crossovert   recalculate_fitnesst   fitnessR   R   R   t   appendt   lent   AssertionError(	   R   t   org_1t   org_2t	   new_org_1t	   new_org_2t   return_orgst	   start_orgt   new_orgt   accept_change(    (    s‹   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/GA/Crossover/General.pyR   $   s    
(   t   __name__t
   __module__t   __doc__R
   R   (    (    (    s‹   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/GA/Crossover/General.pyR      s   (    (   R   R   t   Bio.GA.OrganismR    R   (    (    (    s‹   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/GA/Crossover/General.pyt   <module>   s   