Ejemplo n.º 1
0
 public void Mutate(ChromoSome chromoSome, double mutationProbability)
 {
     if (chromoSome == null)
     {
         throw new ArgumentNullException();
     }
     MutateInternal(chromoSome, mutationProbability);
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 3
0
        public void EndUpdateCurrentGeneration()
        {
            _currentGeneration.EndUpdate(this);

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

                BestChromosomeChanged?.Invoke(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 6
0
 protected abstract void MutateInternal(ChromoSome chromoSome, double mutationProbability);
Ejemplo n.º 7
0
        public IGene Mutation(ChromoSome chromoSome, int index)
        {
            var fChromoSome = chromoSome as FloatChromoSome;

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