A Genetic Algorithm Framework for .NET
Create a Console Application and install EvoleSharp using Nuget:
PM> Install-Package EvolveSharp
In this simple example we are creating a fitness function to sum all genes of an individual
public class ExampleFitnessFunction : IFitnessFunction<double> {
public double Evaluate(IIndividual<double> individual) {
var sum = 0.0;
for (var i = 0; i < individual.Length; i++) { sum += individual[i]; }
return sum;
}
}
You can set 3 parameters:
- Population count: How many individuals each population will have
- Gene count: How many genes each individual will have
- Generation count: How many generations will occour
class Program
{
static void Main(string[] args)
{
const int populationCount = 100;
const int generationCount = 10000;
const int geneCount = 10;
var ga = new GeneticAlgorithm(populationCount, geneCount, new ExampleFitnessFunction());
ga.Evolve(generationCount);
}
}
- You can create your own mutation, selection, crossover and initializer class. You just need to inherit the respective interface.
- You can set the
Mutator
,CrossoverMethod
,Selector
andInitializer
after instantiate theGeneticAlgorithm
class. - You can create and set your own reporter in
GeneticAlgorithm
class.
Clone EvolveSharp and try the Travelling salesman problem sample
Please use the issue tracker and pull requests.
Copyright (c) 2014 Afonso França Licensed under the MIT license.