public override void Mutate() { //add if( Tool.Mutate( 100 ) ) { MathOp op = new MathOp(); op.Left = BaseOp; BaseOp = op; } BaseOp.Mutate(); }
public override MathLiteral Clone() { MathOp clone = new MathOp(); clone.Operator = Operator; clone.Left = Left.Clone(); clone.Right = Right.Clone(); return(clone); }
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 ); } }
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); }
public override void Mutate() { //add if (Tool.Mutate(100)) { MathOp op = new MathOp(); op.Left = BaseOp; BaseOp = op; } BaseOp.Mutate(); }
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); } }
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(); } }
public override MathLiteral Clone() { MathOp clone = new MathOp(); clone.Operator = Operator; clone.Left = Left.Clone(); clone.Right = Right.Clone(); return clone; }
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(); } }