Changeset 10011 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators
- Timestamp:
- 10/01/13 12:08:25 (11 years ago)
- Location:
- branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/Equal.cs
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [StorableClass] 28 public class Equal : CodeNode {29 public override int MinimumArity { get { return 0; } }30 public override int MaximumArity { get { return 0; } }29 public class Equal : CodeNode, ILogicalComparator { 30 public override int MinimumArity { get { return 2; } } 31 public override int MaximumArity { get { return 2; } } 31 32 32 33 [Storable] … … 37 38 38 39 [StorableConstructor] 39 private Equal(bool deserializing) : base(deserializing) { } 40 private Equal(Equal original, Cloner cloner) 41 : base(original, cloner) { 42 } 40 protected Equal(bool deserializing) : base(deserializing) { } 41 protected Equal(Equal original, Cloner cloner) : base(original, cloner) { } 43 42 44 public Equal() 45 : base("Equal", "Equal comparator.") { 46 this.Prefix = "=="; 47 this.Suffix = ""; 48 } 43 public Equal() : base("Equal", "Equal comparator.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) { 55 return this.Prefix + " " + this.Suffix; 49 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 ISymbolicExpressionTreeNode lhs = null, rhs = null; 51 var enumerator = children.GetEnumerator(); 52 int childCount = 0; 53 while (enumerator.MoveNext()) { 54 childCount++; 55 switch (childCount) { 56 case 1: lhs = enumerator.Current; break; 57 case 2: rhs = enumerator.Current; break; 58 default: throw new System.Exception("Unexpected number of children. Expected 2 children."); 59 } 60 } 61 if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children."); 62 63 var result = new[] { 64 ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees), 65 ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees) 66 }; 67 68 return result[0] + " == " + result[1]; 56 69 } 57 70 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThan.cs
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [StorableClass] 28 public class GreaterThan : CodeNode {29 public override int MinimumArity { get { return 0; } }30 public override int MaximumArity { get { return 0; } }29 public class GreaterThan : CodeNode, ILogicalComparator { 30 public override int MinimumArity { get { return 2; } } 31 public override int MaximumArity { get { return 2; } } 31 32 32 33 [Storable] … … 37 38 38 39 [StorableConstructor] 39 private GreaterThan(bool deserializing) : base(deserializing) { } 40 private GreaterThan(GreaterThan original, Cloner cloner) 41 : base(original, cloner) { 42 } 40 protected GreaterThan(bool deserializing) : base(deserializing) { } 41 protected GreaterThan(GreaterThan original, Cloner cloner) : base(original, cloner) { } 43 42 44 public GreaterThan() 45 : base("GreaterThan", "GreaterThan comparator.") { 46 this.Prefix = ">"; 47 this.Suffix = ""; 48 } 43 public GreaterThan() : base("GreaterThan", "GreaterThan comparator.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) { 55 return this.Prefix + " " + this.Suffix; 49 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 ISymbolicExpressionTreeNode lhs = null, rhs = null; 51 var enumerator = children.GetEnumerator(); 52 int childCount = 0; 53 while (enumerator.MoveNext()) { 54 childCount++; 55 switch (childCount) { 56 case 1: lhs = enumerator.Current; break; 57 case 2: rhs = enumerator.Current; break; 58 default: throw new System.Exception("Unexpected number of children. Expected 2 children."); 59 } 60 } 61 if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children."); 62 63 var result = new[] { 64 ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees), 65 ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees) 66 }; 67 68 return result[0] + " > " + result[1]; 56 69 } 57 70 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThanOrEqual.cs
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [StorableClass] 28 public class GreaterThanOrEqual : CodeNode {29 public override int MinimumArity { get { return 0; } }30 public override int MaximumArity { get { return 0; } }29 public class GreaterThanOrEqual : CodeNode, ILogicalComparator { 30 public override int MinimumArity { get { return 2; } } 31 public override int MaximumArity { get { return 2; } } 31 32 32 33 [Storable] … … 37 38 38 39 [StorableConstructor] 39 private GreaterThanOrEqual(bool deserializing) : base(deserializing) { } 40 private GreaterThanOrEqual(GreaterThanOrEqual original, Cloner cloner) 41 : base(original, cloner) { 42 } 40 protected GreaterThanOrEqual(bool deserializing) : base(deserializing) { } 41 protected GreaterThanOrEqual(GreaterThanOrEqual original, Cloner cloner) : base(original, cloner) { } 43 42 44 public GreaterThanOrEqual() 45 : base("GreaterThanOrEqual", "GreaterThanOrEqual comparator.") { 46 this.Prefix = ">="; 47 this.Suffix = ""; 48 } 43 public GreaterThanOrEqual() : base("GreaterThanOrEqual", "GreaterThanOrEqual comparator.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) { 55 return this.Prefix + " " + this.Suffix; 49 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 ISymbolicExpressionTreeNode lhs = null, rhs = null; 51 var enumerator = children.GetEnumerator(); 52 int childCount = 0; 53 while (enumerator.MoveNext()) { 54 childCount++; 55 switch (childCount) { 56 case 1: lhs = enumerator.Current; break; 57 case 2: rhs = enumerator.Current; break; 58 default: throw new System.Exception("Unexpected number of children. Expected 2 children."); 59 } 60 } 61 if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children."); 62 63 var result = new[] { 64 ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees), 65 ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees) 66 }; 67 68 return result[0] + " >= " + result[1]; 56 69 } 57 70 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThan.cs
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [StorableClass] 28 public class LessThan : CodeNode {29 public override int MinimumArity { get { return 0; } }30 public override int MaximumArity { get { return 0; } }29 public class LessThan : CodeNode, ILogicalComparator { 30 public override int MinimumArity { get { return 2; } } 31 public override int MaximumArity { get { return 2; } } 31 32 32 33 [Storable] … … 37 38 38 39 [StorableConstructor] 39 private LessThan(bool deserializing) : base(deserializing) { } 40 private LessThan(LessThan original, Cloner cloner) 41 : base(original, cloner) { 40 protected LessThan(bool deserializing) : base(deserializing) { } 41 protected LessThan(LessThan original, Cloner cloner) : base(original, cloner) { } 42 42 43 } 44 45 public LessThan() 46 : base("LessThan", "LessThan comparator.") { 47 this.Prefix = "<"; 48 this.Suffix = ""; 49 } 43 public LessThan() : base("LessThan", "LessThan comparator.") { } 50 44 51 45 public override IDeepCloneable Clone(Cloner cloner) { … … 53 47 } 54 48 55 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) { 56 return this.Prefix + " " + this.Suffix; 49 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 ISymbolicExpressionTreeNode lhs = null, rhs = null; 51 var enumerator = children.GetEnumerator(); 52 int childCount = 0; 53 while (enumerator.MoveNext()) { 54 childCount++; 55 switch (childCount) { 56 case 1: lhs = enumerator.Current; break; 57 case 2: rhs = enumerator.Current; break; 58 default: throw new System.Exception("Unexpected number of children. Expected 2 children."); 59 } 60 } 61 if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children."); 62 63 var result = new[] { 64 ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees), 65 ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees) 66 }; 67 68 return result[0] + " < " + result[1]; 57 69 } 58 70 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThanOrEqual.cs
r9790 r10011 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 26 27 namespace HeuristicLab.Problems.Robocode { 27 28 [StorableClass] 28 public class LessThanOrEqual : CodeNode {29 public override int MinimumArity { get { return 0; } }30 public override int MaximumArity { get { return 0; } }29 public class LessThanOrEqual : CodeNode, ILogicalComparator { 30 public override int MinimumArity { get { return 2; } } 31 public override int MaximumArity { get { return 2; } } 31 32 32 33 [Storable] … … 37 38 38 39 [StorableConstructor] 39 private LessThanOrEqual(bool deserializing) : base(deserializing) { } 40 private LessThanOrEqual(LessThanOrEqual original, Cloner cloner) 41 : base(original, cloner) { 42 } 40 protected LessThanOrEqual(bool deserializing) : base(deserializing) { } 41 protected LessThanOrEqual(LessThanOrEqual original, Cloner cloner) : base(original, cloner) { } 43 42 44 public LessThanOrEqual() 45 : base("LessThanOrEqual", "LessThanOrEqual comparator.") { 46 this.Prefix = "<="; 47 this.Suffix = ""; 48 } 43 public LessThanOrEqual() : base("LessThanOrEqual", "LessThanOrEqual comparator.") { } 49 44 50 45 public override IDeepCloneable Clone(Cloner cloner) { … … 52 47 } 53 48 54 public override string Interpret(ISymbolicExpressionTreeNode node, System.Collections.Generic.IEnumerable<ISymbolicExpressionTreeNode> children) { 55 return this.Prefix + " " + this.Suffix; 49 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 ISymbolicExpressionTreeNode lhs = null, rhs = null; 51 var enumerator = children.GetEnumerator(); 52 int childCount = 0; 53 while (enumerator.MoveNext()) { 54 childCount++; 55 switch (childCount) { 56 case 1: lhs = enumerator.Current; break; 57 case 2: rhs = enumerator.Current; break; 58 default: throw new System.Exception("Unexpected number of children. Expected 2 children."); 59 } 60 } 61 if (childCount < 2) throw new System.Exception("Unexpected number of children. Expected 2 children."); 62 63 var result = new[] { 64 ((CodeNode)lhs.Symbol).Interpret(lhs, lhs.Subtrees), 65 ((CodeNode)rhs.Symbol).Interpret(rhs, rhs.Subtrees) 66 }; 67 68 return result[0] + " <= " + result[1]; 56 69 } 57 70 }
Note: See TracChangeset
for help on using the changeset viewer.