Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/14/13 11:03:13 (12 years ago)
Author:
ascheibe
Message:

#2069 fixed cloning constructors and formatting

Location:
branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/Logical Comparators/Conjunction.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class Conjunction : CodeNode
    9     {
    10         public override int MinimumArity { get { return 0; } }
    11         public override int MaximumArity { get { return 0; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class Conjunction : CodeNode {
     8    public override int MinimumArity { get { return 0; } }
     9    public override int MaximumArity { get { return 0; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private Conjunction(bool deserializing) : base(deserializing) { }
    21         private Conjunction(Conjunction original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "&&";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private Conjunction(bool deserializing) : base(deserializing) { }
     19    private Conjunction(Conjunction original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public Conjunction()
    29             : base("Conjunction", "Conjunction comparator.")
    30         {
    31             this.Prefix = "&&";
    32             this.Suffix = "";
    33         }
     23    public Conjunction()
     24      : base("Conjunction", "Conjunction comparator.") {
     25      this.Prefix = "&&";
     26      this.Suffix = "";
     27    }
    3428
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new Conjunction(this, cloner);
    38         }
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new Conjunction(this, cloner);
     31    }
    3932
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             return this.Prefix + " " + this.Suffix;
    43         }
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      return this.Prefix + " " + this.Suffix;
    4435    }
     36  }
    4537}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/Logical Comparators/Disjunction.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class Disjunction : CodeNode
    9     {
    10         public override int MinimumArity { get { return 0; } }
    11         public override int MaximumArity { get { return 0; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class Disjunction : CodeNode {
     8    public override int MinimumArity { get { return 0; } }
     9    public override int MaximumArity { get { return 0; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private Disjunction(bool deserializing) : base(deserializing) { }
    21         private Disjunction(Disjunction original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "||";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private Disjunction(bool deserializing) : base(deserializing) { }
     19    private Disjunction(Disjunction original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public Disjunction()
    29             : base("Disjunction", "Disjunction comparator.")
    30         {
    31             this.Prefix = "||";
    32             this.Suffix = "";
    33         }
     23    public Disjunction()
     24      : base("Disjunction", "Disjunction comparator.") {
     25      this.Prefix = "||";
     26      this.Suffix = "";
     27    }
    3428
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new Disjunction(this, cloner);
    38         }
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new Disjunction(this, cloner);
     31    }
    3932
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             return this.Prefix + " " + this.Suffix;
    43         }
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      return this.Prefix + " " + this.Suffix;
    4435    }
     36  }
    4537}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/Logical Comparators/Equal.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class Equal : CodeNode
    9     {
    10         public override int MinimumArity { get { return 0; } }
    11         public override int MaximumArity { get { return 0; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class Equal : CodeNode {
     8    public override int MinimumArity { get { return 0; } }
     9    public override int MaximumArity { get { return 0; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private Equal(bool deserializing) : base(deserializing) { }
    21         private Equal(Equal original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "==";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private Equal(bool deserializing) : base(deserializing) { }
     19    private Equal(Equal original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public Equal()
    29             : base("Equal", "Equal comparator.")
    30         {
    31             this.Prefix = "==";
    32             this.Suffix = "";
    33         }
     23    public Equal()
     24      : base("Equal", "Equal comparator.") {
     25      this.Prefix = "==";
     26      this.Suffix = "";
     27    }
    3428
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new Equal(this, cloner);
    38         }
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new Equal(this, cloner);
     31    }
    3932
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             return this.Prefix + " " + this.Suffix;
    43         }
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      return this.Prefix + " " + this.Suffix;
    4435    }
     36  }
    4537}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/Logical Comparators/GreaterThan.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class GreaterThan : CodeNode
    9     {
    10         public override int MinimumArity { get { return 0; } }
    11         public override int MaximumArity { get { return 0; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class GreaterThan : CodeNode {
     8    public override int MinimumArity { get { return 0; } }
     9    public override int MaximumArity { get { return 0; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private GreaterThan(bool deserializing) : base(deserializing) { }
    21         private GreaterThan(GreaterThan original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = ">";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private GreaterThan(bool deserializing) : base(deserializing) { }
     19    private GreaterThan(GreaterThan original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public GreaterThan()
    29             : base("GreaterThan", "GreaterThan comparator.")
    30         {
    31             this.Prefix = ">";
    32             this.Suffix = "";
    33         }
     23    public GreaterThan()
     24      : base("GreaterThan", "GreaterThan comparator.") {
     25      this.Prefix = ">";
     26      this.Suffix = "";
     27    }
    3428
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new GreaterThan(this, cloner);
    38         }
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new GreaterThan(this, cloner);
     31    }
    3932
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             return this.Prefix + " " + this.Suffix;
    43         }
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      return this.Prefix + " " + this.Suffix;
    4435    }
     36  }
    4537}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/Logical Comparators/GreaterThanOrEqual.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class GreaterThanOrEqual : CodeNode
    9     {
    10         public override int MinimumArity { get { return 0; } }
    11         public override int MaximumArity { get { return 0; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class GreaterThanOrEqual : CodeNode {
     8    public override int MinimumArity { get { return 0; } }
     9    public override int MaximumArity { get { return 0; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private GreaterThanOrEqual(bool deserializing) : base(deserializing) { }
    21         private GreaterThanOrEqual(GreaterThanOrEqual original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = ">=";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private GreaterThanOrEqual(bool deserializing) : base(deserializing) { }
     19    private GreaterThanOrEqual(GreaterThanOrEqual original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public GreaterThanOrEqual()
    29             : base("GreaterThanOrEqual", "GreaterThanOrEqual comparator.")
    30         {
    31             this.Prefix = ">=";
    32             this.Suffix = "";
    33         }
     23    public GreaterThanOrEqual()
     24      : base("GreaterThanOrEqual", "GreaterThanOrEqual comparator.") {
     25      this.Prefix = ">=";
     26      this.Suffix = "";
     27    }
    3428
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new GreaterThanOrEqual(this, cloner);
    38         }
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new GreaterThanOrEqual(this, cloner);
     31    }
    3932
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             return this.Prefix + " " + this.Suffix;
    43         }
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      return this.Prefix + " " + this.Suffix;
    4435    }
     36  }
    4537}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/Logical Comparators/LessThan.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class LessThan : CodeNode
    9     {
    10         public override int MinimumArity { get { return 0; } }
    11         public override int MaximumArity { get { return 0; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class LessThan : CodeNode {
     8    public override int MinimumArity { get { return 0; } }
     9    public override int MaximumArity { get { return 0; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private LessThan(bool deserializing) : base(deserializing) { }
    21         private LessThan(LessThan original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "<";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private LessThan(bool deserializing) : base(deserializing) { }
     19    private LessThan(LessThan original, Cloner cloner)
     20      : base(original, cloner) {
    2721
    28         public LessThan()
    29             : base("LessThan", "LessThan comparator.")
    30         {
    31             this.Prefix = "<";
    32             this.Suffix = "";
    33         }
     22    }
    3423
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new LessThan(this, cloner);
    38         }
     24    public LessThan()
     25      : base("LessThan", "LessThan comparator.") {
     26      this.Prefix = "<";
     27      this.Suffix = "";
     28    }
    3929
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             return this.Prefix + " " + this.Suffix;
    43         }
     30    public override IDeepCloneable Clone(Cloner cloner) {
     31      return new LessThan(this, cloner);
    4432    }
     33
     34    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     35      return this.Prefix + " " + this.Suffix;
     36    }
     37  }
    4538}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/Logical Comparators/LessThanOrEqual.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class LessThanOrEqual : CodeNode
    9     {
    10         public override int MinimumArity { get { return 0; } }
    11         public override int MaximumArity { get { return 0; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class LessThanOrEqual : CodeNode {
     8    public override int MinimumArity { get { return 0; } }
     9    public override int MaximumArity { get { return 0; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private LessThanOrEqual(bool deserializing) : base(deserializing) { }
    21         private LessThanOrEqual(LessThanOrEqual original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "<=";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private LessThanOrEqual(bool deserializing) : base(deserializing) { }
     19    private LessThanOrEqual(LessThanOrEqual original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public LessThanOrEqual()
    29             : base("LessThanOrEqual", "LessThanOrEqual comparator.")
    30         {
    31             this.Prefix = "<=";
    32             this.Suffix = "";
    33         }
     23    public LessThanOrEqual()
     24      : base("LessThanOrEqual", "LessThanOrEqual comparator.") {
     25      this.Prefix = "<=";
     26      this.Suffix = "";
     27    }
    3428
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new LessThanOrEqual(this, cloner);
    38         }
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new LessThanOrEqual(this, cloner);
     31    }
    3932
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             return this.Prefix + " " + this.Suffix;
    43         }
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      return this.Prefix + " " + this.Suffix;
    4435    }
     36  }
    4537}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/LogicalComparison.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class LogicalComparison : CodeNode
    9     {
    10         public override int MinimumArity { get { return 3; } }
    11         public override int MaximumArity { get { return 3; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class LogicalComparison : CodeNode {
     8    public override int MinimumArity { get { return 3; } }
     9    public override int MaximumArity { get { return 3; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private LogicalComparison(bool deserializing) : base(deserializing) { }
    21         private LogicalComparison(LogicalComparison original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "(";
    25             this.Suffix = ")";
     17    [StorableConstructor]
     18    private LogicalComparison(bool deserializing) : base(deserializing) { }
     19    private LogicalComparison(LogicalComparison original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
     22
     23    public LogicalComparison()
     24      : base("LogicalComparison", "A LogicalComparison.") {
     25      this.Prefix = "(";
     26      this.Suffix = ")";
     27    }
     28
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new LogicalComparison(this, cloner);
     31    }
     32
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      ISymbolicExpressionTreeNode condition = null, lhs = null, rhs = null;
     35      var enumerator = children.GetEnumerator();
     36      int childCount = 0;
     37      while (enumerator.MoveNext()) {
     38        childCount++;
     39        switch (childCount) {
     40          case 1: condition = enumerator.Current; break;
     41          case 2: lhs = enumerator.Current; break;
     42          case 3: rhs = enumerator.Current; break;
     43          default: throw new System.Exception("Unexpected number of children. Expected 3 children.");
    2644        }
     45      }
     46      if (childCount < 3) throw new System.Exception("Unexpected number of children. Expected 3 children.");
    2747
    28         public LogicalComparison()
    29             : base("LogicalComparison", "A LogicalComparison.")
    30         {
    31             this.Prefix = "(";
    32             this.Suffix = ")";
    33         }
     48      if (!(condition.Symbol is Conjunction || condition.Symbol is Disjunction))
     49        throw new System.Exception("Unexpected first child for LogicalComparison of type: " +
     50            condition.GetType().ToString() + ". Expected " + typeof(Conjunction).ToString() +
     51            " or " + typeof(Disjunction).ToString() + ".");
    3452
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new LogicalComparison(this, cloner);
    38         }
     53      // TODO Check children 2 & 3 for correct types
    3954
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             ISymbolicExpressionTreeNode condition = null, lhs = null, rhs = null;
    43             var enumerator = children.GetEnumerator();
    44             int childCount = 0;
    45             while (enumerator.MoveNext())
    46             {
    47                 childCount++;
    48                 switch (childCount)
    49                 {
    50                     case 1: condition = enumerator.Current; break;
    51                     case 2: lhs = enumerator.Current; break;
    52                     case 3: rhs = enumerator.Current; break;
    53                     default: throw new System.Exception("Unexpected number of children. Expected 3 children.");
    54                 }
    55             }
    56             if (childCount < 3) throw new System.Exception("Unexpected number of children. Expected 3 children.");
    57 
    58             if (!(condition.Symbol is Conjunction || condition.Symbol is Disjunction))
    59                 throw new System.Exception("Unexpected first child for LogicalComparison of type: " +
    60                     condition.GetType().ToString() + ". Expected " + typeof(Conjunction).ToString() +
    61                     " or " + typeof(Disjunction).ToString() + ".");
    62 
    63             // TODO Check children 2 & 3 for correct types
    64 
    65             string[] result = new string[]
     55      string[] result = new string[]
    6656            {
    6757                ((CodeNode)condition.Symbol).Interpret(condition, condition.Subtrees),
     
    7060            };
    7161
    72             return this.Prefix + " " + result[1] + " " + result[0] + " " + result[2] + " " + this.Suffix;
    73         }
     62      return this.Prefix + " " + result[1] + " " + result[0] + " " + result[2] + " " + this.Suffix;
    7463    }
     64  }
    7565}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/LogicalExpression.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class LogicalExpression : CodeNode
    9     {
    10         public override int MinimumArity { get { return 1; } }
    11         public override int MaximumArity { get { return 1; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class LogicalExpression : CodeNode {
     8    public override int MinimumArity { get { return 1; } }
     9    public override int MaximumArity { get { return 1; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private LogicalExpression(bool deserializing) : base(deserializing) { }
    21         private LogicalExpression(LogicalExpression original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private LogicalExpression(bool deserializing) : base(deserializing) { }
     19    private LogicalExpression(LogicalExpression original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public LogicalExpression()
    29             : base("LogicalExpression", "A LogicalExpression.")
    30         {
    31             this.Prefix = "";
    32             this.Suffix = "";
    33         }
     23    public LogicalExpression()
     24      : base("LogicalExpression", "A LogicalExpression.") {
     25      this.Prefix = "";
     26      this.Suffix = "";
     27    }
    3428
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new LogicalExpression(this, cloner);
    38         }
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new LogicalExpression(this, cloner);
     31    }
    3932
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             var enumerator = children.GetEnumerator();
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      var enumerator = children.GetEnumerator();
    4335
    44             if (!enumerator.MoveNext()) throw new System.Exception("LogicalExpression was not given a child.");
    45             var symbol = enumerator.Current.Symbol;
     36      if (!enumerator.MoveNext()) throw new System.Exception("LogicalExpression was not given a child.");
     37      var symbol = enumerator.Current.Symbol;
    4638
    47             if(!(symbol is LogicalValue || symbol is LogicalComparison ||
    48                 symbol is NumericalComparison || symbol is Negation))
    49                 throw new System.Exception("LogicalExpression was given a child of type " + symbol.GetType().ToString() +
    50                     ". The expected child must be of type " + typeof(LogicalValue).ToString() + " or " +
    51                     typeof(LogicalComparison).ToString() + " or " + typeof(NumericalComparison).ToString() + " or " +
    52                     typeof(Negation).ToString() + ".");
     39      if (!(symbol is LogicalValue || symbol is LogicalComparison ||
     40          symbol is NumericalComparison || symbol is Negation))
     41        throw new System.Exception("LogicalExpression was given a child of type " + symbol.GetType().ToString() +
     42            ". The expected child must be of type " + typeof(LogicalValue).ToString() + " or " +
     43            typeof(LogicalComparison).ToString() + " or " + typeof(NumericalComparison).ToString() + " or " +
     44            typeof(Negation).ToString() + ".");
    5345
    54             string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    55             if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child.");
     46      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
     47      if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child.");
    5648
    57             return this.Prefix + result + this.Suffix;
    58         }
     49      return this.Prefix + result + this.Suffix;
    5950    }
     51  }
    6052}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/LogicalValue.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class LogicalValue : CodeNode
    9     {
    10         public override int MinimumArity { get { return 0; } }
    11         public override int MaximumArity { get { return 0; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class LogicalValue : CodeNode {
     8    public override int MinimumArity { get { return 0; } }
     9    public override int MaximumArity { get { return 0; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private LogicalValue(bool deserializing) : base(deserializing) { }
    21         private LogicalValue(LogicalValue original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "";
    25             this.Suffix = "";
    26         }
     17    [StorableConstructor]
     18    private LogicalValue(bool deserializing) : base(deserializing) { }
     19    private LogicalValue(LogicalValue original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public LogicalValue()
    29             : base("LogicalValue", "A LogicalValue.")
    30         {
    31             this.Prefix = "";
    32             this.Suffix = "";
    33         }
     23    public LogicalValue()
     24      : base("LogicalValue", "A LogicalValue.") {
     25      this.Prefix = "";
     26      this.Suffix = "";
     27    }
    3428
    35         public override ISymbolicExpressionTreeNode CreateTreeNode()
    36         {
     29    public override ISymbolicExpressionTreeNode CreateTreeNode() {
    3730
    38             return new BooleanTreeNode();
    39         }
     31      return new BooleanTreeNode();
     32    }
    4033
    41         public override IDeepCloneable Clone(Cloner cloner)
    42         {
    43             return new LogicalValue(this, cloner);
    44         }
     34    public override IDeepCloneable Clone(Cloner cloner) {
     35      return new LogicalValue(this, cloner);
     36    }
    4537
    46         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    47         {
    48             return " " + ((BooleanTreeNode)node).Value.ToString().ToLower() + " ";
    49         }
     38    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     39      return " " + ((BooleanTreeNode)node).Value.ToString().ToLower() + " ";
    5040    }
     41  }
    5142}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/Negation.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class Negation : CodeNode
    9     {
    10         public override int MinimumArity { get { return 1; } }
    11         public override int MaximumArity { get { return 1; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class Negation : CodeNode {
     8    public override int MinimumArity { get { return 1; } }
     9    public override int MaximumArity { get { return 1; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private Negation(bool deserializing) : base(deserializing) { }
    21         private Negation(Negation original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "!(";
    25             this.Suffix = ")";
    26         }
     17    [StorableConstructor]
     18    private Negation(bool deserializing) : base(deserializing) { }
     19    private Negation(Negation original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
    2722
    28         public Negation()
    29             : base("Negation", "A Negation.")
    30         {
    31             this.Prefix = "!(";
    32             this.Suffix = ")";
    33         }
     23    public Negation()
     24      : base("Negation", "A Negation.") {
     25      this.Prefix = "!(";
     26      this.Suffix = ")";
     27    }
    3428
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new Negation(this, cloner);
    38         }
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new Negation(this, cloner);
     31    }
    3932
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             var enumerator = children.GetEnumerator();
    43             if (!enumerator.MoveNext()) throw new System.Exception("Negation was not given a child.");
    44            
    45             var symbol = enumerator.Current.Symbol;
    46             if (!(symbol is LogicalValue || symbol is LogicalComparison ||
    47                 symbol is NumericalComparison || symbol is Negation))
    48                 throw new System.Exception("Negation was given a child of type " + symbol.GetType().ToString() +
    49                     ". The expected child must be of type " + typeof(LogicalValue).ToString() + " or " +
    50                     typeof(LogicalComparison).ToString() + " or " + typeof(NumericalComparison).ToString() + " or " +
    51                     typeof(Negation).ToString() + ".");
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      var enumerator = children.GetEnumerator();
     35      if (!enumerator.MoveNext()) throw new System.Exception("Negation was not given a child.");
    5236
    53             string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
    54             if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child.");
     37      var symbol = enumerator.Current.Symbol;
     38      if (!(symbol is LogicalValue || symbol is LogicalComparison ||
     39          symbol is NumericalComparison || symbol is Negation))
     40        throw new System.Exception("Negation was given a child of type " + symbol.GetType().ToString() +
     41            ". The expected child must be of type " + typeof(LogicalValue).ToString() + " or " +
     42            typeof(LogicalComparison).ToString() + " or " + typeof(NumericalComparison).ToString() + " or " +
     43            typeof(Negation).ToString() + ".");
    5544
    56             return this.Prefix + result + this.Suffix;
    57         }
     45      string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees);
     46      if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child.");
     47
     48      return this.Prefix + result + this.Suffix;
    5849    }
     50  }
    5951}
  • branches/Robocode/HeuristicLab.Problems.Robocode/Symbols/Logical Expressions/NumericalComparison.cs

    r9565 r9630  
    33using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    44
    5 namespace HeuristicLab.Problems.Robocode
    6 {
    7     [StorableClass]
    8     public class NumericalComparison : CodeNode
    9     {
    10         public override int MinimumArity { get { return 3; } }
    11         public override int MaximumArity { get { return 3; } }
     5namespace HeuristicLab.Problems.Robocode {
     6  [StorableClass]
     7  public class NumericalComparison : CodeNode {
     8    public override int MinimumArity { get { return 3; } }
     9    public override int MaximumArity { get { return 3; } }
    1210
    13         [Storable]
    14         public override string Prefix { get; set; }
     11    [Storable]
     12    public override string Prefix { get; set; }
    1513
    16         [Storable]
    17         public override string Suffix { get; set; }
     14    [Storable]
     15    public override string Suffix { get; set; }
    1816
    19         [StorableConstructor]
    20         private NumericalComparison(bool deserializing) : base(deserializing) { }
    21         private NumericalComparison(NumericalComparison original, Cloner cloner)
    22             : base(original, cloner)
    23         {
    24             this.Prefix = "(";
    25             this.Suffix = ")";
     17    [StorableConstructor]
     18    private NumericalComparison(bool deserializing) : base(deserializing) { }
     19    private NumericalComparison(NumericalComparison original, Cloner cloner)
     20      : base(original, cloner) {
     21    }
     22
     23    public NumericalComparison()
     24      : base("NumericalComparison", "A NumericalComparison.") {
     25      this.Prefix = "(";
     26      this.Suffix = ")";
     27    }
     28
     29    public override IDeepCloneable Clone(Cloner cloner) {
     30      return new NumericalComparison(this, cloner);
     31    }
     32
     33    public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) {
     34      ISymbolicExpressionTreeNode condition = null, lhs = null, rhs = null;
     35      var enumerator = children.GetEnumerator();
     36      int childCount = 0;
     37      while (enumerator.MoveNext()) {
     38        childCount++;
     39        switch (childCount) {
     40          case 1: condition = enumerator.Current; break;
     41          case 2: lhs = enumerator.Current; break;
     42          case 3: rhs = enumerator.Current; break;
     43          default: throw new System.Exception("Unexpected number of children. Expected 3 children.");
    2644        }
     45      }
     46      if (childCount < 3) throw new System.Exception("Unexpected number of children. Expected 3 children.");
    2747
    28         public NumericalComparison()
    29             : base("NumericalComparison", "A NumericalComparison.")
    30         {
    31             this.Prefix = "(";
    32             this.Suffix = ")";
    33         }
     48      if (!(condition.Symbol is Equal || condition.Symbol is GreaterThan ||
     49          condition.Symbol is GreaterThanOrEqual || condition.Symbol is LessThan || condition.Symbol is LessThanOrEqual))
     50        throw new System.Exception("Unexpected first child for NumericalComparison of type: " +
     51            condition.GetType().ToString() + ". Expected " + typeof(Equal).ToString() +
     52            " or " + typeof(GreaterThan).ToString() +
     53            " or " + typeof(GreaterThanOrEqual).ToString() +
     54            " or " + typeof(LessThan).ToString() +
     55            " or " + typeof(LessThanOrEqual).ToString() + ".");
    3456
    35         public override IDeepCloneable Clone(Cloner cloner)
    36         {
    37             return new NumericalComparison(this, cloner);
    38         }
     57      // TODO Check children 2 & 3 for correct types
    3958
    40         public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children)
    41         {
    42             ISymbolicExpressionTreeNode condition = null, lhs = null, rhs = null;
    43             var enumerator = children.GetEnumerator();
    44             int childCount = 0;
    45             while (enumerator.MoveNext())
    46             {
    47                 childCount++;
    48                 switch (childCount)
    49                 {
    50                     case 1: condition = enumerator.Current; break;
    51                     case 2: lhs = enumerator.Current; break;
    52                     case 3: rhs = enumerator.Current; break;
    53                     default: throw new System.Exception("Unexpected number of children. Expected 3 children.");
    54                 }
    55             }
    56             if (childCount < 3) throw new System.Exception("Unexpected number of children. Expected 3 children.");
    57 
    58             if (!(condition.Symbol is Equal || condition.Symbol is GreaterThan ||
    59                 condition.Symbol is GreaterThanOrEqual || condition.Symbol is LessThan || condition.Symbol is LessThanOrEqual))
    60                 throw new System.Exception("Unexpected first child for NumericalComparison of type: " +
    61                     condition.GetType().ToString() + ". Expected " + typeof(Equal).ToString() +
    62                     " or " + typeof(GreaterThan).ToString() +
    63                     " or " + typeof(GreaterThanOrEqual).ToString() +
    64                     " or " + typeof(LessThan).ToString() +
    65                     " or " + typeof(LessThanOrEqual).ToString() + ".");
    66 
    67             // TODO Check children 2 & 3 for correct types
    68 
    69             string[] result = new string[]
     59      string[] result = new string[]
    7060            {
    7161                ((CodeNode)condition.Symbol).Interpret(condition, condition.Subtrees),
     
    7464            };
    7565
    76             return this.Prefix + " " + result[1] + " " + result[0] + " " + result[2] + " " + this.Suffix;
    77         }
     66      return this.Prefix + " " + result[1] + " " + result[0] + " " + result[2] + " " + this.Suffix;
    7867    }
     68  }
    7969}
Note: See TracChangeset for help on using the changeset viewer.