Changeset 10046 for branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions
- Timestamp:
- 10/17/13 12:07:20 (11 years ago)
- Location:
- branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Disjunction.cs
r10011 r10046 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 53 54 54 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 55 59 string result = string.Join(" || ", children.Select(c => ((CodeNode)c.Symbol).Interpret(c, c.Subtrees))); 56 60 return Prefix + result + Suffix; -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/Equal.cs
r10011 r10046 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 49 51 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 52 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."); 53 if (children.Count() != 2) 54 throw new Exception("Unexpected number of children. Expected 2 children."); 55 56 lhs = children.First(); 57 rhs = children.Last(); 62 58 63 59 var result = new[] { -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThan.cs
r10011 r10046 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 49 51 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 52 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."); 53 if (children.Count() != 2) 54 throw new Exception("Unexpected number of children. Expected 2 children."); 55 56 lhs = children.First(); 57 rhs = children.Last(); 62 58 63 59 var result = new[] { -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/GreaterThanOrEqual.cs
r10011 r10046 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 49 51 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 52 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."); 53 if (children.Count() != 2) 54 throw new Exception("Unexpected number of children. Expected 2 children."); 55 56 lhs = children.First(); 57 rhs = children.Last(); 62 58 63 59 var result = new[] { -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThan.cs
r10011 r10046 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 49 51 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 52 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."); 53 if (children.Count() != 2) 54 throw new Exception("Unexpected number of children. Expected 2 children."); 55 56 lhs = children.First(); 57 rhs = children.Last(); 62 58 63 59 var result = new[] { -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Logical Comparators/LessThanOrEqual.cs
r10011 r10046 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 49 51 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 52 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."); 53 if (children.Count() != 2) 54 throw new Exception("Unexpected number of children. Expected 2 children."); 55 56 lhs = children.First(); 57 rhs = children.Last(); 62 58 63 59 var result = new[] { -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/LogicalExpression.cs
r10011 r10046 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 48 50 49 51 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 50 var enumerator = children.GetEnumerator();51 if (!enumerator.MoveNext()) throw new System.Exception("LogicalExpression was not given a child.");52 if (children.Count() != 1) 53 throw new ArgumentException("Expected 1 child in LogicalExpression.", "children"); 52 54 53 var symbol = enumerator.Current.Symbol; 55 var exprTree = children.Single(); 56 var symbol = exprTree.Symbol; 54 57 if (!(symbol is LogicalValue || symbol is Conjunction || symbol is Disjunction || symbol is Negation)) 55 58 throw new System.Exception("LogicalExpression was given a child of type " + symbol.GetType() + … … 59 62 + " or " + typeof(Negation) + "."); 60 63 61 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 62 if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child."); 63 64 return result; 64 return Prefix + ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees) + Suffix; 65 65 } 66 66 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/LogicalValue.cs
r10011 r10046 52 52 53 53 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 54 return ((BooleanTreeNode)node).Value.ToString().ToLower();54 return Prefix + ((BooleanTreeNode)node).Value.ToString().ToLower() + Suffix; 55 55 } 56 56 } -
branches/Robocode.TrunkInt/HeuristicLab.Problems.Robocode/3.3/Symbols/Logical Expressions/Negation.cs
r10011 r10046 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; … … 52 54 53 55 public override string Interpret(ISymbolicExpressionTreeNode node, IEnumerable<ISymbolicExpressionTreeNode> children) { 54 var enumerator = children.GetEnumerator();55 if (!enumerator.MoveNext()) throw new System.Exception("Negation was not given a child.");56 if (children.Count() != 1) 57 throw new ArgumentException("Expected 1 child in Negation.", "children"); 56 58 57 var symbol = enumerator.Current.Symbol; 59 var exprTree = children.Single(); 60 var symbol = exprTree.Symbol; 58 61 if (!(symbol is LogicalValue || symbol is Conjunction || symbol is Disjunction || symbol is Negation || symbol is ILogicalComparator)) 59 62 throw new System.Exception("Negation was given a child of type " + symbol.GetType() + … … 64 67 + " or " + typeof(ILogicalComparator) + "."); 65 68 66 string result = ((CodeNode)symbol).Interpret(enumerator.Current, enumerator.Current.Subtrees); 67 if (enumerator.MoveNext()) throw new System.Exception("LogicalExpression was given more than one child."); 68 69 return Prefix + result + Suffix; 69 return Prefix + ((CodeNode)symbol).Interpret(exprTree, exprTree.Subtrees) + Suffix; 70 70 } 71 71 }
Note: See TracChangeset
for help on using the changeset viewer.