2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 13:33:13 +00:00

Soft Computing

This commit is contained in:
2022-11-06 13:25:49 +03:00
parent f1d5b0a38b
commit 2844eb60ec
11 changed files with 790 additions and 430 deletions

View File

@ -88,23 +88,25 @@ namespace Esiur.Analysis.Optimization
}
public T Evaluate(int maxIterations)
public IEnumerable<(int, double, T)> Evaluate(int maxIterations)
{
GeneratePopultation();
var generation = 0;
T best;
KeyValuePair<T, double> best;
do
{
var ordered = GetFitness().OrderBy(x => x.Value).ToArray();
best = ordered[0].Key;
if (ordered[0].Value == 0)
best = ordered[0];
if (best.Value == 0)
break;
yield return (generation, best.Value, best.Key);
// Elitism selection ( 10% of fittest population )
var eliteCount = (int)(ordered.Length * 0.1);
@ -124,12 +126,14 @@ namespace Esiur.Analysis.Optimization
Population = newGeneration;
Debug.WriteLine($"Gen {generation} Fittest: {ordered.First().Value} {ordered.First().Key.ToString()} ");
} while (generation++ < maxIterations);
Debug.WriteLine($"Gen {generation} Best: {best.ToString()} ");
return best;
yield return (generation, best.Value, best.Key);
}
}
}