Exemplo n.º 1
0
 /// <summary>
 ///     Construct the parallel task.
 /// </summary>
 /// <param name="genome">The genome.</param>
 /// <param name="theOwner">The owner.</param>
 public ParallelScoreTask(IGenome genome, ParallelScore theOwner)
 {
     owner         = theOwner;
     this.genome   = genome;
     scoreFunction = theOwner.ScoreFunction;
     adjusters     = theOwner.Adjusters;
 }
 /// <summary>
 ///     Construct the parallel task.
 /// </summary>
 /// <param name="genome">The genome.</param>
 /// <param name="theOwner">The owner.</param>
 public ParallelScoreTask(IGenome genome, ParallelScore theOwner)
 {
     owner = theOwner;
     this.genome = genome;
     scoreFunction = theOwner.ScoreFunction;
     adjusters = theOwner.Adjusters;
 }
Exemplo n.º 3
0
        /// <summary>
        ///     Called before the first iteration. Determine the number of threads to
        ///     use.
        /// </summary>
        private void PreIteration()
        {
            _initialized = true;
            _speciation.Init(this);

            // score the population
            var pscore = new ParallelScore(Population,
                                           CODEC, _adjusters, ScoreFunction, ThreadCount);
            pscore.Process();

            // just pick the first genome with a valid score as best, it will be
            // updated later.
            // also most populations are sorted this way after training finishes
            // (for reload)
            // if there is an empty population, the constructor would have blow
            IList<IGenome> list = Population.Flatten();

            int idx = 0;
            do
            {
                BestGenome = list[idx++];
            } while (idx < list.Count
                     && (Double.IsInfinity(BestGenome.Score) || Double
                                                                    .IsNaN(BestGenome.Score)));

            Population.BestGenome = BestGenome;

            // speciate
            IList<IGenome> genomes = Population.Flatten();
            _speciation.PerformSpeciation(genomes);

            // purge invalid genomes
            Population.PurgeInvalidGenomes();
        }