G2DBinaryString – the classical binary string chromosome

This representation is a 2D Binary String, the string looks like this matrix:

00101101010 00100011010 00101101010 10100101000

Default Parameters

Initializator

Initializators.G2DBinaryStringInitializator()

The Binatry String Initializator for G2DBinaryString

Mutator

Mutators.G2DBinaryStringMutatorFlip()

The Flip Mutator for G2DBinaryString

Crossover

Crossovers.G2DBinaryStringXSinglePoint()

The Single Point Crossover for G2DBinaryString

New in version 0.6: Added the module G2DBinaryString

Class

class G2DBinaryString.G2DBinaryString(height, width)

G3DBinaryString Class - The 2D Binary String chromosome

Inheritance diagram for G2DBinaryString.G2DBinaryString:

Inheritance diagram of G2DBinaryString.G2DBinaryString

Example:
>>> genome = G2DBinaryString.G2DBinaryString(10, 12)
Parameters:
  • height – the number of rows
  • width – the number of columns
clearString()
Remove all genes from Genome
clone()

Return a new instace copy of the genome

Return type:the G2DBinaryString clone instance
copy(g)

Copy genome to ‘g’

Example:
>>> genome_origin.copy(genome_destination)
Parameter:g – the destination G2DBinaryString instance
crossover

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

genome.crossover.set(Crossovers.G2DBinaryStringXUniform)
evaluate(**args)

Called to evaluate genome

Parameter:args – this parameters will be passes to the evaluator
evaluator

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)
0
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

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

genome.initializator.set(Initializators.G2DBinaryStringInitializator)

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

initialize(**args)

Called to initialize genome

Parameter:args – this parameters will be passed to the initializator
mutate(**args)

Called to mutate the genome

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

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

genome.mutator.set(Mutators.G2DBinaryStringMutatorSwap)
resetStats()
Clear score and fitness of genome
resumeString()
Returns a resumed string representation of the Genome
setItem(x, y, value)

Set the specified gene of List

Example:
>>> genome.setItem(3, 1, 0)
Parameters:
  • x – the x index, the column
  • y – the y index, the row
  • value – the value (integers 0 or 1)
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.

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