public void Mutate(ChromoSome chromoSome, double mutationProbability) { if (chromoSome == null) { throw new ArgumentNullException(); } MutateInternal(chromoSome, mutationProbability); }
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); }
public void EndUpdateCurrentGeneration() { _currentGeneration.EndUpdate(this); if (_bestChromoSome != _currentGeneration.BestChromoSome) { _bestChromoSome = _currentGeneration.BestChromoSome; BestChromosomeChanged?.Invoke(this, EventArgs.Empty); } }
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(); }
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); }
protected abstract void MutateInternal(ChromoSome chromoSome, double mutationProbability);
public IGene Mutation(ChromoSome chromoSome, int index) { var fChromoSome = chromoSome as FloatChromoSome; return(new FloatGene(fChromoSome.GetValue(index))); }