Inheritance: IEngineTask
Beispiel #1
0
        private void ThreadWorker(int i, int offspringIndex, int matingPopulationSize)
        {
            IGenome mother    = Population.Genomes[i];
            var     fatherInt = (int)(ThreadSafeRandom.NextDouble() * matingPopulationSize);
            IGenome father    = Population.Genomes[fatherInt];
            IGenome child1    = Population.Genomes[offspringIndex + i * 2];
            IGenome child2    = Population.Genomes[offspringIndex + i * 2 + 1];

            var worker = new MateWorker(mother, father, child1,
                                        child2);

            worker.Run();
        }
        /// <summary>
        /// Modify the weight matrix and bias values based on the last call to
        /// calcError.
        /// </summary>
        public override sealed void Iteration()
        {
            if (_first)
            {
                Population.Claim(this);
                _first = false;
            }

            var countToMate = (int) (Population.PopulationSize*PercentToMate);
            int offspringCount = countToMate*2;
            int offspringIndex = Population.PopulationSize
                                 - offspringCount;
            var matingPopulationSize = (int) (Population.PopulationSize*MatingPopulation);

            TaskGroup group = EngineConcurrency.Instance
                .CreateTaskGroup();

            // mate and form the next generation
            for (int i = 0; i < countToMate; i++)
            {
                IGenome mother = Population.Genomes[i];
                var fatherInt = (int)(ThreadSafeRandom.NextDouble()*matingPopulationSize);
                IGenome father = Population.Genomes[fatherInt];
                IGenome child1 = Population.Genomes[offspringIndex];
                IGenome child2 = Population.Genomes[offspringIndex + 1];

                var worker = new MateWorker(mother, father, child1,
                                            child2);

                if (MultiThreaded)
                {
                    EngineConcurrency.Instance.ProcessTask(worker, group);
                }
                else
                {
                    worker.Run();
                }

                offspringIndex += 2;
            }

            if (MultiThreaded)
            {
                group.WaitForComplete();
            }

            // sort the next generation
            Population.Sort();
        }
        /// <summary>
        /// Modify the weight matrix and bias values based on the last call to
        /// calcError.
        /// </summary>
        public override sealed void Iteration()
        {
            if (_first)
            {
                EngineConcurrency.Instance.ThreadCount = ThreadCount;
                Population.Claim(this);
                _first = false;
            }

            var countToMate    = (int)(Population.PopulationSize * PercentToMate);
            int offspringCount = countToMate * 2;
            int offspringIndex = Population.PopulationSize
                                 - offspringCount;
            var matingPopulationSize = (int)(Population.PopulationSize * MatingPopulation);

            TaskGroup group = EngineConcurrency.Instance
                              .CreateTaskGroup();

            // mate and form the next generation
            for (int i = 0; i < countToMate; i++)
            {
                IGenome mother    = Population.Genomes[i];
                var     fatherInt = (int)(ThreadSafeRandom.NextDouble() * matingPopulationSize);
                IGenome father    = Population.Genomes[fatherInt];
                IGenome child1    = Population.Genomes[offspringIndex];
                IGenome child2    = Population.Genomes[offspringIndex + 1];

                var worker = new MateWorker(mother, father, child1,
                                            child2);

                EngineConcurrency.Instance.ProcessTask(worker, group);


                offspringIndex += 2;
            }

            group.WaitForComplete();

            // sort the next generation
            Population.Sort();
        }
Beispiel #4
0
 public override sealed void Iteration()
 {
     int num;
     int num2;
     int num3;
     int num4;
     TaskGroup group;
     int num5;
     IGenome genome;
     IGenome genome2;
     IGenome genome3;
     IGenome genome4;
     if (!this._x62584df2cb5d40dd)
     {
         goto Label_016F;
     }
     if ((((uint) num3) + ((uint) num2)) >= 0)
     {
         EngineConcurrency.Instance.ThreadCount = base.ThreadCount;
         base.Population.Claim(this);
         this._x62584df2cb5d40dd = false;
         goto Label_016F;
     }
     goto Label_008B;
     Label_0083:
     if (num5 < num)
     {
         int num6;
         genome = base.Population.Genomes[num5];
         do
         {
             num6 = (int) (ThreadSafeRandom.NextDouble() * num4);
         }
         while ((((uint) num) + ((uint) num6)) < 0);
         genome2 = base.Population.Genomes[num6];
         goto Label_00FB;
     }
     if (0 == 0)
     {
         group.WaitForComplete();
         base.Population.Sort();
         return;
     }
     Label_008B:
     genome4 = base.Population.Genomes[num3 + 1];
     MateWorker task = new MateWorker(genome, genome2, genome3, genome4);
     EngineConcurrency.Instance.ProcessTask(task, group);
     num3 += 2;
     num5++;
     if ((((uint) num2) + ((uint) num2)) > uint.MaxValue)
     {
         goto Label_0184;
     }
     goto Label_0083;
     Label_00FB:
     genome3 = base.Population.Genomes[num3];
     goto Label_008B;
     Label_016F:
     num = (int) (base.Population.PopulationSize * base.PercentToMate);
     Label_0184:
     num2 = num * 2;
     num3 = base.Population.PopulationSize - num2;
     num4 = (int) (base.Population.PopulationSize * base.MatingPopulation);
     if (0 != 0)
     {
         goto Label_00FB;
     }
     group = EngineConcurrency.Instance.CreateTaskGroup();
     num5 = 0;
     goto Label_0083;
 }
Beispiel #5
0
        /// <summary>
        /// Modify the weight matrix and bias values based on the last call to
        /// calcError.
        /// </summary>
        public override sealed void Iteration()
        {
            if (_first)
            {
                Population.Claim(this);
                _first = false;
            }

            var countToMate = (int) (Population.PopulationSize*PercentToMate);
            int offspringCount = countToMate*2;
            int offspringIndex = Population.PopulationSize
                                 - offspringCount;
            var matingPopulationSize = (int) (Population.PopulationSize*MatingPopulation);

            // mate and form the next generation
            Parallel.For(0, countToMate, i =>
            {
                IGenome mother = Population.Genomes[i];
                var fatherInt = (int)(ThreadSafeRandom.NextDouble() * matingPopulationSize);
                IGenome father = Population.Genomes[fatherInt];
                IGenome child1 = Population.Genomes[offspringIndex];
                IGenome child2 = Population.Genomes[offspringIndex + 1];

                var worker = new MateWorker(mother, father, child1,
                                            child2);

                worker.Run();

                offspringIndex += 2;
            });

            // sort the next generation
            Population.Sort();
        }
        private void ThreadWorker(int i, int offspringIndex, int matingPopulationSize)
        {
            IGenome mother = Population.Genomes[i];
            var fatherInt = (int)(ThreadSafeRandom.NextDouble() * matingPopulationSize);
            IGenome father = Population.Genomes[fatherInt];
            IGenome child1 = Population.Genomes[offspringIndex + i * 2];
            IGenome child2 = Population.Genomes[offspringIndex + i * 2 + 1];

            var worker = new MateWorker(mother, father, child1,
                                        child2);

            worker.Run();
        }