1. 程式人生 > >MIP啟發式演算法:遺傳演算法 (Genetic algorithm)

MIP啟發式演算法:遺傳演算法 (Genetic algorithm)

*本文主要記錄和分享學習到的知識,算不上原創

*參考文獻見連結

本文主要講述啟發式演算法中的遺傳演算法。遺傳演算法也是以local search為核心框架,但在表現形式上和hill climbing, tabu search, Variable neighborhood search等以一個初始解出發的演算法會有些許不同。這種以若干個初始解出發的啟發式演算法在diversification方面表現得會比較好。

http://www.theprojectspot.com/tutorial-post/creating-a-genetic-algorithm-for-beginners/3

目錄

  GA的過程

  GA的虛擬碼

  Example

GA的思想

  模仿生物界進化的過程:適者生存

GA的過程

(1)Initialization 

Create an initial population. This population is usually randomly generated and can be any desired size, from only a few individuals to thousands.

(2)Evaluation

Each member of the population is then evaluated and we calculate a 'fitness'

for that individual. The fitness value is calculated by how well it fits with our desired requirements. These requirements could be simple, 'faster algorithms are better', or more complex, 'stronger materials are better but they shouldn't be too heavy'.

(3)Selection

We want to be constantly improving our populations overall fitness. Selection helps us to do this by discarding the bad designs and only keeping the best individuals in the population.  There are a few different selection methods but the basic idea is the same, make it more likely that fitter individuals will be selected for our next generation.

(4)Crossover

During crossover we create new individuals by combining aspects of our selected individuals. We can think of this as mimicking how sex works in nature. The hope is that by combining certain traits from two or more individuals we will create an even 'fitter' offspring which will inherit the best traits from each of it's parents.

(5)Mutation

We need to add a little bit randomness into our populations' genetics otherwise every combination of solutions we can create would be in our initial population. Mutation typically works by making very small changes at random to an individuals genome.

(6)And repeat!

Now we have our next generation we can start again from step two until we reach a termination condition.

 

GA的關鍵:
(1)如何表示解?

(2)如何進行crossover和mutation?

(3)如何進行優勝劣汰?

GA的虛擬碼

 Example: GA for TSP

https://github.com/xiaolou023/Algorithms/tree/master/TSP/src/simpleGA2