Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/15/11 13:34:38 (14 years ago)
Author:
mkommend
Message:

#1418: Finally added results from the grammar refactoring.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentCreater.cs

    r5549 r5686  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Parameters;
    2829using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    29 using HeuristicLab.Parameters;
    3030
    3131namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    126126                       where node.SubTrees.Count() > 0
    127127                       from subtree in node.SubTrees
    128                        select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).ToList();
     128                       select new CutPoint(node, subtree)).ToList();
    129129
    130130      if (cutPoints.Count() == 0)
     
    133133      var selectedCutPoint = cutPoints[random.Next(cutPoints.Count)];
    134134      // replace the branch at the cut point with an argument node
    135       var replacedBranch = selectedCutPoint.ReplacedChild;
    136       selectedCutPoint.Parent.RemoveSubTree(selectedCutPoint.ReplacedChildIndex);
    137       selectedCutPoint.Parent.InsertSubTree(selectedCutPoint.ReplacedChildIndex, newArgumentNode);
     135      var replacedBranch = selectedCutPoint.Child;
     136      selectedCutPoint.Parent.RemoveSubTree(selectedCutPoint.ChildIndex);
     137      selectedCutPoint.Parent.InsertSubTree(selectedCutPoint.ChildIndex, newArgumentNode);
    138138
    139139      // find all old invocations of the selected ADF and attach a cloned version of the replaced branch (with all argument-nodes expanded)
     
    167167      defunBranch.NumberOfArguments++;
    168168      defunBranch.Grammar.AddSymbol(newArgumentNode.Symbol);
    169       defunBranch.Grammar.SetMinSubtreeCount(newArgumentNode.Symbol, 0);
    170       defunBranch.Grammar.SetMaxSubtreeCount(newArgumentNode.Symbol, 0);
     169      defunBranch.Grammar.SetSubtreeCount(newArgumentNode.Symbol, 0, 0);
    171170      // allow the argument as child of any other symbol
    172171      foreach (var symb in defunBranch.Grammar.Symbols)
    173         for (int i = 0; i < defunBranch.Grammar.GetMaxSubtreeCount(symb); i++) {
    174           defunBranch.Grammar.SetAllowedChild(symb, newArgumentNode.Symbol, i);
     172        for (int i = 0; i < defunBranch.Grammar.GetMaximumSubtreeCount(symb); i++) {
     173          defunBranch.Grammar.AddAllowedChildSymbol(symb, newArgumentNode.Symbol, i);
    175174        }
    176175      foreach (var subtree in tree.Root.SubTrees) {
     
    178177        var matchingSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().Where(s => s.FunctionName == defunBranch.FunctionName).SingleOrDefault();
    179178        if (matchingSymbol != null) {
    180           subtree.Grammar.SetMinSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments);
    181           subtree.Grammar.SetMaxSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments);
    182           foreach (var child in subtree.Grammar.GetAllowedSymbols(subtree.Symbol, 0)) {
    183             for (int i = 0; i < subtree.Grammar.GetMaxSubtreeCount(matchingSymbol); i++) {
    184               subtree.Grammar.SetAllowedChild(matchingSymbol, child, i);
     179          subtree.Grammar.SetSubtreeCount(matchingSymbol, defunBranch.NumberOfArguments, defunBranch.NumberOfArguments);
     180          foreach (var child in subtree.Grammar.GetAllowedChildSymbols(subtree.Symbol, 0)) {
     181            for (int i = 0; i < subtree.Grammar.GetMaximumSubtreeCount(matchingSymbol); i++) {
     182              subtree.Grammar.AddAllowedChildSymbol(matchingSymbol, child, i);
    185183            }
    186184          }
Note: See TracChangeset for help on using the changeset viewer.