Package pygene :: Module organism :: Class Organism
[show private | hide private]
[frames | no frames]

Type Organism

object --+        
         |        
PGXmlMixin --+    
             |    
  BaseOrganism --+
                 |
                Organism


Simple genetic algorithms organism

Contains only single genes, not pairs (ie, single-helix)

Note - all organisms are hermaphrodites, which can reproduce by mating with another. In this implementation, there is no gender.

Class variables (to override) are: Python operators supported:
Method Summary
  __init__(self, **kw)
Initialises this organism randomly, or from a set of named gene keywords
  __getitem__(self, item)
allows shorthand for querying the phenotype of this organism
  copy(self)
returns a deep copy of this organism
  dump(self)
Produce a detailed human-readable report on this organism, its genotype and phenotype
  mate(self, partner)
Mates this organism with another organism to produce two entirely new organisms via random choice of genes from this or the partner
  mutate(self)
Implement the mutation phase, invoking the stochastic mutation method on each component gene
  phenotype(self, geneName)
Returns the phenotype resulting from a given gene, OR the total phenotype resulting from all the genes
  xmlDumpSelf(self, doc, parent)
Dumps out this object's contents into an xml tree
    Inherited from BaseOrganism
  __add__(self, partner)
Allows '+' operator for sexual reproduction
  __cmp__(self, other)
Convenience method which invokes duel
  __repr__(self)
Delivers a minimal string representation of this organism.
  duel(self, opponent)
Duels this organism against an opponent
  fitness(self)
Return the fitness level of this organism, as a float
  xmlDumpAttribs(self, elem)
Dump out the custom attributes of this organism
    Inherited from PGXmlMixin
  xmlDump(self, fileobj)
Dumps out the population to an open file in XML format.
  xmlDumpClass(self, tag)
dumps out class information
  xmlDumps(self)
dumps out to xml, returning a string of the raw generated xml
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
float crossoverRate = 0.5                                                                   
dict genome = {}
bool mutateOneOnly = False

Method Details

__init__(self, **kw)
(Constructor)

Initialises this organism randomly, or from a set of named gene keywords

Arguments:
  • gamete1, gamete2 - a pair of gametes from which to take the genes comprising the new organism. May be omitted.
Keywords:
  • keyword names are gene names within the organism's genome, and values are either:
    • instances of a Gene subclass, or
    • a Gene subclass (in which case the class will be instantiated to form a random gene object)
Any gene names in the genome, which aren't given in the constructor keywords, will be added as random instances of the respective gene class. (Recall that all Gene subclasses can be instantiated with no arguments to create a random valued gene).
Overrides:
__builtin__.object.__init__

__getitem__(self, item)
(Indexing operator)

allows shorthand for querying the phenotype of this organism

copy(self)

returns a deep copy of this organism

dump(self)

Produce a detailed human-readable report on this organism, its genotype and phenotype
Overrides:
pygene.organism.BaseOrganism.dump

mate(self, partner)

Mates this organism with another organism to produce two entirely new organisms via random choice of genes from this or the partner
Overrides:
pygene.organism.BaseOrganism.mate

mutate(self)

Implement the mutation phase, invoking the stochastic mutation method on each component gene

Does not affect this organism, but returns a mutated copy of it
Overrides:
pygene.organism.BaseOrganism.mutate

phenotype(self, geneName=None)

Returns the phenotype resulting from a given gene, OR the total phenotype resulting from all the genes

tries to invoke a child class' method called 'phen_<name>'

xmlDumpSelf(self, doc, parent)

Dumps out this object's contents into an xml tree

Arguments:
  • doc - an xml.dom.minidom.Document object
  • parent - an xml.dom.minidom.Element parent, being the node into which this node should be placed
Overrides:
pygene.organism.BaseOrganism.xmlDumpSelf

Class Variable Details

crossoverRate

Type:
float
Value:
0.5                                                                   

genome

Type:
dict
Value:
{}                                                                     

mutateOneOnly

Type:
bool
Value:
False                                                                  

Generated by Epydoc 2.1 on Mon Dec 12 14:37:12 2005 http://epydoc.sf.net