4

How can I write genetic algorithms in C#? Are there libraries available? Like C++: http://lancet.mit.edu/ga/

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Penguen
  • 16,836
  • 42
  • 130
  • 205

4 Answers4

5

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.

Matthew Lock
  • 13,144
  • 12
  • 92
  • 130
Chris S
  • 64,770
  • 52
  • 221
  • 239
2

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#

Community
  • 1
  • 1
Marek
  • 2,419
  • 6
  • 34
  • 38
0

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.

JohnIdol
  • 48,899
  • 61
  • 158
  • 242
0

You can find some genetic algorithm information for C# on CodeProject.

Lucero
  • 59,176
  • 9
  • 122
  • 152