Changeset 10075 for branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers
- Timestamp:
- 10/21/13 11:29:55 (11 years ago)
- Location:
- branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/DepthFirstMapper.cs
r10068 r10075 25 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Random; 27 28 28 29 namespace HeuristicLab.Problems.GrammaticalEvolution { … … 56 57 SymbolicExpressionTree tree = new SymbolicExpressionTree(); 57 58 var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode(); 59 if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(new MersenneTwister()); 58 60 var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode(); 61 if (startNode.HasLocalParameters) startNode.ResetLocalParameters(new MersenneTwister()); 59 62 rootNode.AddSubtree(startNode); 60 63 tree.Root = rootNode; … … 96 99 var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex); 97 100 98 if ((currSubtreeCount + newNode.Symbol.M aximumArity) > maxSubtreeCount) {101 if ((currSubtreeCount + newNode.Symbol.MinimumArity) > maxSubtreeCount) { 99 102 // TODO: maybe check, if there is any node, which fits in the tree yet 100 103 currentNode.AddSubtree(GetRandomTerminalNode(currentNode, grammar)); … … 102 105 currentNode.AddSubtree(newNode); 103 106 genotypeIndex++; 104 currSubtreeCount += newNode.Symbol.M aximumArity;107 currSubtreeCount += newNode.Symbol.MinimumArity; 105 108 106 while (newNode.Symbol.M aximumArity > newNode.SubtreeCount) {109 while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) { 107 110 MapDepthFirstRecursively(newNode, genotype, 108 111 grammar, maxSubtreeCount, … … 112 115 113 116 } else { 114 while (currentNode.Symbol.M aximumArity > currentNode.SubtreeCount) {117 while (currentNode.Symbol.MinimumArity > currentNode.SubtreeCount) { 115 118 var newNode = GetNewChildNode(currentNode, genotype, grammar, genotypeIndex); 116 119 currentNode.AddSubtree(newNode); 117 120 genotypeIndex++; 118 while (newNode.Symbol.M aximumArity > newNode.SubtreeCount) {121 while (newNode.Symbol.MinimumArity > newNode.SubtreeCount) { 119 122 newNode.AddSubtree(GetRandomTerminalNode(newNode, grammar)); 120 123 } -
branches/GrammaticalEvolution/HeuristicLab.Problems.GrammaticalEvolution/Mappers/GenotypeToPhenotypeMapper.cs
r10068 r10075 52 52 protected ISymbolicExpressionTreeNode GetRandomTerminalNode(ISymbolicExpressionTreeNode parentNode, 53 53 ISymbolicExpressionGrammar grammar) { 54 var possibleSymbolsList = from s in grammar.GetAllowedChildSymbols(parentNode.Symbol) 55 where s.MaximumArity == 0 56 where s.MinimumArity == 0 57 select s; 58 // TODO: Check, if symbol list is empty (no terminal nodes found) - what should happen? 59 return possibleSymbolsList.SelectRandom(new MersenneTwister()).CreateTreeNode(); 54 // only select specific symbols, which can be interpreted ... 55 var possibleSymbolsList = (from s in grammar.GetAllowedChildSymbols(parentNode.Symbol) 56 where s.InitialFrequency > 0.0 57 where s.MaximumArity == 0 58 where s.MinimumArity == 0 59 select s).ToList(); 60 // TODO: Check, if symbol list is empty (no terminal nodes found) - what should happen? 61 var newNode = possibleSymbolsList.SelectRandom(new MersenneTwister()).CreateTreeNode(); 62 if (newNode.HasLocalParameters) newNode.ResetLocalParameters(new MersenneTwister()); 63 return newNode; 60 64 } 61 65 … … 74 78 int genotypeIndex) { 75 79 76 IEnumerable<ISymbol> symbolList = grammar.GetAllowedChildSymbols(parentNode.Symbol); 80 // only select specific symbols, which can be interpreted ... 81 IEnumerable<ISymbol> symbolList = (from s in grammar.GetAllowedChildSymbols(parentNode.Symbol) 82 where s.InitialFrequency > 0.0 83 select s).ToList(); 77 84 int prodRuleCount = symbolList.Count(); 78 85 int prodRuleIndex = genotype[genotypeIndex % genotype.Length] % prodRuleCount; 79 86 80 return symbolList.ElementAt(prodRuleIndex).CreateTreeNode(); 87 var newNode = symbolList.ElementAt(prodRuleIndex).CreateTreeNode(); 88 if (newNode.HasLocalParameters) newNode.ResetLocalParameters(new MersenneTwister()); 89 return newNode; 81 90 } 82 91 }
Note: See TracChangeset
for help on using the changeset viewer.