Changeset 10011 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThanOrEqual.cs
- Timestamp:
- 10/01/13 12:08:25 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.