public TicTacToeGenetic(FeedforwardNetwork network,
                                bool reset, int populationSize,
                                double mutationPercent, double percentToMate,
                                Type opponent)
        {
            this.setOpponent(opponent);
            this.MutationPercent  = mutationPercent;
            this.MatingPopulation = percentToMate * 2;
            this.PopulationSize   = populationSize;
            this.PercentToMate    = percentToMate;

            this.Chromosomes = new TicTacToeChromosome[this.PopulationSize];
            for (int i = 0; i < this.Chromosomes.Length; i++)
            {
                FeedforwardNetwork chromosomeNetwork = (FeedforwardNetwork)network
                                                       .Clone();
                if (reset)
                {
                    chromosomeNetwork.Reset();
                }

                TicTacToeChromosome c = new TicTacToeChromosome(this,
                                                                chromosomeNetwork);
                c.UpdateGenes();
                SetChromosome(i, c);
            }
            SortChromosomes();
        }
        public TicTacToeGenetic(FeedforwardNetwork network,
                 bool reset, int populationSize,
                 double mutationPercent, double percentToMate,
                 Type opponent)
        {


            this.setOpponent(opponent);
            this.MutationPercent=mutationPercent;
            this.MatingPopulation=percentToMate * 2;
            this.PopulationSize=populationSize;
            this.PercentToMate=percentToMate;

            this.Chromosomes = new TicTacToeChromosome[this.PopulationSize];
            for (int i = 0; i < this.Chromosomes.Length; i++)
            {
                FeedforwardNetwork chromosomeNetwork = (FeedforwardNetwork)network
                        .Clone();
                if (reset)
                {
                    chromosomeNetwork.Reset();
                }

                TicTacToeChromosome c = new TicTacToeChromosome(this,
                        chromosomeNetwork);
                c.UpdateGenes();
                SetChromosome(i, c);
            }
            SortChromosomes();
        }
Пример #3
0
        public TicTacToeGenetic(FeedforwardNetwork network,
                 bool reset, int populationSize,
                 double mutationPercent, double percentToMate,
                 Type opponent)
        {


            this.setOpponent(opponent);
            this.MutationPercent=mutationPercent;
            this.MatingPopulation=percentToMate * 2;
            this.PopulationSize=populationSize;
            this.PercentToMate=percentToMate;

            this.Chromosomes = new TicTacToeChromosome[this.PopulationSize];
            var rangePartitioner = Partitioner.Create(0, this.Chromosomes.Length);
            //Parallel.ForEach(rangePartitioner, (range, loopState) =>
            {
                for (int i = 0; i < Chromosomes.Length; i++)
                {
                    Console.WriteLine("step: " + i);
                    FeedforwardNetwork chromosomeNetwork = (FeedforwardNetwork)network
                            .Clone();
                    if (reset)
                    {
                        chromosomeNetwork.Reset();
                    }

                    TicTacToeChromosome c = new TicTacToeChromosome(this,
                            chromosomeNetwork);
                    c.UpdateGenes();
                    lock (_locker)
                    {
                        SetChromosome(i, c);
                    }                    
                }
            };
            Console.WriteLine("PreEpoch # Error:" + getScore());
            SortChromosomes();
        }
Пример #4
0
        public TicTacToeGenetic(FeedforwardNetwork network,
                                bool reset, int populationSize,
                                double mutationPercent, double percentToMate,
                                Type opponent)
        {
            this.setOpponent(opponent);
            this.MutationPercent  = mutationPercent;
            this.MatingPopulation = percentToMate * 2;
            this.PopulationSize   = populationSize;
            this.PercentToMate    = percentToMate;

            this.Chromosomes = new TicTacToeChromosome[this.PopulationSize];
            var rangePartitioner = Partitioner.Create(0, this.Chromosomes.Length);

            //Parallel.ForEach(rangePartitioner, (range, loopState) =>
            {
                for (int i = 0; i < Chromosomes.Length; i++)
                {
                    Console.WriteLine("step: " + i);
                    FeedforwardNetwork chromosomeNetwork = (FeedforwardNetwork)network
                                                           .Clone();
                    if (reset)
                    {
                        chromosomeNetwork.Reset();
                    }

                    TicTacToeChromosome c = new TicTacToeChromosome(this,
                                                                    chromosomeNetwork);
                    c.UpdateGenes();
                    lock (_locker)
                    {
                        SetChromosome(i, c);
                    }
                }
            };
            Console.WriteLine("PreEpoch # Error:" + getScore());
            SortChromosomes();
        }