Changeset 3338 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTree.cs
- Timestamp:
- 04/13/10 20:44:31 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTree.cs
r3317 r3338 50 50 } 51 51 52 [Storable]53 private Dictionary<int, IEnumerable<string>> allowedFunctionsInBranch;54 55 52 public int Size { 56 53 get { … … 67 64 public SymbolicExpressionTree() 68 65 : base() { 69 allowedFunctionsInBranch = new Dictionary<int, IEnumerable<string>>();70 66 } 71 67 72 68 public SymbolicExpressionTree(SymbolicExpressionTreeNode root) 73 69 : base() { 74 allowedFunctionsInBranch = new Dictionary<int, IEnumerable<string>>();75 70 } 76 71 77 72 public IEnumerable<SymbolicExpressionTreeNode> IterateNodesPrefix() { 78 return IterateNodesPrefix(root); 79 } 80 private IEnumerable<SymbolicExpressionTreeNode> IterateNodesPrefix(SymbolicExpressionTreeNode node) { 81 yield return node; 82 foreach (var subtree in node.SubTrees) { 83 foreach (var n in IterateNodesPrefix(subtree)) 84 yield return n; 85 } 73 return root.IterateNodesPrefix(); 86 74 } 87 75 public IEnumerable<SymbolicExpressionTreeNode> IterateNodesPostfix() { 88 return IterateNodesPostfix(root);76 return root.IterateNodesPostfix(); 89 77 } 90 private IEnumerable<SymbolicExpressionTreeNode> IterateNodesPostfix(SymbolicExpressionTreeNode node) { 91 foreach (var subtree in node.SubTrees) {92 foreach (var n in IterateNodesPrefix(subtree))93 yield return n;78 79 public SymbolicExpressionTreeNode GetTopLevelBranchOf(SymbolicExpressionTreeNode node) { 80 foreach (var branch in root.SubTrees) { 81 if (branch.IterateNodesPrefix().Contains(node)) return branch; 94 82 } 95 yield return node;83 throw new ArgumentException("Node was not found in tree."); 96 84 } 97 85 … … 101 89 clone.ReadOnlyView = ReadOnlyView; 102 90 clone.root = (SymbolicExpressionTreeNode)this.root.Clone(); 103 clone.allowedFunctionsInBranch = new Dictionary<int, IEnumerable<string>>(allowedFunctionsInBranch);104 91 return clone; 92 } 93 94 public bool IsValidExpression() { 95 if (root.Symbol != root.Grammar.StartSymbol) return false; 96 foreach (var subtree in root.SubTrees) 97 if (subtree.Grammar == root.Grammar) return false; 98 return root.IsValidTree(); 105 99 } 106 100 }
Note: See TracChangeset
for help on using the changeset viewer.