Пример #1
0
        public virtual void EvaluatePopulation(Population pop, EvolutionAlgorithm ea)
        {
            // Evaluate in single-file each genome within the population.
            // Only evaluate new genomes (those with EvaluationCount==0).
            int count = pop.GenomeList.Count;

            for (int i = 0; i < count; i++)
            {
                IGenome g = pop.GenomeList[i];
                if (g.EvaluationCount != 0)
                {
                    continue;
                }

                INetwork network = g.Decode(activationFn);
                if (network == null)
                {                       // Future genomes may not decode - handle the possibility.
                    g.Fitness = EvolutionAlgorithm.MIN_GENOME_FITNESS;
                }
                else
                {
                    g.Fitness = Math.Max(networkEvaluator.EvaluateNetwork(network), EvolutionAlgorithm.MIN_GENOME_FITNESS);
                }

                // Reset these genome level statistics.
                g.TotalFitness    = g.Fitness;
                g.EvaluationCount = 1;

                // Update master evaluation counter.
                evaluationCount++;
            }
        }
        public virtual void EvaluatePopulation(Population pop, EvolutionAlgorithm ea)
        {
            // Evaluate in single-file each genome within the population.
            // Only evaluate new genomes (those with EvaluationCount==0).
            int count = pop.GenomeList.Count;

            for (int i = 0; i < count; i++)
            {
                IGenome g = pop.GenomeList[i];
                if (g.EvaluationCount != 0)
                {
                    continue;
                }

                INetwork network = g.Decode(activationFn);
                if (network == null)
                {                       // Future genomes may not decode - handle the possibility.
                    g.Fitness = EvolutionAlgorithm.MIN_GENOME_FITNESS;
                }
                else
                {
                    BehaviorType behavior;
                    g.Fitness     = Math.Max(networkEvaluator.EvaluateNetwork(network, out behavior), EvolutionAlgorithm.MIN_GENOME_FITNESS);
                    g.RealFitness = g.Fitness;
                    g.Behavior    = behavior;
                }

                // Reset these genome level statistics.
                g.TotalFitness    = g.Fitness;
                g.EvaluationCount = 1;

                // Update master evaluation counter.
                evaluationCount++;
            }

            if (ea.NeatParameters.noveltySearch)
            {
                if (ea.NeatParameters.noveltySearch && ea.noveltyInitialized)
                {
                    ea.CalculateNovelty();
                }
            }
        }