-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSamplePopulationConverter.cs
36 lines (32 loc) · 1.46 KB
/
SamplePopulationConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using GeneticAlgorithm.Interfaces;
namespace GeneticAlgorithm.PopulationConverters
{
class SamplePopulationConverter : IPopulationConverter
{
/// <summary>
/// This method is will be called once per generation (after the ConvertPopulation method for that generation), so you can use it to remember old data.
/// </summary>
public void AddGeneration(Population population)
{
double[] evaluations = population.GetEvaluations();
IChromosome[] chromosomes = population.GetChromosomes();
}
/// <summary>
/// This method will be called every generation after the population is created.
/// In this method you can change the population in any way you want.
/// This allows you to add Lamarckian evolution to your algorithm - that is, let the chromosomes improve themselves before generating the children.
/// </summary>
public IChromosome[] ConvertPopulation(IChromosome[] population, int generation, IEnvironment environment)
{
IChromosome[] newChromosomes = new IChromosome[population.Length];
for (int i = 0; i < population.Length; i++)
newChromosomes[i] = ImproveChromosome(population[i]);
return newChromosomes;
}
private IChromosome ImproveChromosome(IChromosome chromosome)
{
// Improve the chromosome in some way here
return chromosome;
}
}
}