This is the classical chromosome representation on GAs, it is the 1D Binary String. This string looks like “00011101010”.
Initializator
Initializators.G1DBinaryStringInitializator()
The Binatry String Initializator for G1DBinaryString
Mutator
Mutators.G1DBinaryStringMutatorFlip()
The Flip Mutator for G1DBinaryString
Crossover
Crossovers.G1DBinaryStringXSinglePoint()
The Single Point Crossover for G1DBinaryString
G1DBinaryString Class - The 1D Binary String chromosome
Inheritance diagram for G1DBinaryString.G1DBinaryString:
This chromosome class extends the GenomeBase.GenomeBase and GenomeBase.G1DBase classes.
>>> genome = G1DBinaryString.G1DBinaryString(5)
Parameter: | length – the 1D Binary String size |
---|
Appends an item to the list
>>> g = G1DBinaryString(2)
>>> g.append(0)
Parameter: | value – value to be added, 0 or 1 |
---|
Return a new instace copy of the genome
>>> 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 genome to ‘g’
>>> g1 = G1DBinaryString(2)
>>> g1.append(0)
>>> g1.append(1)
>>> g2 = G1DBinaryString(2)
>>> g1.copy(g2)
>>> g2[1]
1
Parameter: | g – the destination genome |
---|
This is the reproduction function slot, the crossover. You can change the default crossover method using:
genome.crossover.set(Crossovers.G1DBinaryStringXUniform)
Called to evaluate genome
Parameter: | args – this parameters will be passes to the evaluator |
---|
This is the evaluation function slot, you can add a function with the set method:
genome.evaluator.set(eval_func)
Returns the binary string representation
>>> g = G1DBinaryString(2)
>>> g.append(0)
>>> g.append(1)
>>> g.getBinary()
'01'
Return type: | the binary string |
---|
Converts the binary string to decimal representation
>>> g = G1DBinaryString(5)
>>> for i in xrange(len(g)):
... g.append(0)
>>> g[3] = 1
>>> g.getDecimal()
2
Return type: | decimal value |
---|
Get the Fitness Score of the genome
Return type: | genome fitness score |
---|
Returns the internal list of the genome
... note:: this method was created to solve performance issues :rtype: the internal list
Returns the list supposed size
Warning
this is different from what the len(obj) returns
Gets an internal parameter
>>> genome.getParam("rangemax")
100
Note
All the individuals of the population shares this parameters and uses the same instance of this dict.
Parameters: |
|
---|
Get the Raw Score of the genome
Return type: | genome raw score |
---|
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.
Called to initialize genome
Parameter: | args – this parameters will be passed to the initializator |
---|
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 |
This is the mutator function slot, you can change the default mutator using the slot set function:
genome.mutator.set(Mutators.G1DBinaryStringMutatorSwap)
Removes an item from the list
>>> genome.remove(44)
Parameter: | value – value to be added |
---|
Assigns a list to the internal list of the chromosome
Parameter: | lst – the list to assign the internal list of the chromosome |
---|
Set the internal params
>>> 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 |
---|