EvolveSharp
.NET Genetic Algorithm Framework
Install / Use
/learn @afonsof/EvolveSharpREADME
A Genetic Algorithm Framework for .NET
<a href="http://afonsof.github.io/EvolveSharp" target="_blank">Visit our website</a>
Getting Started
1. Setting Up
Create a Console Application and install EvoleSharp using Nuget:
PM> Install-Package EvolveSharp
2. Create a fitness function
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;
}
}
3. Instantiate the GeneticAlgorithm class and call the Evolve method
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);
}
}
Other information
- 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,SelectorandInitializerafter instantiate theGeneticAlgorithmclass. - You can create and set your own reporter in
GeneticAlgorithmclass.
Sample
Clone EvolveSharp and try the Travelling salesman problem sample
<img src="http://afonsof.github.io/EvolveSharp/images/tsp.png" />Contributing
Please use the issue tracker and pull requests.
License
Copyright (c) 2014 Afonso França Licensed under the MIT license.
Related Skills
node-connect
338.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.4kCommit, push, and open a PR



