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:
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user