public void UpdatePopulation() { var min = CurrentPopulation.First(y => CalculateCF(y) == CurrentPopulation.Min(x => CalculateCF(x))); if (CalculateCF(CurrentBlueChild) > CalculateCF(min)) { CurrentPopulation[CurrentPopulation.IndexOf(min)] = CurrentBlueChild; min = CurrentPopulation.First(y => CalculateCF(y) == CurrentPopulation.Min(x => CalculateCF(x))); } if (CalculateCF(CurrentYellowChild) > CalculateCF(min)) { CurrentPopulation[CurrentPopulation.IndexOf(min)] = CurrentYellowChild; } }
private void SetBestIndividual() { var bestIndividual = CurrentPopulation.First(); for (int i = 1; i < MaxPopulationCount; i++) { var currentIndividual = CurrentPopulation[i]; if ((OptimizationTarget == OptimizationTarget.Maximum && currentIndividual.Result > bestIndividual.Result) || (OptimizationTarget == OptimizationTarget.Minimum && currentIndividual.Result < bestIndividual.Result)) { bestIndividual = currentIndividual; } } BestIndividual = bestIndividual; }
public (List <int>, float) GetTheBestChromosome() { var best = CurrentPopulation.First(y => CalculateCF(y) == CurrentPopulation.Max(x => CalculateCF(x))); List <int> cf_names = new List <int>(); for (int i = 0; i < best.Count; i++) { if (best[i] == 1) { cf_names.Add(i); } } var cf = CalculateCF(best); return(cf_names, cf); }
public void GetCurrentFittestCoefficients() { Chromosome bestChromosome = CurrentPopulation.First(); foreach (Chromosome c in CurrentPopulation) { if (c.Fitness > bestChromosome.Fitness) { bestChromosome = c; } } Tuple <double, double, double> cf = bestChromosome.GetCoefficients(); List <double> coefficients = new List <double>(); coefficients.Add(cf.Item1); coefficients.Add(cf.Item2); coefficients.Add(cf.Item3); SaveData(coefficients, "FunctionCoefficients"); }