zoukankan      html  css  js  c++  java
  • A Generic Genetic Algorithm Implemented with C#


    Using The Code / A Simple Sample



    static void Main(string[] args)

    {

        DoubleGenome.DefaultLength = 4;

        DoubleGenome.DefaultFitnessFunction = new DoubleGenomeFitnessFunction_Max();

        DoubleGenome.DefaultMutateRate = 0.05;

     

        GeneticAlgorithm<DoubleGenome> pro = new GeneticAlgorithm<DoubleGenome>();

        pro.CrossoverRate = 0.8;

        pro.PopulationSize = 100;

        pro.GenerationSize = 2000;

        pro.Elitism = true;


        pro.Compute();

     

        DoubleGenome g = pro.GetBestGenome();

        for (int i = 0; i < g.Value.Length; i++)

        {

            Console.WriteLine(g.Value[i]);

        }

    }


    To solve your problem with this "Generic Genetic Algorithm",
    You should first describe your problem by writing your own genome class derived from the abstract class "Genome", implementing abstract methods such as "Crossover", "Mutate", "ComputeFitness", etc.

    Sample Project Download:
    https://files.cnblogs.com/Dah/Adrian.Algorithm.Genetic.rar

    Feel free to leave your comment or suggestion. :)
  • 相关阅读:
    Many Equal Substrings CF
    Seek the Name, Seek the Fame POJ
    人人都是好朋友(离散化 + 并查集)
    建设道路
    day_30
    day_29作业
    day_29
    day_28
    day_27
    day_26作业
  • 原文地址:https://www.cnblogs.com/Dah/p/647543.html
Copyright © 2011-2022 走看看