Crossover and Mutation The two main operations in evolutionary computing are crossover and mutation. Crossover works like this: Randomly choose two parents from the population. Let’s say these: Parent 1: T F T F T T F Parent 2: T T T F F T T Those two parents will create a child whose DNA is related to the parents’. It works like this: for each of the seven genes in the chromosome, we will randomly pick a number between 1 and 10 and use it to choose which parents’ value the child will get. If the random number is 1 through 5, we will use Parent 1’s included value for the child; if it is 6 through 10, we’ll use Parent 2’s. Let’s assume our seven random numbers are: 1 4 10 3 6 6 9 Then the child’s set of item included =ields would be: Child: T F T F F T T Mutation is even simpler: we choose a single individual from our population and again generate a random number between 1 and 10 for each nucleotide. Mutation generally happens more rarely than reproduction, so if the random number is 1, we will =lip that gene in the individual; otherwise, we will leave it the same. Let’s assume our seven random numbers are: 5 1 7 8 9 2 7 and the chosen individual’s included values are: T T F T T T F Then after mutation, that individual now looks like this (with the second gene =lipped from a T to a F): T F F T T T F public class Chromosome extends ArrayList implements Comparable private static Random rng Used for random number generation public Chromosome() This no-arg constructor can be empty public Chromosome(ArrayList items) Adds a copy of each of the items passed in to this Chromosome. Uses a random number to decide whether each item’s included Field is set to true or false.
Crossover and Mutation
The two main operations in evolutionary computing are crossover and mutation. Crossover
works like this:
Randomly choose two parents from the population. Let’s say these:
Parent 1: T F T F T T F
Parent 2: T T T F F T T
Those two parents will create a child whose DNA is related to the parents’. It works like
this: for each of the seven genes in the chromosome, we will randomly pick a number
between 1 and 10 and use it to choose which parents’ value the child will get. If the random
number is 1 through 5, we will use Parent 1’s included value for the child; if it is 6 through
10, we’ll use Parent 2’s. Let’s assume our seven random numbers are:
1 4 10 3 6 6 9
Then the child’s set of item included =ields would be:
Child: T F T F F T T
Mutation is even simpler: we choose a single individual from our population and again
generate a random number between 1 and 10 for each nucleotide. Mutation generally
happens more rarely than reproduction, so if the random number is 1, we will =lip that gene
in the individual; otherwise, we will leave it the same. Let’s assume our seven random
numbers are:
5 1 7 8 9 2 7
and the chosen individual’s included values are:
T T F T T T F
Then after mutation, that individual now looks like this (with the second gene =lipped from
a T to a F):
T F F T T T F
public class Chromosome extends ArrayList implements Comparable private static Random rng Used for random number generation public Chromosome() This no-arg constructor can be empty public Chromosome(ArrayList items) Adds a copy of each of the items passed in to this Chromosome. Uses a random number to decide whether each item’s included Field is set to true or false.

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images









