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”.
Default Parameters¶
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
Class¶
-
class
G1DBinaryString.
G1DBinaryString
(length=10)¶ G1DBinaryString Class - The 1D Binary String chromosome
Inheritance diagram for
G1DBinaryString.G1DBinaryString
:This chromosome class extends the
GenomeBase.GenomeBase
andGenomeBase.G1DBase
classes.- Example:
>>> genome = G1DBinaryString.G1DBinaryString(5)
Parameters: length – the 1D Binary String size -
append
(value)¶ Appends an item to the list
- Example:
>>> g = G1DBinaryString(2) >>> g.append(0)
Parameters: value – value to be added, 0 or 1
-
clearList
()¶ 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
Parameters: g – the destination genome
-
crossover
= None¶ 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
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)
-
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
-
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
= None¶ 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
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.G1DBinaryStringMutatorSwap)
-
remove
(value)¶ Removes an item from the list
- Example:
>>> genome.remove(44)
Parameters: 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
Parameters: 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.
Parameters: args – this params will saved in every chromosome for genetic op. use