internal Genome BuildGenome() { var outputs = new Node[_numOutputs]; for (int i = 0; i < _numInputs; i++) { outputs[i] = RampedHalfAndHalf(); } return new Genome(outputs, this); }
internal override Node Clone(Stack<Node> chainToReplace, Node newNode) { var replacedChild = chainToReplace.Pop(); if (chainToReplace.Count == 0) { return replacedChild == Left ? new AddOperator(newNode, Right) : new AddOperator(Left, newNode); } return replacedChild == Left ? new AddOperator(Left.Clone(chainToReplace, newNode), Right) : new AddOperator(Left, Right.Clone(chainToReplace, newNode)); }
internal override bool Find(Stack<Node> stack, Node target) { bool result = this == target || Left.Find(stack, target) || Right.Find(stack, target); if (result) { stack.Push(this); } return result; }
internal BinaryOperator(Node left, Node right) : base(2) { Left = left; Right = right; }
internal override bool Find(Stack<Node> stack, Node target) { if (this == target) { stack.Push(this); return true; } return false; }
internal override Node Clone(Stack<Node> chainToReplace, Node newNode) { Debugger.Break(); throw new Exception("Can't replace child of a terminal"); }
internal SubtractOperator(Node left, Node right) : base(left, right) { }
internal CompareOperator(Node a, Node b, Node c, Node d) : base(4) { _a = a; _b = b; _c = c; _d = d; _children = new[] {_a, _b, _c, _d}; }
internal ProtectedDivideOperator(Node left, Node right) : base(left, right) { }
internal abstract bool Find(Stack<Node> stack, Node target);
internal abstract Node Clone(Stack<Node> chainToReplace, Node newNode);
internal MultiplyOperator(Node left, Node right) : base(left, right) { }
internal ExponentOperator(Node left, Node right) : base(left, right) { }
internal override Node Clone(Stack<Node> chainToReplace, Node newNode) { throw new OperationCanceledException(); /* var replacedChild = chainToReplace.Pop(); Node a, b, c, d; return chainToReplace.Count == 0 ? ( replacedChild == Left ? new ExponentOperator(newNode, Right) : new ExponentOperator(Left, newNode)) : replacedChild == Left ? new ExponentOperator(Left.Clone(chainToReplace, newNode), Right) : new ExponentOperator(Left, Right.Clone(chainToReplace, newNode)); */ }
internal Genome(Node[] outputs, God god) { _outputs = outputs; Head = outputs[0]; _god = god; }
internal override Node Clone(Stack<Node> chainToReplace, Node newNode) { var replacedChild = chainToReplace.Pop(); return chainToReplace.Count == 0 ? ( replacedChild == Left ? new ProtectedDivideOperator(newNode, Right) : new ProtectedDivideOperator(Left, newNode)) : replacedChild == Left ? new ProtectedDivideOperator(Left.Clone(chainToReplace, newNode), Right) : new ProtectedDivideOperator(Left, Right.Clone(chainToReplace, newNode)); }
private Node ReplaceRandomWith(Node newNode) { var result = GetRandomChain(); return result.Count == 0 ? newNode : Head.Clone(result, newNode); }
internal AddOperator(Node left, Node right) : base(left, right) { }