<p>I've been looking for some good genetic programming examples for C#. Anyone knows of good online/book resources? Wonder if there is a C# library out there for Evolutionary/Genetic programming?</p>

[{'answer_id': 14009, 'author': 'Judah Gabriel Himango', 'author_id': 536, 'author_profile': 'https://Stackoverflow.com/users/536', 'pm_score': 5, 'selected': False, 'text': '<p>MSDN had an article last year about genetic programming: <a href="http://msdn.microsoft.com/en-us/magazine/cc163934.aspx" rel="noreferrer">Genetic Algorithms: Survival of the Fittest with Windows Forms</a></p>\n'}, {'answer_id': 14010, 'author': 'denis phillips', 'author_id': 748, 'author_profile': 'https://Stackoverflow.com/users/748', 'pm_score': 3, 'selected': False, 'text': '<p>I saw a good high-level discussion of it on channel9 by Mike Swanson at <a href="http://channel9.msdn.com/posts/Charles/Algorithms-and-Data-Structures-Mike-Swanson-Genetic-Session-Scheduler/" rel="noreferrer">http://channel9.msdn.com/posts/Charles/Algorithms-and-Data-Structures-Mike-Swanson-Genetic-Session-Scheduler/</a></p>\n'}, {'answer_id': 14063, 'author': 'mgsloan', 'author_id': 1164871, 'author_profile': 'https://Stackoverflow.com/users/1164871', 'pm_score': 2, 'selected': False, 'text': '<p>Do you mean actual genetic programming, as opposed to genetic algorithms in general?</p>\n\n<p>If so, C#/.net isn\'t the best language for it.  LISP, for example, has always been a mainstay of GP.</p>\n\n<p>However, if you must, you\'re probably going to want to dynamically generate CIL / MSIL.  You could do this using <a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.aspx" rel="nofollow noreferrer">System.Reflection.Emit</a>, however I\'d recommend <a href="http://www.mono-project.com/Cecil" rel="nofollow noreferrer">Mono.Cecil</a>.  It lacks good docs (as if reflection emit has them).. But it offers much better assembly emission and reflection.</p>\n\n<p>Another issue is that it is less than trivial to load code, and later dispose of it, in the .net framework.  At least, you cannot unload assemblies.  You can unload appdomains, but the whole business of loading code into a seperate appdomain, and calling it externally can get pretty messy.  .NET 3.5\'s System.Addin stuff should make this easier.</p>\n'}, {'answer_id': 14066, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 3, 'selected': False, 'text': "<p>You might be able to implement genetic programming using LINQ expression trees -- it's more likely to generate something usable than random IL generation.</p>\n"}, {'answer_id': 27476, 'author': 'Scott Wisniewski', 'author_id': 1737192, 'author_profile': 'https://Stackoverflow.com/users/1737192', 'pm_score': 4, 'selected': False, 'text': '<p>I would recommend against actually generating assemblies unless you absolutely need to, particularly if you are just getting started with implementing the genetic algorithm.</p>\n\n<p>The genetic algorithm is easiest to implement when the target language is functional and dynamically typed. That is generally why most genetic algorithm research is written in LISP. As a result, if you are going to implement it in C#, you are probably better off defining your own mini "tree language", having the algorithm generate trees, and just interpreting the trees when it comes time to run each iteration of the algorithm. </p>\n\n<p>I did a project like this when I was in college (an implementation of the genetic algorithm in C#), and that was the approach I took.</p>\n\n<p>Doing it that way will give you the advantage of only having 1 representation to work with (the AST representation) that is optimally suited for both execution and the genetic algorithm "reproduction" steps. </p>\n\n<p>Alternatively, if you try to generate assemblies you are probably going to end up adding a large amount of unneeded complexity to the app. Currently, the CLR does not allow an assembly to be unloaded from an App domain unless the entire app domain is destroyed. This would mean that you would need to spin up a separate app domain for each generated program in each iteration of the algorithm to avoid introducing a giant memory leak into your app. In general, the whole thing would just add a bunch of extra irritation.</p>\n\n<p>Interpreted AST\'s, on the other hand, are garbage collectible just like any other object, and so you wouldn\'t need to monkey around with multiple app domains. If, for performance reasons you want to code-gen the final result you can add support for that later. However, I you would recommend that you do that using the <a href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.dynamicmethod.aspx" rel="noreferrer">DynamicMethod</a> class. It will allow you to convert an AST into a compiled delegate dynamically at runtime. That will enable you to deploy a single DLL while keeping the code generation stuff as simple as possible. Also, DynamicMethod instances are garbage collectible so you could end up employing them as part of the genetic algorithm to speed things up there as well.</p>\n'}, {'answer_id': 131258, 'author': 'Jason Jackson', 'author_id': 13103, 'author_profile': 'https://Stackoverflow.com/users/13103', 'pm_score': 2, 'selected': False, 'text': '<p>I am reading <a href="http://www.gp-field-guide.org.uk/" rel="nofollow noreferrer">A Field Guide to Genetic Programming</a> right now (free PDF download).  It is also available as a paperback.  It discuses the use of a library written in Java called <a href="http://cswww.essex.ac.uk/staff/rpoli/TinyGP/" rel="nofollow noreferrer">TinyGP</a>.  You might get some mileage out of that.  I have not started doing any actual programming but am hoping to applies some of the concepts in C#.</p>\n'}, {'answer_id': 224097, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>I maintain a port of ECJ in C#. It's great.</p>\n"}, {'answer_id': 1030053, 'author': 'Jader Dias', 'author_id': 48465, 'author_profile': 'https://Stackoverflow.com/users/48465', 'pm_score': 6, 'selected': True, 'text': '<p>After developing <a href="http://code.google.com/p/evo-lisa-clone/" rel="noreferrer">my own Genetic Programming didactic application</a>, I found a complete Genetic Programming Framework called <a href="http://code.google.com/p/aforge/source/browse/#svn/trunk/Sources/Genetic" rel="noreferrer">AForge.NET Genetics</a>. It\'s a part of the <a href="http://code.google.com/p/aforge/" rel="noreferrer">Aforge.NET library</a>. It\'s licensed under LGPL.</p>\n'}, {'answer_id': 6203431, 'author': 'bstabile', 'author_id': 778481, 'author_profile': 'https://Stackoverflow.com/users/778481', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve forked ECJ to C# .NET 4.0 if you are interested in a full-featured Evolutionary Computation framework. The package includes everything from the original ECJ Java project, including all of the working samples. </p>\n\n<p>I also wrote 500 unit tests to verify many aspects of the conversion. But many more tests are needed. In particular, the distributed computation aspects are not fully tested. That\'s because I plan on converting from ECJ\'s simple use of sockets to a more robust strategy using WCF and WF. I\'ll also be reworking the framework to utilize TPL (Task Parallel Library).</p>\n\n<p>Anyway, you can download the initial conversion here:</p>\n\n<p><a href="http://branecloud.codeplex.com" rel="nofollow">http://branecloud.codeplex.com</a></p>\n\n<p>I am also in the process of converting several other frameworks from Java to .NET that relate to "synthetic intelligence" research (when I can find the time).</p>\n\n<p>Ben</p>\n'}, {'answer_id': 7797614, 'author': 'Andreas', 'author_id': 189767, 'author_profile': 'https://Stackoverflow.com/users/189767', 'pm_score': 3, 'selected': False, 'text': '<p>If you\'re interested in genetic algorithms or heuristic optimization in general you might want to take a look at <a href="http://dev.heuristiclab.com" rel="noreferrer">HeuristicLab</a>. It is developed for several years, 1.5 years since we released the new version. It is programmed in C# 4 and has a nice GUI. There are many algorithms already available like Genetic Algorithm, Genetic Programming, Evolution Strategy, Local Search, Tabu Search, Particle Swarm Optimization, Simulated Annealing and more. There are also several problems implemented like a vehicle routing problem, traveling salesman, real function optimization, knapsack, quadratic assignment problem, classification, regression, and many more. There are tutorials also and we have protocol buffers integrated so you can communicate with external programs for solution evaluation. It is licensed under GPL. In 2009 the software has received the Microsoft innovation award of Microsoft Austria.</p>\n\n<p>We\'ve also written a book on the subject: <a href="https://rads.stackoverflow.com/amzn/click/com/1584886293" rel="noreferrer" rel="nofollow noreferrer">Genetic Algorithms and Genetic Programming</a>.</p>\n'}, {'answer_id': 23791487, 'author': 'cs0815', 'author_id': 283538, 'author_profile': 'https://Stackoverflow.com/users/283538', 'pm_score': 2, 'selected': False, 'text': '<p>The Manning book: "<a href="http://www.amazon.co.uk/Metaprogramming-NET-Kevin-Hazzard/dp/1617290262" rel="nofollow">Metaprogramming in .NET</a>" dedicates a large section on GP via expression trees. </p>\n'}, {'answer_id': 24674105, 'author': 'giacomelli', 'author_id': 956886, 'author_profile': 'https://Stackoverflow.com/users/956886', 'pm_score': 2, 'selected': False, 'text': '<p>You can try <a href="https://github.com/giacomelli/GeneticSharp" rel="nofollow">GeneticSharp</a>.</p>\n\n<p>It has all classic GA operations, like selection, crossover, mutation, reinsertion and termination.</p>\n\n<p>It\'s very extensible, you can define your own chromosomes, fitness function, population generation strategy and all cited operations above too.</p>\n\n<p>It can be used in many kind of apps, like C# libraries and Unity 3D games, there is samples running it in a <a href="https://github.com/giacomelli/GeneticSharp/tree/master/src/GeneticSharp.Runner.GtkApp" rel="nofollow">GTK# app</a> and <a href="https://github.com/giacomelli/GeneticSharp/tree/master/src/Samples/Unity/Checkers" rel="nofollow">Unity 3D checkers game</a>.</p>\n\n<p>It also works in Win and OSX.</p>\n\n<p>Here is a basic sample how to use the library:</p>\n\n<pre><code>var selection = new EliteSelection();\nvar crossover = new OrderedCrossover();\nvar mutation = new ReverseSequenceMutation();\nvar fitness = new YourFitnessFunction();\nvar chromosome = new YourChromosome();\nvar population = new Population (50, 70, chromosome);\n\nvar ga = new GeneticAlgorithm(population, fitness, selection, crossover, mutation);\n\nga.Start();\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/14008', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/877/']