- Timestamp:
- 03/31/10 14:26:45 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
r3237 r3239 32 32 [Item("ProbabilisticTreeCreator", "An operator that creates new symbolic expression trees with uniformly distributed size")] 33 33 public class ProbabilisticTreeCreator : SymbolicExpressionTreeCreator { 34 private const int MAX_TRIES = 100;35 34 public ProbabilisticTreeCreator() 36 35 : base() { … … 48 47 int treeSize = random.Next(allowedMinSize, allowedMaxSize); 49 48 SymbolicExpressionTree tree = new SymbolicExpressionTree(); 50 int tries = 0;51 49 do { 52 50 try { 53 tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize+1, maxTreeHeight+1); 54 //// determine possible root symbols to create a tree of the target size 55 //var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0) 56 // where treeSize <= grammar.MaximalExpressionLength(symbol) 57 // where treeSize >= grammar.MinimalExpressionLength(symbol) 58 // select symbol; 59 //Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols); 60 //tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight); 51 tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize + 1, maxTreeHeight + 1); 61 52 } 62 53 catch (ArgumentException) { 63 54 // try a different size 64 55 treeSize = random.Next(allowedMinSize, allowedMaxSize); 65 tries = 0;66 }67 if (tries++ >= MAX_TRIES) {68 // try a different size69 treeSize = random.Next(allowedMinSize, allowedMaxSize);70 tries = 0;71 56 } 72 57 } while (tree.Root == null || tree.Size > maxTreeSize || tree.Height > maxTreeHeight); … … 191 176 return tree; 192 177 } 193 194 //private bool IsRecursiveExpansionPossible(Symbol symbol) {195 // return FindCycle(function, new Stack<IFunction>());196 //}197 198 //private Dictionary<IFunction, bool> inCycle = new Dictionary<IFunction, bool>();199 //private bool FindCycle(IFunction function, Stack<IFunction> functionChain) {200 // if (inCycle.ContainsKey(function)) {201 // return inCycle[function];202 // } else if (IsTerminal(function)) {203 // inCycle[function] = false;204 // return false;205 // } else if (functionChain.Contains(function)) {206 // inCycle[function] = true;207 // return true;208 // } else {209 // functionChain.Push(function);210 // bool result = false;211 // // all slot indexes212 // for (int i = 0; i < function.MaxSubTrees; i++) {213 // foreach (IFunction subFunction in GetAllowedSubFunctions(function, i)) {214 // result |= FindCycle(subFunction, functionChain);215 // }216 // }217 218 // functionChain.Pop();219 // inCycle[function] = result;220 // return result;221 // }222 //}223 224 178 } 225 179 }
Note: See TracChangeset
for help on using the changeset viewer.