### Navigation

- index
- modules |
- next |
- previous |
- Pyevolve 0.6 final documentation »
- Modules »
- `pyevolve` – the main pyevolve namespace »

# `GenomeBase` – the genomes base module

This module have the class which every representation extends, if you are planning to create a new representation, you must take a inside look into this module.

class `GenomeBase.``G1DBase`(size)

  G1DBase Class - The base class for 1D chromosomes

  Parameters: | size – the 1D list size

  New in version 0.6: Added te G1DBase class

  `append`(value)

    Appends an item to the end of the list

    Example:

          >>> genome.append(44)

    Parameters: | value – value to be added

  `clearList`()

    Remove all genes from Genome

  `copy`(g)

    Copy genome to ‘g’

    Example:

          >>> genome_origin.copy(genome_destination)

    Parameters: | g – the destination instance

  `getInternalList`()

    Returns the internal list of the genome

    ... note:: this method was created to solve performance issues :rtype: the internal list

  `getListSize`()

    Returns the list supposed size

    Warning

    this is different from what the len(obj) returns

  `remove`(value)

    Removes an item from the list

    Example:

          >>> genome.remove(44)

    Parameters: | value – value to be added

  `resumeString`()

    Returns a resumed string representation of the Genome

  `setInternalList`(lst)

    Assigns a list to the internal list of the chromosome

    Parameters: | lst – the list to assign the internal list of the chromosome

class `GenomeBase.``GTreeBase`(root_node)

  GTreeBase Class - The base class for the tree genomes

  Parameters: | root_node – the root node of the tree

  New in version 0.6: Added te GTreeBase class

  `clone`()

    Clone this GenomeBase

    Return type: | the clone genome

    Note

    If you are planning to create a new chromosome representation, you must implement this method on your class.

  `copy`(g, node=None, node_parent=None)

    Copy the current contents GTreeBase to ‘g’

    Parameters: | g – the destination GTreeBase tree

    Note

    If you are planning to create a new chromosome representation, you must implement this method on your class.

  `getAllNodes`()

    Return a new list with all nodes

    Return type: | the list with all nodes

  `getHeight`()

    Return the tree height

    Return type: | the tree height

  `getNodeDepth`(node)

    Returns the depth of a node

    Return type: | the depth of the node, the depth of root node is 0

  `getNodeHeight`(node)

    Returns the height of a node

    Note

    If the node has no childs, the height will be 0.

    Return type: | the height of the node

  `getNodesCount`(start_node=None)

    Return the number of the nodes on the tree starting at the start_node, if start_node is None, then the method will count all the tree nodes.

    Return type: | the number of nodes

  `getRandomNode`(node_type=0)

    Returns a random node from the Tree

    Parameters: | node_type – 0 = Any, 1 = Leaf, 2 = Branch
    Return type: | random node

  `getRoot`()

    Return the tree root node

    Return type: | the tree root node

  `getTraversalString`(start_node=None, spc=0)

    Returns a tree-formated string of the tree. This method is used by the __repr__ method of the tree

    Return type: | a string representing the tree

  `processNodes`(cloning=False)

    Creates a cache on the tree, this method must be called every time you change the shape of the tree. It updates the internal nodes list and the internal nodes properties such as depth and height.

  `setRoot`(root)

    Sets the root of the tree

    Parameters: | root – the tree root node

  `traversal`(callback, start_node=None)

    Traversal the tree, this method will call the user-defined callback function for each node on the tree

    Parameters:

    - callback – a function
    - start_node – the start node to begin the traversal

class `GenomeBase.``GTreeNodeBase`(parent, childs=None)

  GTreeNodeBase Class - The base class for the node tree genomes

  Parameters:

  - parent – the parent node of the node
  - childs – the childs of the node, must be a list of nodes

  New in version 0.6: Added te GTreeNodeBase class

  `addChild`(child)

    Adds a child to the node

    Parameters: | child – the node to be added

  `clone`()

    Clone this GenomeBase

    Return type: | the clone genome

    Note

    If you are planning to create a new chromosome representation, you must implement this method on your class.

  `copy`(g)

    Copy the current contents GTreeNodeBase to ‘g’

    Parameters: | g – the destination node

    Note

    If you are planning to create a new chromosome representation, you must implement this method on your class.

  `getChild`(index)

    Returns the index-child of the node

    Return type: | child node

  `getChilds`()

    Return the childs of the node

    Warning

    use .getChilds()[:] if you’ll change the list itself, like using childs.reverse(), otherwise the original genome child order will be changed.

    Return type: | a list of nodes

  `getParent`()

    Get the parent node of the node

    Return type: | the parent node

  `isLeaf`()

    Return True if the node is a leaf

    Return type: | True or False

  `replaceChild`(older, newer)

    Replaces a child of the node

    Parameters:

    - older – the child to be replaces
    - newer – the new child which replaces the older

  `setParent`(parent)

    Sets the parent of the node

    Parameters: | parent – the parent node

class `GenomeBase.``GenomeBase`

  GenomeBase Class - The base of all chromosome representation

  `clone`()

    Clone this GenomeBase

    Return type: | the clone genome

    Note

    If you are planning to create a new chromosome representation, you must implement this method on your class.

  `copy`(g)

    Copy the current GenomeBase to ‘g’

    Parameters: | g – the destination genome

    Note

    If you are planning to create a new chromosome representation, you must implement this method on your class.

  `crossover` = None

    This is the reproduction function slot, the crossover. You can change the default crossover method using:

        genome.crossover.set(Crossovers.G1DListCrossoverUniform)

  `evaluate`(**args)

    Called to evaluate genome

    Parameters: | args – this parameters will be passes to the evaluator

  `evaluator` = None

    This is the evaluation function slot, you can add a function with the set method:

        genome.evaluator.set(eval_func)

  `getFitnessScore`()

    Get the Fitness Score of the genome

    Return type: | genome fitness score

  `getParam`(key, nvl=None)

    Gets an internal parameter

    Example:

          >>> genome.getParam("rangemax")
          100

    Note

    All the individuals of the population shares this parameters and uses the same instance of this dict.

    Parameters:

    - key – the key of param
    - nvl – if the key doesn’t exist, the nvl will be returned

  `getRawScore`()

    Get the Raw Score of the genome

    Return type: | genome raw score

  `initializator` = None

    This is the initialization function of the genome, you can change the default initializator using the function slot:

        genome.initializator.set(Initializators.G1DListInitializatorAllele)

    In this example, the initializator `Initializators.G1DListInitializatorAllele()` will be used to create the initial population.

  `initialize`(**args)

    Called to initialize genome

    Parameters: | args – this parameters will be passed to the initializator

  `mutate`(**args)

    Called to mutate the genome

    Parameters: | args – this parameters will be passed to the mutator
    Return type: | the number of mutations returned by mutation operator

  `mutator` = None

    This is the mutator function slot, you can change the default mutator using the slot set function:

        genome.mutator.set(Mutators.G1DListMutatorSwap)

  `resetStats`()

    Clear score and fitness of genome

  `setParams`(**args)

    Set the internal params

    Example:

          >>> genome.setParams(rangemin=0, rangemax=100, gauss_mu=0, gauss_sigma=1)

    Note

    All the individuals of the population shares this parameters and uses the same instance of this dict.

    Parameters: | args – this params will saved in every chromosome for genetic op. use

### Navigation

- index
- modules |
- next |
- previous |
- Pyevolve 0.6 final documentation »
- Modules »
- `pyevolve` – the main pyevolve namespace »