예제 #1
0
        private void CalculateFitness(Individual cur)
        {
            cur.RawFitness = cur.TotalHealthDifference;
            cur.Features   = new [] { cur.DamageDone, cur.NumTurns };
            Console.WriteLine("Raw Fitness: " + cur.RawFitness);

            if (_featureMap.Add(cur))
            {
                // Reassess the fitness of all elements
                var queue = new Queue <Shard>();
                while (!_populationDeque.IsEmpty)
                {
                    Shard curShard = _populationDeque.DeleteMax();
                    curShard.Representative.Fitness =
                        -_featureMap.GetRank(curShard.Representative);
                    queue.Enqueue(curShard);
                }

                while (queue.Count > 0)
                {
                    Shard curShard = queue.Dequeue();
                    _populationDeque.Add(curShard);
                }
            }
            cur.Fitness = -_featureMap.GetRank(cur);
            Console.WriteLine("Fitness: " + cur.Fitness);

            // Save stats
            bool didHitMaxWins =
                cur.WinCount > _maxWins;
            bool didHitMaxFitness =
                cur.RawFitness > _maxFitness;

            _maxWins    = Math.Max(_maxWins, cur.WinCount);
            _maxFitness = Math.Max(_maxFitness, cur.RawFitness);

            // Log individual
            if (didHitMaxWins)
            {
                _champion_log.LogIndividual(cur);
            }
            if (didHitMaxFitness)
            {
                _fittest_log.LogIndividual(cur);
            }
        }