Exemplo n.º 1
0
        public void WriteParamValues(int iteration, double fitness, Gene gene)
        {
            Write(iteration + ",");

            for (var index = 0; index < gene.Chromosomes.Count; index++)
            {
                Write(gene.Chromosomes[index] + ",");
            }

            WriteLine(fitness.ToString("N3"));
        }
Exemplo n.º 2
0
        public bool Valid(Gene gene)
        {
            var valid = !_seenGenes.ContainsKey(gene);

            if (valid)
            {
                _seenGenes.Add(gene, true);
            }

            return(valid);
        }
Exemplo n.º 3
0
        public bool Valid(Gene gene)
        {
            var valid = !_seenGenes.ContainsKey(gene);

            if (valid)
            {
                _seenGenes.Add(gene, true);
            }

            return valid;
        }
Exemplo n.º 4
0
        public bool Valid(Gene gene)
        {
            foreach (var validator in _geneValidators)
            {
                if (!validator.Valid(gene))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 5
0
        public GeneScore Evaluate(Gene gene)
        {
            for (var i = 0; i < gene.Chromosomes.Count; i++)
            {
                // NT needs everything to be doubles
                _strategy.Parameters[_strategyParameterIndices[i]].Value = Convert.ToDouble(gene.Chromosomes[i]);
            }

            _strategy.RunIteration();

            return new GeneScore(gene, FitnessFunctionWrapper.LastPerformanceValue);
        }
Exemplo n.º 6
0
        public bool Valid(Gene gene)
        {
            foreach (var validator in _geneValidators)
            {
                if (!validator.Valid(gene))
                {
                    return false;
                }
            }

            return true;
        }
Exemplo n.º 7
0
        private Gene Reproduce(double mutationRate, params Gene[] parents)
        {
            var child = new Gene();

            for (var i = 0; i < _chromosomeTypes.Count; i++)
            {
                var chromosome = parents[_random.Next(parents.Length)].Chromosomes[i];

                if (_random.NextDouble() < mutationRate)
                {
                    chromosome = _chromosomeTypes[i].Mutate(chromosome, _random);
                }

                child.Chromosomes.Add(chromosome);
            }

            return(child);
        }
Exemplo n.º 8
0
        private Gene Reproduce(double mutationRate, params Gene[] parents)
        {
            var child = new Gene();

            for (var i = 0; i < _chromosomeTypes.Count; i++)
            {
                var chromosome = parents[_random.Next(parents.Length)].Chromosomes[i];

                if (_random.NextDouble() < mutationRate)
                {
                    chromosome = _chromosomeTypes[i].Mutate(chromosome, _random);
                }

                child.Chromosomes.Add(chromosome);
            }

            return child;
        }
Exemplo n.º 9
0
        private Gene CreateNew()
        {
            var gene = new Gene();

            foreach (var chromosomeType in _chromosomeTypes)
            {
                gene.Chromosomes.Add(chromosomeType.GetRandomValue(_random));
            }

            return gene;
        }