How can I write genetic algorithms in C#? Are there libraries available? Like C++: http://lancet.mit.edu/ga/
-
1Probably Genetic Algorithms. Just a guess based on the title to his question. – Alan Apr 14 '09 at 19:03
4 Answers
This may sound like a facetious answer, but you will want to firstly decide what you want the genetic algorithm to solve. As mentioned the Travelling Sales Person problem is a common one and a fairly good way of learning how they work.
I say this as one the most important parts of a GA is the fitness function, which no framework is going to write for you.
This codeproject article from 2003 does cover:
- Fitness functions
- Biased roulette wheels
- Mutation
It's easy to use:
GA ga = new GA(crossover rate,
mutation rate,
population size,
number of generations,
number of parameters for the fitness function);
ga.FitnessFunction = new GAFunction(theActualFunction);
This could be upgraded to .NET 3:
ga.FitnessFunction = delegate(double[] values)
{
return 1.2d;
};
As you can see the fitness function for this expects your genes to be represented as double values (rather than for example bit strings).
However (and this is not dismissing the article, which is good), you could write this quite easily yourself providing you know how basic GAs work.

- 13,144
- 12
- 92
- 130

- 64,770
- 52
- 221
- 239
-
1Actually the AForge.net genetic suite tackles the travelling salesman problem, and the source is included. – Patrick McCurley Apr 03 '12 at 16:28
-
There's a nice discussion about using GAs to tackle the traveling salesman problem here: http://www.lalena.com/AI/Tsp/ – Matthew Lock Mar 27 '13 at 01:51
There is a nice framework "AForge.NET Genetics" which will give you more than just "hello world" example you can find on codeproject. See duplicate post Genetic Programming in C#
I developed a simple GA showcase project in C#. It's the hello world of genetic algorithms, and I built the example on a set of interfaces that are general enough to be used as a pattern for developing genetic algorithms.
You can find code and documentation (including an Enterprise Architect doc including design diagrams) on the github page. You can also download the executable to see it in action.
Hope it helps.

- 48,899
- 61
- 158
- 242