Ejemplo n.º 1
0
        private float CalculateFitness()
        {
            float _fitness = 0;

            if (cache.TryGetFitness(genotype, out _fitness))
            {
                return(_fitness);
            }

            cache.AddCalculatedFitness(genotype.ToString(), _fitness);
            return(_fitness);
        }
Ejemplo n.º 2
0
        public bool TryGetFitness(IGenotype <int, int> genotype, out float fitness)
        {
            var _fitnessIsCalculated = calculatedFitnesses.TryGetValue(genotype.ToString(), out fitness);

            if (!_fitnessIsCalculated)
            {
                for (int y = 0; y < genotype.GetGenotypeSize(); y++)
                {
                    for (int x = y + 1; x < genotype.GetGenotypeSize(); x++)
                    {
                        fitness += distance[x, y] *
                                   (flow[genotype.GetGene(y).GetValue(), genotype.GetGene(x).GetValue()] +
                                    flow[genotype.GetGene(x).GetValue(), genotype.GetGene(y).GetValue()]);
                    }
                }
            }
            return(_fitnessIsCalculated);
        }