This is the classical chromosome representation on GAs, it is the 1D Binary String. This string looks like “00011101010”.
G1DBinaryString Class - The 1D Binary String chromosome
>>> g = 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 |
---|
Gets an initialization parameter
>>> genome.getParam("rangemax")
100
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 |
---|
This is the mutator function slot, you can change the default mutator using the slot set function:
genome.mutator.set(Mutators.G1DBinaryStringMutatorSwap)
Set the initializator params
>>> 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 |
---|