# `G2DList` – the 2D list chromosome

This is the 2D List representation, this list can carry real numbers or integers or any kind of object, by default, we have genetic operators for integer and real lists, which can be found on the respective modules. This chromosome class extends the `GenomeBase.GenomeBase`.

## Default Parameters

Initializator

> `Initializators.G2DListInitializatorInteger()`

> The Integer Initializator for G2DList

Mutator

> `Mutators.G2DListMutatorSwap()`

> The Swap Mutator for G2DList

Crossover

> `Crossovers.G2DListCrossoverUniform()`

> The Uniform Crossover for G2DList

## Class

class `G2DList.``G2DList`(height, width, cloning=False)

  G2DList Class - The 2D List chromosome representation

  Inheritance diagram for `G2DList.G2DList`:

  Examples

  > The instantiation

  >       >>> genome = G2DList.G2DList(10, 10)

  > Compare

  >       >>> genome2 = genome1.clone()
  >       >>> genome2 == genome1
  >       True

  > Iteration

  >       >>> for row in genome:
  >       >>>   print row
  >       [1, 3, 4, 1]
  >       [7, 5, 3, 4]
  >       [9, 0, 1, 2]

  > Size, slice, get/set, append

  >       >>> len(genome)
  >       3
  >       >>> genome
  >       (...)
  >       [1, 3, 4, 1]
  >       [7, 5, 3, 4]
  >       [9, 0, 1, 2]
  >       >>> genome[1][2]
  >       3
  >       >>> genome[1] = [666, 666, 666, 666]
  >       >>> genome
  >       (...)
  >       [1, 3, 4, 1]
  >       [666, 666, 666, 666]
  >       [9, 0, 1, 2]
  >       >>> genome[1][1] = 2
  >       (...)

  Parameters:

  - height – the number of rows
  - width – the number of columns

  `clearList`()

    Remove all genes from Genome

  `clone`()

    Return a new instace copy of the genome

    Return type: | the G2DList clone instance

  `copy`(g)

    Copy genome to ‘g’

    Example:

          >>> genome_origin.copy(genome_destination)

    Parameters: | g – the destination G2DList instance

  `crossover` = None

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

        genome.crossover.set(Crossovers.G2DListCrossoverSingleHPoint)

  `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

  `getHeight`()

    Return the height (lines) of the List

  `getItem`(x, y)

    Return the specified gene of List

    Example:

          >>> genome.getItem(3, 1)
          666
          >>> genome[3][1]

    Parameters:

    - x – the x index, the column
    - y – the y index, the row

    Return type: | the item at x,y position

  `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

  `getSize`()

    Returns a tuple (height, widht)

    Example:

          >>> genome.getSize()
          (3, 2)

  `getWidth`()

    Return the width (lines) of the List

  `initializator` = None

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

        genome.initializator.set(Initializators.G2DListInitializatorAllele)

    In this example, the initializator `Initializators.G2DListInitializatorAllele()` 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.G2DListMutatorIntegerGaussian)

  `resetStats`()

    Clear score and fitness of genome

  `resumeString`()

    Returns a resumed string representation of the Genome

    New in version 0.6: The resumeString method.

  `setItem`(x, y, value)

    Set the specified gene of List

    Example:

          >>> genome.setItem(3, 1, 666)
          >>> genome[3][1] = 666

    Parameters:

    - x – the x index, the column
    - y – the y index, the row
    - value – the value

  `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