I would recommend against creating assemblies if you absolutely do not need it, especially if you are just starting out with a genetic algorithm.
The genetic algorithm is easiest to implement when the target language is functional and dynamically typed. That is why most studies of the genetic algorithm are 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 a tree generation algorithm and just interpreting the trees when the time comes to start each iteration of the algorithm,
I did such a project when I was in college (implementing the genetic algorithm in C #), and that was the approach I took.
Performing this method will give you the advantage of only having 1 view for working with (AST view), which is optimally suited for both executing and “propagating” the genetic algorithm.
Alternatively, if you try to generate assemblies, you will probably end up adding a lot of unnecessary complexity to the application. Currently, the CLR does not allow you to unload the assembly from the application domain if the entire application domain is not destroyed. This would mean that you would need to deploy a separate application domain for each generated program at each iteration of the algorithm to avoid introducing a giant memory leak into your application. In general, all this will simply add a bunch of unnecessary annoyance.
Interpreted ASTs, on the other hand, collect garbage like any other object, and therefore you do not need to become desecrated with multiple application domains. If for performance reasons you want to get gen-code, you can add the final result later. However, I would recommend that you do this using the DynamicMethod class. This will allow you to convert the AST to a compiled delegate dynamically at runtime. This will allow you to deploy a single DLL, while keeping the code generation material as simple as possible. In addition, DynamicMethod instances are garbage collectors, so you can use them as part of a genetic algorithm to speed things up there.
Scott Wisniewski Aug 26 '08 at 6:14 2008-08-26 06:14
source share