Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8148


Ignore:
Timestamp:
06/28/12 13:10:39 (12 years ago)
Author:
mkommend
Message:

#1885: Corrected SubroutineCreator to adapt the grammar according to the new ADF.

Location:
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineCreater.cs

    r7259 r8148  
    139139      // the grammar in the newly defined function is a clone of the grammar of the originating branch
    140140      defunNode.SetGrammar((ISymbolicExpressionTreeGrammar)selectedBody.Grammar.Clone());
     141
     142      var allowedChildSymbols = selectedBody.Grammar.GetAllowedChildSymbols(selectedBody.Symbol);
     143      foreach (var allowedChildSymbol in allowedChildSymbols)
     144        defunNode.Grammar.AddAllowedChildSymbol(defunNode.Symbol, allowedChildSymbol);
     145      var maxSubtrees = selectedBody.Grammar.GetMaximumSubtreeCount(selectedBody.Symbol);
     146      for (int i = 0; i < maxSubtrees; i++) {
     147        foreach (var allowedChildSymbol in selectedBody.Grammar.GetAllowedChildSymbols(selectedBody.Symbol, i))
     148          defunNode.Grammar.AddAllowedChildSymbol(defunNode.Symbol, allowedChildSymbol);
     149      }
     150
    141151      // remove all argument symbols from grammar except that one contained in cutpoints
    142152      var oldArgumentSymbols = selectedBody.Grammar.Symbols.OfType<Argument>().ToList();
  • trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs

    r7259 r8148  
    7373      symbolicExpressionTree.Root.AddSubtree(duplicatedDefunBranch);
    7474      duplicatedDefunBranch.SetGrammar((ISymbolicExpressionTreeGrammar)selectedBranch.Grammar.Clone());
     75
     76      var allowedChildSymbols = selectedBranch.Grammar.GetAllowedChildSymbols(selectedBranch.Symbol);
     77      foreach (var allowedChildSymbol in allowedChildSymbols)
     78        duplicatedDefunBranch.Grammar.AddAllowedChildSymbol(duplicatedDefunBranch.Symbol, allowedChildSymbol);
     79      var maxSubtrees = selectedBranch.Grammar.GetMaximumSubtreeCount(selectedBranch.Symbol);
     80      for (int i = 0; i < maxSubtrees; i++) {
     81        foreach (var allowedChildSymbol in selectedBranch.Grammar.GetAllowedChildSymbols(selectedBranch.Symbol, i))
     82          duplicatedDefunBranch.Grammar.AddAllowedChildSymbol(duplicatedDefunBranch.Symbol, allowedChildSymbol);
     83      }
     84
    7585      // add an invoke symbol for each branch that is allowed to invoke the original function
    7686      foreach (var subtree in symbolicExpressionTree.Root.Subtrees.OfType<SymbolicExpressionTreeTopLevelNode>()) {
Note: See TracChangeset for help on using the changeset viewer.