Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/15/11 13:34:38 (13 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/SubroutineDeleter.cs

    r5549 r5686  
    2626using HeuristicLab.Data;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using System.Collections.Generic;
    2928
    3029namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
     
    8786                                from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>()
    8887                                where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName
    89                                 select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).FirstOrDefault();
     88                                select new CutPoint(node, subtree)).FirstOrDefault();
    9089      while (invocationCutPoint != null) {
    9190        // deletion by random regeneration
    9291        ISymbolicExpressionTreeNode replacementTree = null;
    93         var allowedSymbolsList = invocationCutPoint.Parent.Grammar.GetAllowedSymbols(invocationCutPoint.Parent.Symbol, invocationCutPoint.ReplacedChildIndex).ToList();
     92        var allowedSymbolsList = invocationCutPoint.Parent.Grammar.GetAllowedChildSymbols(invocationCutPoint.Parent.Symbol, invocationCutPoint.ChildIndex).ToList();
    9493        var weights = allowedSymbolsList.Select(s => s.InitialFrequency);
    9594        var selectedSymbol = allowedSymbolsList.SelectRandom(weights, random);
    9695
    97         int minPossibleLength = invocationCutPoint.Parent.Grammar.GetMinExpressionLength(selectedSymbol);
    98         int maxLength = Math.Max(minPossibleLength, invocationCutPoint.ReplacedChild.GetLength());
    99         int minPossibleDepth = invocationCutPoint.Parent.Grammar.GetMinExpressionDepth(selectedSymbol);
    100         int maxDepth = Math.Max(minPossibleDepth, invocationCutPoint.ReplacedChild.GetDepth());
     96        int minPossibleLength = invocationCutPoint.Parent.Grammar.GetMinimumExpressionLength(selectedSymbol);
     97        int maxLength = Math.Max(minPossibleLength, invocationCutPoint.Child.GetLength());
     98        int minPossibleDepth = invocationCutPoint.Parent.Grammar.GetMinimumExpressionDepth(selectedSymbol);
     99        int maxDepth = Math.Max(minPossibleDepth, invocationCutPoint.Child.GetDepth());
    101100        replacementTree = selectedSymbol.CreateTreeNode();
    102101        if (replacementTree.HasLocalParameters)
    103102          replacementTree.ResetLocalParameters(random);
    104         invocationCutPoint.Parent.RemoveSubTree(invocationCutPoint.ReplacedChildIndex);
    105         invocationCutPoint.Parent.InsertSubTree(invocationCutPoint.ReplacedChildIndex, replacementTree);
     103        invocationCutPoint.Parent.RemoveSubTree(invocationCutPoint.ChildIndex);
     104        invocationCutPoint.Parent.InsertSubTree(invocationCutPoint.ChildIndex, replacementTree);
    106105
    107         ProbabilisticTreeCreator.PTC2(random, replacementTree, maxLength, maxDepth, 0, 0);
     106        ProbabilisticTreeCreator.PTC2(random, replacementTree, maxLength, maxDepth);
    108107
    109108        invocationCutPoint = (from node in symbolicExpressionTree.IterateNodesPrefix()
    110109                              from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>()
    111110                              where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName
    112                               select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).FirstOrDefault();
     111                              select new CutPoint(node, subtree)).FirstOrDefault();
    113112      }
    114113    }
Note: See TracChangeset for help on using the changeset viewer.