/** Builds a Push Interpreter suitable for interpreting the Program given in getProgram(). */ public Interpreter GetInterpreter(IEvolutionState state, GPIndividual ind, int threadnum) { // create an Interpreter with an IMersenneTwister RNG Interpreter interpreter = new Interpreter(state.Random[threadnum]); // Find the function set GPFunctionSet set = ind.Trees[0].Constraints((GPInitializer)(state.Initializer)).FunctionSet; GPNode[] terminals = set.Terminals[0]; // only one type we assume // dump the additional instructions into the interpreter foreach (GPNode t in terminals) { if (t is Terminal) // maybe has some instructions? { // This code is here rather than (more appropriately) in Terminal so that we can // free up Terminal from being reliant on the underlying library. Terminal op = (Terminal)(t); PushInstruction[] customInstructions = op.CustomInstructions; int[] indices = op.Indices; String[] instructions = op.Instructions; for (int j = 0; j < customInstructions.Length; j++) { Console.Error.WriteLine(instructions[indices[j]]); interpreter.AddInstruction(instructions[indices[j]], (PushInstruction)customInstructions[j].Clone()); // or should this be DefineInstruction? } } } // all done return(interpreter); }