コード例 #1
0
ファイル: GA.cs プロジェクト: Overx/AI
        public void Resume(GAFunction fitnessFunc, OnGeneration onGenerationFunc)
        {
            FitnessFunction      = fitnessFunc;
            OnGenerationFunction = onGenerationFunc;

            Go(true);
        }
コード例 #2
0
ファイル: StringFunction.cs プロジェクト: Overx/AI
 public StringFunction(Func <IFitness> getFitnessMethod, GAStatus bestStatus, GAFunction fitnessFunc, OnGeneration generationFunc, double crossoverRate, double mutationRate, int genomeSize, TargetParams targetParams)
 {
     _getFitnessFunc = getFitnessMethod;
     _bestStatus     = bestStatus;
     _crossoverRate  = crossoverRate;
     _mutationRate   = mutationRate;
     _genomeSize     = genomeSize;
     _fitnessFunc    = fitnessFunc;
     _generationFunc = generationFunc;
     _targetParams   = targetParams;
 }
コード例 #3
0
ファイル: StringFunction.cs プロジェクト: ipepe/AI-Programmer
 public StringFunction(Func<IFitness> getFitnessMethod, GAStatus bestStatus, GAFunction fitnessFunc, OnGeneration generationFunc, double crossoverRate, double mutationRate, int genomeSize, TargetParams targetParams)
 {
     _getFitnessFunc = getFitnessMethod;
     _bestStatus = bestStatus;
     _crossoverRate = crossoverRate;
     _mutationRate = mutationRate;
     _genomeSize = genomeSize;
     _fitnessFunc = fitnessFunc;
     _generationFunc = generationFunc;
     _targetParams = targetParams;
 }
コード例 #4
0
        public StringFunctionChunk(Func <IFitness> getFitnessMethod, Action <string, object> onStepComplete, GAStatus bestStatus, GAFunction fitnessFunc, OnGeneration generationFunc, double crossoverRate, double mutationRate, int genomeSize, TargetParams targetParams, int chunkSize = 4)
        {
            _getFitnessFunc = getFitnessMethod;
            _onStepComplete = onStepComplete;
            _bestStatus     = bestStatus;
            _crossoverRate  = crossoverRate;
            _mutationRate   = mutationRate;
            _genomeSize     = genomeSize;
            _fitnessFunc    = fitnessFunc;
            _generationFunc = generationFunc;
            _targetParams   = targetParams;

            _chunkSize = chunkSize;
        }
コード例 #5
0
        public void InitializeGA(NetworkInitializer initializer, Func <double[], double> fitnessFunction)
        {
            var input = (GeneticInitializer)initializer;

            this.crossover      = input.Crossover;
            this.iterations     = input.Iterations;
            this.mutationRate   = input.MutationRate;
            this.populationSize = input.PopulationSize;

            InitializeWeights(initializer);

            ga         = new GA(crossover, mutationRate, populationSize, iterations, weights);
            ga.Elitism = true;
            GAFunction func = new GAFunction(fitnessFunction);

            ga.FitnessFunction = func;
        }
コード例 #6
0
ファイル: GAManager.cs プロジェクト: yakii9/AI-Programmer
        /// <summary>
        /// Setup the genetic algorithm and run it.
        /// </summary>
        /// <returns>Best brain's output source code</returns>
        public static string Run(IGeneticAlgorithm iga, GAFunction fitnessFunc, OnGeneration generationFunc, Action setupFunc = null, bool resume = false)
        {
            GA ga = (GA)iga;

            if (!resume)
            {
                if (setupFunc != null)
                {
                    // Perform any additional setup for this fitness.
                    setupFunc();
                }

                try
                {
                    // Delete any existing dat file.
                    File.Delete(Directory.GetCurrentDirectory() + "\\my-genetic-algorithm.dat");
                }
                catch (Exception excep)
                {
                    Console.WriteLine("Unable to delete " + Directory.GetCurrentDirectory() + "\\my-genetic-algorithm.dat\n" + excep.Message);
                }

                // Start a new genetic algorithm.
                ga.GAParams.Elitism     = true;
                ga.GAParams.HistoryPath = Directory.GetCurrentDirectory() + "\\history.txt";
                ga.FitnessFunction      = new GAFunction(fitnessFunc);
                ga.OnGenerationFunction = new OnGeneration(generationFunc);
                ga.Go();
            }
            else
            {
                // Load a saved genetic algorithm.
                ga.Load("my-genetic-algorithm.dat");
                ga.Resume(fitnessFunc, generationFunc);
            }

            // Results.
            double[] weights;
            double   fitness;

            ga.GetBest(out weights, out fitness);

            Console.WriteLine("***** DONE! *****");

            return(CommonManager.ConvertDoubleArrayToBF(weights));
        }
コード例 #7
0
ファイル: GAManager.cs プロジェクト: ipepe/AI-Programmer
        /// <summary>
        /// Setup the genetic algorithm and run it.
        /// </summary>
        /// <returns>Best brain's output source code</returns>
        public static string Run(IGeneticAlgorithm iga, GAFunction fitnessFunc, OnGeneration generationFunc, Action setupFunc = null, bool resume = false)
        {
            GA ga = (GA)iga;

            if (!resume)
            {
                if (setupFunc != null)
                {
                    // Perform any additional setup for this fitness.
                    setupFunc();
                }

                // Delete any existing dat file.
                File.Delete(Directory.GetCurrentDirectory() + "\\my-genetic-algorithm.dat");

                // Start a new genetic algorithm.
                ga.GAParams.Elitism = true;
                ga.GAParams.HistoryPath = Directory.GetCurrentDirectory() + "\\history.txt";
                ga.FitnessFunction = new GAFunction(fitnessFunc);
                ga.OnGenerationFunction = new OnGeneration(generationFunc);
                ga.Go();
            }
            else
            {
                // Load a saved genetic algorithm.
                ga.Load("my-genetic-algorithm.dat");
                ga.Resume(fitnessFunc, generationFunc);
            }

            // Results.
            double[] weights;
            double fitness;
            ga.GetBest(out weights, out fitness);

            Console.WriteLine("***** DONE! *****");

            return CommonManager.ConvertDoubleArrayToBF(weights);
        }
コード例 #8
0
ファイル: GA.cs プロジェクト: amennelet/AI-Programmer
        public void Resume(GAFunction fitnessFunc, OnGeneration onGenerationFunc)
        {
            FitnessFunction = fitnessFunc;
            OnGenerationFunction = onGenerationFunc;

            Go(true);
        }