Suppose a genetic algorithm uses chromosomes of the form x = abcdefgh with a fixed length of eight genes. Each gene can be any digit between 0 and 9. Let the fitness of individual x be calculated as:
f(x) = (a + b) − (c + d) + (e + f) − (g + h) ,
and let the initial population consist of four individuals with the following chromosomes:
x1 = 6 5 4 1 3 5 3 2
x2 = 8 7 1 2 6 6 0 1
x3 = 2 3 9 2 1 2 8 5
x4 = 4 1 8 5 2 0 9 4
Write your program into the following smaller pieces and test each of the functions listed below separately:
• randomNumber(length) returns a random genome number of a given length.
• makePopulation(size, length) returns a new randomly created population of the specified size, represented as a list of genomes of the specified length.
• fitness(genome) returns the fitness value of a genome.
• evaluateFitness(population) returns a pair of values: the average fitness of the population as a whole and the fitness of the best individual in the population. Arrange them in order with the fittest first and the least fit last.
SUBMISSION
Java Coding
Output
Please submit your github link ONLY for posting here
INSTRUCTION
A192 - TEST LAB 1 – STIN3084 - 5 JULY 2020
Suppose a genetic algorithm uses chromosomes of the form x = abcdefgh with a fixed length of eight genes. Each gene can be any digit between 0 and 9. Let the fitness of individual x be calculated as: f(x) = (a + b) − (c + d) + (e + f) − (g + h) , and let the initial population consist of four individuals with the following chromosomes: x1 = 6 5 4 1 3 5 3 2 x2 = 8 7 1 2 6 6 0 1 x3 = 2 3 9 2 1 2 8 5 x4 = 4 1 8 5 2 0 9 4
Write your program into the following smaller pieces and test each of the functions listed below separately: • randomNumber(length) returns a random genome number of a given length. • makePopulation(size, length) returns a new randomly created population of the specified size, represented as a list of genomes of the specified length. • fitness(genome) returns the fitness value of a genome. • evaluateFitness(population) returns a pair of values: the average fitness of the population as a whole and the fitness of the best individual in the population. Arrange them in order with the fittest first and the least fit last.
SUBMISSION