Ejemplo n.º 1
0
 internal Genome BuildGenome()
 {
     var outputs = new Node[_numOutputs];
     for (int i = 0; i < _numInputs; i++) {
         outputs[i] = RampedHalfAndHalf();
     }
     return new Genome(outputs, this);
 }
Ejemplo n.º 2
0
 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));
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 internal BinaryOperator(Node left, Node right)
     : base(2)
 {
     Left = left;
     Right = right;
 }
Ejemplo n.º 5
0
 internal override bool Find(Stack<Node> stack, Node target)
 {
     if (this == target) {
         stack.Push(this);
         return true;
     }
     return false;
 }
Ejemplo n.º 6
0
 internal override Node Clone(Stack<Node> chainToReplace, Node newNode)
 {
     Debugger.Break();
     throw new Exception("Can't replace child of a terminal");
 }
Ejemplo n.º 7
0
 internal SubtractOperator(Node left, Node right)
     : base(left, right)
 {
 }
Ejemplo n.º 8
0
 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};
 }
Ejemplo n.º 9
0
 internal ProtectedDivideOperator(Node left, Node right)
     : base(left, right)
 {
 }
Ejemplo n.º 10
0
 internal abstract bool Find(Stack<Node> stack, Node target);
Ejemplo n.º 11
0
 internal abstract Node Clone(Stack<Node> chainToReplace, Node newNode);
Ejemplo n.º 12
0
 internal MultiplyOperator(Node left, Node right)
     : base(left, right)
 {
 }
Ejemplo n.º 13
0
 internal ExponentOperator(Node left, Node right)
     : base(left, right)
 {
 }
Ejemplo n.º 14
0
 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));
      */
 }
Ejemplo n.º 15
0
 internal Genome(Node[] outputs, God god)
 {
     _outputs = outputs;
     Head = outputs[0];
     _god = god;
 }
Ejemplo n.º 16
0
 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));
 }
Ejemplo n.º 17
0
 private Node ReplaceRandomWith(Node newNode)
 {
     var result = GetRandomChain();
     return result.Count == 0 ? newNode : Head.Clone(result, newNode);
 }
Ejemplo n.º 18
0
 internal AddOperator(Node left, Node right)
     : base(left, right)
 {
 }