Esempio n. 1
0
		public override void Mutate() {
			//add
			if( Tool.Mutate( 100 ) ) {
				MathOp op = new MathOp();
				op.Left = BaseOp;
				BaseOp = op;
			}

			BaseOp.Mutate();
		}
Esempio n. 2
0
        public override MathLiteral Clone()
        {
            MathOp clone = new MathOp();

            clone.Operator = Operator;
            clone.Left     = Left.Clone();
            clone.Right    = Right.Clone();

            return(clone);
        }
Esempio n. 3
0
		private void TraverseNode( MathOp op, List<MathOp> nodes ) {
			nodes.Add( op );
			if( op.Left is MathOp ) {
				TraverseNode( op.Left as MathOp, nodes );
			}

			if( op.Right is MathOp ) {
				TraverseNode( op.Right as MathOp, nodes );
			}
		}
Esempio n. 4
0
        public Organism MakeCrossOver(Organism father)
        {
            Organism child     = this.Clone();
            MathOp   fatherDna = (MathOp)father.GetRandomNode().Clone();
            MathOp   motherDna = child.GetRandomNode();

            motherDna.Left  = fatherDna.Left;
            motherDna.Right = fatherDna.Right;

            return(child);
        }
Esempio n. 5
0
        public override void Mutate()
        {
            //add
            if (Tool.Mutate(100))
            {
                MathOp op = new MathOp();
                op.Left = BaseOp;
                BaseOp  = op;
            }

            BaseOp.Mutate();
        }
Esempio n. 6
0
        private void TraverseNode(MathOp op, List <MathOp> nodes)
        {
            nodes.Add(op);
            if (op.Left is MathOp)
            {
                TraverseNode(op.Left as MathOp, nodes);
            }

            if (op.Right is MathOp)
            {
                TraverseNode(op.Right as MathOp, nodes);
            }
        }
Esempio n. 7
0
		public override void Mutate() {
			//swap
			if( Tool.Mutate( 100 ) ) {
				MathLiteral tmp = Left;
				Left = Right;
				Right = tmp;
			}

			if( Tool.Mutate( 100 ) ) {
				this.Collapse();
			}

			if( Tool.Mutate( 15 ) ) {
				if( Left.IsStatic() ) {
					MathValue val = new MathValue();
					val.Value = Left.Evaluate( null );
					Left = val;
				}
			}

			if( Tool.Mutate( 15 ) ) {
				if( Right.IsStatic() ) {
					MathValue val = new MathValue();
					val.Value = Right.Evaluate( null );
					Right = val;
				}
			}

			//delete
			if( Tool.Mutate( 15 ) ) {
				if( Left is MathOp ) {
					MathLiteral grandChild = ( (MathOp)Left ).Left;
					Left = grandChild;
				}

			}

			//delete
			if( Tool.Mutate( 15 ) ) {
				if( Left is MathOp ) {
					MathLiteral grandChild = ( (MathOp)Left ).Right;
					Left = grandChild;
				}

			}

			//delete
			if( Tool.Mutate( 15 ) ) {
				if( Right is MathOp ) {
					MathLiteral grandChild = ( (MathOp)Right ).Right;
					Right = grandChild;
				}

			}

			//delete
			if( Tool.Mutate( 15 ) ) {
				if( Right is MathOp ) {
					MathLiteral grandChild = ( (MathOp)Right ).Left;
					Right = grandChild;
				}

			}

			//add
			if( Tool.Mutate( 100 ) ) {
				MathOp op = new MathOp();
				op.Left = Left;
				Left = op;
			}

			//add
			if( Tool.Mutate( 100 ) ) {
				MathOp op = new MathOp();
				op.Right = Right;
				Right = op;
			}

			//replace
			if( Tool.Mutate( 30 ) ) {
				MathLiteral newLeft = CreateRandomNode();
				Left = newLeft;
			}

			//replace
			if( Tool.Mutate( 30 ) ) {
				MathLiteral newRight = CreateRandomNode();
				Right = newRight;
			}

			Left.Mutate();
			Right.Mutate();
			if( Tool.Mutate( 50 ) ) {
				MutateOp();
			}
		}
Esempio n. 8
0
		public override MathLiteral Clone() {
			MathOp clone = new MathOp();
			clone.Operator = Operator;
			clone.Left = Left.Clone();
			clone.Right = Right.Clone();

			return clone;
		}
Esempio n. 9
0
        public override void Mutate()
        {
            //swap
            if (Tool.Mutate(100))
            {
                MathLiteral tmp = Left;
                Left  = Right;
                Right = tmp;
            }

            if (Tool.Mutate(100))
            {
                this.Collapse();
            }

            if (Tool.Mutate(15))
            {
                if (Left.IsStatic())
                {
                    MathValue val = new MathValue();
                    val.Value = Left.Evaluate(null);
                    Left      = val;
                }
            }

            if (Tool.Mutate(15))
            {
                if (Right.IsStatic())
                {
                    MathValue val = new MathValue();
                    val.Value = Right.Evaluate(null);
                    Right     = val;
                }
            }

            //delete
            if (Tool.Mutate(15))
            {
                if (Left is MathOp)
                {
                    MathLiteral grandChild = ((MathOp)Left).Left;
                    Left = grandChild;
                }
            }

            //delete
            if (Tool.Mutate(15))
            {
                if (Left is MathOp)
                {
                    MathLiteral grandChild = ((MathOp)Left).Right;
                    Left = grandChild;
                }
            }

            //delete
            if (Tool.Mutate(15))
            {
                if (Right is MathOp)
                {
                    MathLiteral grandChild = ((MathOp)Right).Right;
                    Right = grandChild;
                }
            }

            //delete
            if (Tool.Mutate(15))
            {
                if (Right is MathOp)
                {
                    MathLiteral grandChild = ((MathOp)Right).Left;
                    Right = grandChild;
                }
            }

            //add
            if (Tool.Mutate(100))
            {
                MathOp op = new MathOp();
                op.Left = Left;
                Left    = op;
            }

            //add
            if (Tool.Mutate(100))
            {
                MathOp op = new MathOp();
                op.Right = Right;
                Right    = op;
            }

            //replace
            if (Tool.Mutate(30))
            {
                MathLiteral newLeft = CreateRandomNode();
                Left = newLeft;
            }

            //replace
            if (Tool.Mutate(30))
            {
                MathLiteral newRight = CreateRandomNode();
                Right = newRight;
            }

            Left.Mutate();
            Right.Mutate();
            if (Tool.Mutate(50))
            {
                MutateOp();
            }
        }