Changeset 13227 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
- Timestamp:
- 11/17/15 17:22:58 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r12422 r13227 74 74 } 75 75 76 public static ISymbolicExpressionTree CreateExpressionTree(IRandom random, ISymbolicExpressionGrammar grammar, int targetLength, 77 int maxTreeDepth) { 78 SymbolicExpressionTree tree = new SymbolicExpressionTree(); 79 var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode(); 80 if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(random); 81 rootNode.SetGrammar(grammar.CreateExpressionTreeGrammar()); 82 83 var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode(); 84 if (startNode.HasLocalParameters) startNode.ResetLocalParameters(random); 85 startNode.SetGrammar(grammar.CreateExpressionTreeGrammar()); 86 87 rootNode.AddSubtree(startNode); 88 bool success = TryCreateFullTreeFromSeed(random, startNode, targetLength - 2, maxTreeDepth - 1); 89 if (!success) throw new InvalidOperationException(string.Format("Could not create a tree with target length {0} and max depth {1}", targetLength, maxTreeDepth)); 90 91 tree.Root = rootNode; 92 return tree; 93 94 } 95 76 96 private class TreeExtensionPoint { 77 97 public ISymbolicExpressionTreeNode Parent { get; set; } … … 107 127 } else { 108 128 // clean seedNode 109 while (seedNode.Subtrees. Count() > 0) seedNode.RemoveSubtree(0);129 while (seedNode.Subtrees.Any()) seedNode.RemoveSubtree(0); 110 130 } 111 131 // try a different length MAX_TRIES times
Note: See TracChangeset
for help on using the changeset viewer.