3.0 KiB
Genetic Algorithms
Pre-lecture quiz
Genetic Algorithms (GA) are based on evolutionary approach to AI, in which methods of evolution of population is used to obtain an optimal solution for a given problem. They were proposed in 1975 by John Henry Holland.
Genetic Algorithms are based on the following ideas:
- Valid solutions to the problem can be represented as genes
- Crossover allows us to combine two solutions together to obtain new valid solution
- Selection is used to select more optimal solutions using some fitness function
- Mutations are introduced to destabilize optimization and get us out of the local minimum
If you want to implement a Genetic Algorithm, you need the following:
- To find a method of coding our problem solutions using genes g∈Γ
- On the set of genes Γ we need to define fitness function fit: Γ→R. Smaller function values correspond to better solutions.
- To define crossover mechanism to combine two genes together to get a new valid solution crossover: Γ2→Γ.
- To define mutation mechanism mutate: Γ→Γ. In many cases, crossover and mutation are quite simple algorithms to manipulate genes as numeric sequences or bit vectors.
Specific implementation of a genetic algorithm can vary from case to case, but overall structure is the following:
- Select initial population G⊂Γ
- Randomly select one of the operations that will be performed at this step: crossover or mutation
- Crossover:
- Randomly select two genes g1, g2 ∈ G
- Compute crossover g=crossover(g1,g2)
- If fit(g)<fit(g1) or fit(g)<fit(g2) - replace corresponding gene in the population by g.
- Mutation - select random gene g∈G and replace it by mutate(g)
- Repeat from step 2, until we get sufficiently small value of fit, or until the limit on the number of steps is reached.
Typical Tasks
Tasks typically solved by GA:
- Schedule optimization
- Optimal packing
- Optimal cutting
- Speeding up exhaustive search
Notebooks
Go to Genetic.ipynb notebooks to see two examples of using Genetic Algorithms:
- Fair division of treasure
- 8 Queen Problem
Post-lecture quiz
Assignment
Your goal is to solve so-called Diophantine equation - an equation with integer roots. For example, consider the equation a+2b+3c+4d=30. You need to find integer roots that satisfy this equation.
Hints:
- You can consider roots to be in the interval [0;30]
- As a gene, consider using the list of root values
Use Diophantine.ipynb as a starting point.
This assignment is inspired by this post.
✅ Todo: conclusion, challenge, reference.