zoukankan      html  css  js  c++  java
  • 启发式算法:遗传算法 (Genetic algorithm)

    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

  • 相关阅读:
    BZOJ3156 防御准备
    BZOJ1911 [APIO2010] 特别行动队
    BZOJ1096 [ZJOI2007] 仓库建设
    HDU
    斜率优化的各种板子
    HDU
    HDU
    HDU
    HDU
    HDU
  • 原文地址:https://www.cnblogs.com/liuyingsme/p/9859350.html
Copyright © 2011-2022 走看看