Exemplo n.º 1
0
		public void Collapse() {
			if( Left is MathOp ) {
				( (MathOp)Left ).Collapse();
			}
			if( Right is MathOp ) {
				( (MathOp)Right ).Collapse();
			}
			if( Left.IsStatic() ) {
				MathValue val = new MathValue();
				val.Value = Left.Evaluate( null );
				Left = val;
			}
			if( Right.IsStatic() ) {
				MathValue val = new MathValue();
				val.Value = Right.Evaluate( null );
				Right = val;
			}
		}
Exemplo n.º 2
0
		public override MathLiteral Clone() {
			MathValue clone = new MathValue();
			clone.Value = Value;
			return clone;
		}
Exemplo n.º 3
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();
			}
		}
Exemplo n.º 4
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();
            }
        }