private Element InternalMutate(Element element, int mutationDepth, int currentDepth) { if (!_canStillSwap) { return element; } if (currentDepth == mutationDepth) { var valueElement = element as ValueElement; if (valueElement != null) { return MutateValueElement(); } var binaryElement = element as BinaryOperator; if (binaryElement != null) { return MutateBinaryElement(binaryElement); } } else { var binaryOperator = element as BinaryOperator; if (binaryOperator != null) { var leftChild = binaryOperator.LeftElement; var rightChild = binaryOperator.RightElement; ++currentDepth; leftChild = InternalMutate(leftChild, mutationDepth, currentDepth); rightChild = InternalMutate(rightChild, mutationDepth, currentDepth); binaryOperator.LeftElement = leftChild; binaryOperator.RightElement = rightChild; } } return element; }
public void AddOperations(Element element) { _nodes = element; GetTreeDepth(); }
public void Mutate() { _canStillSwap = true; var mutationDepth = GetMutationDepth(); var currentDepth = 0; _nodes = InternalMutate(_nodes, mutationDepth, currentDepth); }