G1DList – the 1D list chromosome

This is the 1D 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.

Default Parameters

Initializator

Initializators.G1DListInitializatorInteger()

The Integer Initializator for G1DList

Mutator

Mutators.G1DListMutatorSwap()

The Swap Mutator for G1DList

Crossover

Crossovers.G1DListCrossoverSinglePoint()

The Single Point Crossover for G1DList

Class

class G1DList.G1DList(size=10, cloning=False)

G1DList Class - The 1D List chromosome representation

Inheritance diagram for G1DList.G1DList:

Inheritance diagram of G1DList.G1DList

This chromosome class extends the GenomeBase.GenomeBase and GenomeBase.G1DBase classes.

Examples

The instantiation
>>> g = G1DList(10)
Compare
>>> genome2 = genome1.clone()
>>> genome2 == genome1
True
Multiply
>>> genome = population[0]
>>> genome
(...)
[1, 2, 3, 4]
>>> genome_result = genome * 2
>>> genome_result
(...)
[2, 2, 6, 8]
Add
>>> genome
(...)
[1, 2, 3, 4]
>>> genome_result = genome + 2
(...)
[3, 4, 5, 6]
Iteration
>>> for i in genome:
>>>   print i
1
2
3
4
Size, slice, get/set, append
>>> len(genome)
4
>>> genome
(...)
[1, 2, 3, 4]
>>> genome[0:1]
[1, 2]
>>> genome[1] = 666
>>> genome
(...)
[1, 666, 3, 4]
>>> genome.append(99)
>>> genome
(...)
[1, 666, 3, 4, 99]
Parameter:size – the 1D list size
append(value)

Appends an item to the end of the list

Example:
>>> genome.append(44)
Parameter:value – value to be added
clearList()
Remove all genes from Genome
clone()

Return a new instace copy of the genome

Return type:the G1DList clone instance
copy(g)

Copy genome to ‘g’

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

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

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

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

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

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.G1DListMutatorSwap)
remove(value)

Removes an item from the list

Example:
>>> genome.remove(44)
Parameter:value – value to be added
resetStats()
Clear score and fitness of genome
resumeString()
Returns a resumed string representation of the Genome
setInternalList(lst)

Assigns a list to the internal list of the chromosome

Parameter:lst – the list to assign the internal list of the chromosome
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


Table Of Contents

Previous topic

G2DBinaryString – the classical binary string chromosome

Next topic

G2DList – the 2D list chromosome

This Page