Changeset 6944 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs
- Timestamp:
- 11/02/11 16:37:07 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs
r6888 r6944 21 21 22 22 using System; 23 using System.Collections.Generic;24 using System.ComponentModel;25 23 using System.Linq; 26 24 using HeuristicLab.Common; … … 133 131 throw new ArgumentException("Cannot create trees of depth " + maxDepth + " or smaller because of grammar constraints.", "maxDepth"); 134 132 135 var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0).ToList();136 133 137 134 int arity = seedNode.Grammar.GetMaximumSubtreeCount(seedNode.Symbol); 138 135 // Throw an exception if the seedNode happens to be a terminal, since in this case we cannot grow a tree. 139 136 if (arity <= 0) 140 throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 137 throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero."); 141 138 142 139 for (var i = 0; i != arity; ++i) { 140 var possibleSymbols = seedNode.Grammar.GetAllowedChildSymbols(seedNode.Symbol,i).Where(s => s.InitialFrequency > 0.0 && seedNode.Grammar.GetMaximumSubtreeCount(s) > 0); 143 141 var selectedSymbol = possibleSymbols.SelectRandom(random); 144 142 var tree = selectedSymbol.CreateTreeNode(); … … 149 147 // Only iterate over the non-terminal nodes (those which have arity > 0) 150 148 // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode 151 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)) 149 foreach (var subTree in seedNode.Subtrees.Where(subTree => subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) != 0)) 152 150 RecursiveGrowFull(random, subTree, 2, maxDepth); 153 151 } … … 159 157 throw new ArgumentException("Cannot grow node of arity zero. Expected a function node."); 160 158 161 var possibleSymbols = currentDepth < maxDepth ?162 root.Grammar.GetAllowedChildSymbols(root.Symbol).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) > 0).ToList() :163 root.Grammar.GetAllowedChildSymbols(root.Symbol).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) == 0).ToList();164 159 165 160 for (var i = 0; i != arity; ++i) { 161 var possibleSymbols = currentDepth < maxDepth ? 162 root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) > 0) : 163 root.Grammar.GetAllowedChildSymbols(root.Symbol,i).Where(s => s.InitialFrequency > 0.0 && root.Grammar.GetMaximumSubtreeCount(s) == 0); 166 164 var selectedSymbol = possibleSymbols.SelectRandom(random); 167 165 var tree = selectedSymbol.CreateTreeNode();
Note: See TracChangeset
for help on using the changeset viewer.