Пример #1
0
 public void Mutate(ChromoSome chromoSome, double mutationProbability)
 {
     if (chromoSome == null)
     {
         throw new ArgumentNullException();
     }
     MutateInternal(chromoSome, mutationProbability);
 }
Пример #2
0
 public Population(int minPopulationCount, int maxPopulationCount, ChromoSome originChromoSome)
 {
     if (minPopulationCount < 2 || maxPopulationCount < _minPopulationCount)
     {
         throw new ArgumentOutOfRangeException();
     }
     _minPopulationCount = minPopulationCount;
     _maxPopulationCount = maxPopulationCount;
     _originChromoSome   = originChromoSome;
     _generations        = new LimitedList <Generation>(DefaultGenerationCount);
 }
Пример #3
0
        public void EndUpdateCurrentGeneration()
        {
            _currentGeneration.EndUpdate(this);

            if (_bestChromoSome != _currentGeneration.BestChromoSome)
            {
                _bestChromoSome = _currentGeneration.BestChromoSome;

                BestChromosomeChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Пример #4
0
        public void EndUpdate(Population population)
        {
            var minCount = population.MinPopulationCount;
            var maxCount = population.MaxPopulationCount;

            while (_chromoSomes.Count < minCount)
            {
                _chromoSomes.Add(_chromoSomes[Util.Next(0, _chromoSomes.Count)]);
            }

            _chromoSomes = _chromoSomes.OrderByDescending(c => c.Fitness.Value).ToList();

            if (_chromoSomes.Count > maxCount)
            {
                _chromoSomes = _chromoSomes.Take(maxCount).ToList();
            }

            _bestChromoSome = _chromoSomes.First();
        }
Пример #5
0
        public void ReInit()
        {
            _bestChromoSome    = null;
            _currentGeneration = null;
            _generations.Clear();

            var chromoSomes = new List <ChromoSome>();

            for (int i = 0; i < _minPopulationCount; i++)
            {
                var chromoSome = _originChromoSome.Random();
                if (chromoSome == null)
                {
                    throw new ArgumentNullException();
                }
                chromoSome.Verify();
                chromoSomes.Add(chromoSome);
            }

            GenerateGeneration(chromoSomes);
        }
Пример #6
0
 protected abstract void MutateInternal(ChromoSome chromoSome, double mutationProbability);
Пример #7
0
        public IGene Mutation(ChromoSome chromoSome, int index)
        {
            var fChromoSome = chromoSome as FloatChromoSome;

            return(new FloatGene(fChromoSome.GetValue(index)));
        }