Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/01/13 12:08:25 (11 years ago)
Author:
jkarder
Message:

#2069:

  • refactored grammar and symbols
  • fixed cloning and storable ctors
  • fixed plugin dependencies
Location:
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Addition.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Addition : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Addition : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Addition(bool deserializing) : base(deserializing) { }
    40     private Addition(Addition original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Addition(bool deserializing) : base(deserializing) { }
     43    protected Addition(Addition original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Addition()
    4646      : base("Addition", "Addition operator.") {
    47       this.Prefix = "+";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" + ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Division.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Division : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Division : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Division(bool deserializing) : base(deserializing) { }
    40     private Division(Division original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Division(bool deserializing) : base(deserializing) { }
     43    protected Division(Division original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Division()
    4646      : base("Division", "Division operator.") {
    47       this.Prefix = "/";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" / ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Modulus.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Modulus : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Modulus : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Modulus(bool deserializing) : base(deserializing) { }
    40     private Modulus(Modulus original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Modulus(bool deserializing) : base(deserializing) { }
     43    protected Modulus(Modulus original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Modulus()
    4646      : base("Modulus", "Modulus operator.") {
    47       this.Prefix = "%";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" % ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Multiplication.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Multiplication : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Multiplication : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Multiplication(bool deserializing) : base(deserializing) { }
    40     private Multiplication(Multiplication original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Multiplication(bool deserializing) : base(deserializing) { }
     43    protected Multiplication(Multiplication original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Multiplication()
    4646      : base("Multiplication", "Multiplication operator.") {
    47       this.Prefix = "*";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" * ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
  • branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Numerical Expressions/Numerical Operators/Subtraction.cs

    r9790 r10011  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     
    2629namespace HeuristicLab.Problems.Robocode {
    2730  [StorableClass]
    28   public class Subtraction : CodeNode {
    29     public override int MinimumArity { get { return 0; } }
    30     public override int MaximumArity { get { return 0; } }
     31  public class Subtraction : CodeNode, INumericalOperator {
     32    public override int MinimumArity { get { return 2; } }
     33    public override int MaximumArity { get { return byte.MaxValue; } }
    3134
    3235    [Storable]
     
    3740
    3841    [StorableConstructor]
    39     private Subtraction(bool deserializing) : base(deserializing) { }
    40     private Subtraction(Subtraction original, Cloner cloner)
    41       : base(original, cloner) {
    42 
    43     }
     42    protected Subtraction(bool deserializing) : base(deserializing) { }
     43    protected Subtraction(Subtraction original, Cloner cloner) : base(original, cloner) { }
    4444
    4545    public Subtraction()
    4646      : base("Subtraction", "Subtraction operator.") {
    47       this.Prefix = "-";
    48       this.Suffix = "";
     47      Prefix = "(";
     48      Suffix = ")";
    4949    }
    5050
     
    5353    }
    5454
    55     public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
    56       return this.Prefix + this.Suffix;
     55    public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) {
     56      if (children.Count() < 2)
     57        throw new ArgumentException("Expected at leaset 2 children.", "children");
     58
     59      string result = string.Join(" - ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees)));
     60      return Prefix + result + Suffix;
    5761    }
    5862  }
Note: See TracChangeset for help on using the changeset viewer.