Exemple #1
0
        internal static Dequation BuildEquation(Individual individual)
        {
            //create a dynamic method, specifying the name, return type, and parameter types
            DynamicMethod dMeth = new DynamicMethod(individual.EquationKey, typeof(double), new Type[] { typeof(int) });
            //then get an IL generator to build the method body
            ILGenerator ilGenerator = dMeth.GetILGenerator();

            //have the individual append the necessary IL to our generator based on its structure
            individual.AppendIL(ilGenerator);
            //lastly, instruct our method to return
            ilGenerator.Emit(OpCodes.Ret);

            return (Dequation)dMeth.CreateDelegate(typeof(Dequation));
        }
Exemple #2
0
 /// <summary>
 /// Creates a copy of this individual as a new instance.
 /// </summary>
 /// <returns>A new instance of this individaul</returns>
 public Individual CreateCopy()
 {
     var root = _root.GetCopy();
     root.IsLeftChild = false;
     var ind = new Individual(root);
     return ind;
 }