Академический Документы
Профессиональный Документы
Культура Документы
Page 1 of 6
Page 2 of 6
The shape
The skin covering
The tail
In this case, 0 indicates that the sheep is round and 1 indicates it is rectangular; 0 indicates the sheep is
woolly whereas 1 indicates it is bald; 0 indicates the sheep has a tail whereas 1 indicates its absence.
Thus
0
is the gene for a sheep with two round legs, one woolly and one bald; and two square legs, one bald and
one woolly.
The genotype of my sheep consists of the three chromosomes given above represented as
We now want to breed beautiful sheep. These we have decided (in actual fact it is the sheep that
ultimately decide) are round and woolly and have a tail. Thus the genotype for the most beautiful sheep
is
1
Let this be a warning to all those amongst you that do not wash behind their ears.
Page 3 of 6
Finally we have to decide how to measure beautiful sheep in a quantitative way. This is performed by a
fitness function (defined on chromosomes and genotypes). The following is the code for the fitness
function that I have adopted for each chromosome. The fitness function is found in the Environment
class.
fitness(i) returns the fitness of the ith chromosome in the genotype.
public int fitness(int i){
int result = 0;
switch (i){
case 0: for (int j = 0; j < this.genes; j++){
if (this.chromosome.charAt(j) == '1'){
result++;
} // if
}// for j
return result;
case 1: for (int j = 0; j < this.genes; j++){
if (this.chromosome.charAt(j) == '0'){
result++;
} // if
}// for j
return result;
case 2: for (int j = 0; j < this.genes-1; j++){
if (j%2 == 0){
if (this.chromosome.charAt(j) == '1'){
result++;
} // if
} else {
if (this.chromosome.charAt(j) == '0'){
result++;
} // if
} // if
} // for
return result;
default: return 1;
} // switch
} // fitness
// skin covering
Page 4 of 6
Page 5 of 6
Generations = 32
Genetic Mutation = 0.1
Page 6 of 6