The very first thing we need to do is specify a data-structure for storing our genetic information.
In biology chromosomes are composed of sequences of genes.
In biology, chromosomes are composed of sequences of genes.
Many people run genetic algorithms on binary arrays since they more closely represent DNA.
However, as computer scientists, it is often easier to model things as continuous numbers.
In this approach, every Gene will be a single floating point number ranging between zero and one.
This keeps things really easy because it is very simple perform any genetic "operation".
Every type of Gene will have a max and min value which represents the absolute extremes of that gene.
However, as computer scientists, it is often easier to model problems using continuous numbers.
In this approach, every gene will be a single floating point number ranging between zero and one.
Every type of gene will have a max and min value which represents the absolute extremes of that gene.
This works well for optimization because it allows us to easily limit our search space.
For example, we can specify that "height" gene can only vary between 0 and 90.
To get the actual value of the gene from its \[0-1] value we simple de-normalize it.
@ -89,16 +87,17 @@ class Gene
```
Now that we have genes, we can create Chromosomes.
Now that we have genes, we can create chromosomes.
Chromosomes are simply collections of genes.
Whatever language you make this in, make sure that when you create a new Chromosome it
is has a [deep copy](https://en.wikipedia.org/wiki/Object_copying) of the genetic information rather than a shallow copy.
A shallow copy is when you simple copy the object pointer where a deep copy is actually creating a full new object.
If you fail to do a deep copy, you will have weird issues where multiple Chromosomes will share the same DNA.
Whatever language you make this in, make sure that when you create a new chromosome it
is has a [deep copy](https://en.wikipedia.org/wiki/Object_copying) of the original genetic information rather than a shallow copy.
A shallow copy is when you simple copy the object pointer where a deep copy is actually creating a new object.
If you fail to do a deep copy, you will have weird issues where multiple chromosomes will share the same DNA.
In this class I added helper functions to clone and create a new Chromosome.
In this class I added helper functions to clone the chromosome as a random copy.
You can only create a new chromosome by cloning because I wanted to keep the program generic and make no assumptions about the domain.
Since you only provide the min/max information for the genes once, cloning an existing chromosome is the easy way of ensuring that all chromosomes contain similarly behaved genes.
Since you only provide the min/max information for the genes once, cloning an existing chromosome is the easiest way of
ensuring that all corresponding chromosomes contain genes with identical extrema.
```javascript
@ -149,7 +148,7 @@ class Chromosome
}
```
Creating a random population is pretty straight forward if implemented this method of random cloning in the Chromosome and Gene class.
Creating a random population is pretty straight forward if implemented a method to create a random clone of a chromosome.