예제 #1
0
        /// <summary>
        /// Main program.
        /// </summary>
        static void Main(string[] args)
        {
            // Get the selected fitness type.
            IFitness myFitness = GetFitnessMethod();

            // Genetic algorithm setup.
            _ga = new GA(_crossoverRate, _mutationRate, 100, 10000000, _genomeSize);

            // Get the target fitness for this method.
            _targetFitness = myFitness.TargetFitness;

            // Run the genetic algorithm and get the best brain.
            string program = GAManager.Run(_ga, fitnessFunction, OnGeneration);

            // Display the final program.
            Console.WriteLine(program);
            Console.WriteLine();

            // Compile to executable.
            BrainPlus.Compile(program, "output.exe", myFitness);

            // Run the result for the user.
            string result = myFitness.RunProgram(program);

            Console.WriteLine(result);

            Console.ReadKey();
        }
예제 #2
0
        /// <summary>
        /// Main program.
        /// </summary>
        static void Main(string[] args)
        {
            // Genetic algorithm setup.
            _ga = new GA(_crossoverRate, _mutationRate, 100, 10000000, _genomeSize);

            if (_functionGenerator != null)
            {
                // Generate additional functions.
                _appendCode += _functionGenerator.Generate(_ga);
            }

            // Generate main program. Instantiate the fitness method.
            IFitness myFitness = GetFitness();

            // Get the target fitness for this method.
            _targetParams.TargetFitness = myFitness.TargetFitness;

            // Run the genetic algorithm and get the best brain.
            string program = GAManager.Run(_ga, fitnessFunction, OnGeneration);

            // Append any functions.
            if (!string.IsNullOrEmpty(_appendCode))
            {
                program += "@" + _appendCode;
            }

            // Display the final program.
            Console.WriteLine(program);
            Console.WriteLine();

            // Compile to executable.
            BrainPlus.Compile(program, "output.exe", myFitness);

            // Run the result for the user.
            string result = myFitness.RunProgram(program);

            Console.WriteLine(result);

            Console.ReadKey();
        }