/// <inheritdoc /> public void PerformOperation(EncogRandom rnd, IGenome[] parents, int parentIndex, IGenome[] offspring, int offspringIndex) { var program = (EncogProgram)parents[0]; EncogProgramContext context = program.Context; EncogProgram result = context.CloneProgram(program); MutateNode(rnd, result.RootNode); offspring[0] = result; }
/// <inheritdoc /> public void PerformOperation(EncogRandom rnd, IGenome[] parents, int parentIndex, IGenome[] offspring, int offspringIndex) { var parent1 = (EncogProgram)parents[0]; var parent2 = (EncogProgram)parents[1]; offspring[0] = null; EncogProgramContext context = parent1.Context; int size1 = parent1.RootNode.Count; int size2 = parent2.RootNode.Count; bool done = false; int tries = 100; while (!done) { int p1Index = rnd.Next(size1); int p2Index = rnd.Next(size2); var holder1 = new LevelHolder(p1Index); var holder2 = new LevelHolder(p2Index); IList <EPLValueType> types = new List <EPLValueType>(); types.Add(context.Result.VariableType); FindNode(rnd, parent1.RootNode, types, holder1); FindNode(rnd, parent2.RootNode, types, holder2); if (LevelHolder.CompatibleTypes(holder1.Types, holder2.Types)) { EncogProgram result = context.CloneProgram(parent1); ProgramNode resultNode = parent1.FindNode(p1Index); ProgramNode p2Node = parent2.FindNode(p2Index); ProgramNode newInsert = context.CloneBranch(result, p2Node); result.ReplaceNode(resultNode, newInsert); offspring[0] = result; done = true; } else { tries--; if (tries < 0) { done = true; } } } }
/// <inheritdoc /> public void PerformOperation(EncogRandom rnd, IGenome[] parents, int parentIndex, IGenome[] offspring, int offspringIndex) { var program = (EncogProgram)parents[0]; EncogProgramContext context = program.Context; EncogProgram result = context.CloneProgram(program); IList <EPLValueType> types = new List <EPLValueType>(); types.Add(context.Result.VariableType); var globalIndex = new int[1]; globalIndex[0] = rnd.Next(result.RootNode.Count); FindNode(rnd, result, result.RootNode, types, globalIndex); offspring[0] = result; }