G1DBinaryString – the classical binary string chromosome

This is the classical chromosome representation on GAs, it is the 1D Binary String. This string looks like “00011101010”.

class G1DBinaryString.G1DBinaryString(length=10)

G1DBinaryString Class - The 1D Binary String chromosome

Example:
>>> g = G1DBinaryString(5)
Parameter:length – the 1D Binary String size
append(value)

Appends an item to the list

Example:
>>> g = G1DBinaryString(2)
>>> g.append(0)
Parameter:value – value to be added, 0 or 1
clearString()
Remove all genes from Genome
clone()

Return a new instace copy of the genome

Example:
>>> g = G1DBinaryString(5)
>>> for i in xrange(len(g)):
...    g.append(1)
>>> clone = g.clone()
>>> clone[0]
1
Return type:the G1DBinaryString instance clone
copy(g)

Copy genome to ‘g’

Example:
>>> g1 = G1DBinaryString(2)
>>> g1.append(0)
>>> g1.append(1)
>>> g2 = G1DBinaryString(2)
>>> g1.copy(g2)
>>> g2[1]
1
Parameter:g – the destination genome
crossover

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

genome.crossover.set(Crossovers.G1DBinaryStringXUniform)
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)
getBinary()

Returns the binary string representation

Example:
>>> g = G1DBinaryString(2)
>>> g.append(0)
>>> g.append(1)
>>> g.getBinary()
'01'
Return type:the binary string
getDecimal()

Converts the binary string to decimal representation

Example:
>>> g = G1DBinaryString(5)
>>> for i in xrange(len(g)):
...    g.append(0)
>>> g[3] = 1
>>> g.getDecimal()
2
Return type:decimal value
getFitnessScore()

Get the Fitness Score of the genome

Return type:genome fitness score
getParam(key, nvl=None)

Gets an initialization parameter

Example:
>>> genome.getParam("rangemax")
100
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.G1DBinaryStringInitializator)

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
mutator

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

genome.mutator.set(Mutators.G1DBinaryStringMutatorSwap)
resetStats()
Clear score and fitness of genome
setParams(**args)

Set the initializator params

Example:
>>> genome.setParams(rangemin=0, rangemax=100, gauss_mu=0, gauss_sigma=1)
Parameter:args – this params will saved in every chromosome for genetic op. use

Recent Blog Posts

Previous topic

GAllele – the genome alleles module

Next topic

G1DList – the 1D list chromosome

This Page