コード例 #1
0
        static void Main()
        {
            int i = 2;

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            if (i == 0)
            {
                Application.Run(new OrigForm.MainOrigForm());
            }

            if (i == 1)
            {
                // TEXT
                TextEvolution evolution = new TextEvolution();

                evolution.SetParameters(
                    new Parameters()
                {
                    TargetFitness  = 0.00,
                    PopulationSize = 100,
                    DnaMinValue    = 0,
                    DnaMaxValue    = -1,  // = nr of ValidCharacters
                    MutationRate   = 0.02
                });

                Application.Run(new TextEvolutionForm(evolution));
            }

            if (i == 2)
            {
                //CIRCLE
                CircleEvolution evolution = new CircleEvolution();

                evolution.SetParameters(
                    new Parameters()
                {
                    TargetFitness  = 2.05f,
                    PopulationSize = 100,
                    DnaMinValue    = 0,
                    DnaMaxValue    = 50,
                    MutationRate   = 0.01
                });

                Application.Run(new CircleEvolutionForm(evolution));
            }
        }
コード例 #2
0
        public void Run(double targetFitness, double mutationRate)
        {
            try
            {
                Console.WriteLine("Target text:");
                string targetText = Console.ReadLine();

                Console.WriteLine("Population size:");
                int populationSize = int.Parse(Console.ReadLine());

                TextEvolution evolution = new TextEvolution();

                evolution.SetParameters(
                    new Parameters()
                {
                    TargetFitness  = targetFitness,
                    PopulationSize = populationSize,
                    DnaMinValue    = 0,
                    DnaMaxValue    = -1,  // = nr of ValidCharacters
                    MutationRate   = mutationRate
                });

                // This weird structure is a result of the fact that a specific end state is sought.
                evolution.TargetText = targetText;

                evolution.Run(targetText.Length, DisplayPhenotype);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                Console.Read();
            }
        }