Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/17/11 13:51:04 (13 years ago)
Author:
gkronber
Message:

#1418 Fixed compiler errors in symbolic expression tree encoding

File:
1 edited

Legend:

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

    r5499 r5510  
    3333  /// As described in Koza, Bennett, Andre, Keane, Genetic Programming III - Darwinian Invention and Problem Solving, 1999, pp. 108
    3434  /// </summary>
    35   [Item("SubroutineDeleter", "Manipulates a symbolic expression by deleting a preexisting function-defining branch.")]
     35  [Item("SubroutineDeleter", "Manipulates a symbolic expression by deleting a preexisting function-defining branch. As described in Koza, Bennett, Andre, Keane, Genetic Programming III - Darwinian Invention and Problem Solving, 1999, pp. 108")]
    3636  [StorableClass]
    3737  public sealed class SubroutineDeleter : SymbolicExpressionTreeArchitectureManipulator {
     
    4747    public override sealed void ModifyArchitecture(
    4848      IRandom random,
    49       SymbolicExpressionTree symbolicExpressionTree,
    50       ISymbolicExpressionGrammar grammar,
    51       IntValue maxTreeSize, IntValue maxTreeHeight,
    52       IntValue maxFunctionDefiningBranches, IntValue maxFunctionArguments,
    53       out bool success) {
    54       success = DeleteSubroutine(random, symbolicExpressionTree, grammar, maxTreeSize.Value, maxTreeHeight.Value, maxFunctionDefiningBranches.Value, maxFunctionArguments.Value);
     49      ISymbolicExpressionTree symbolicExpressionTree,
     50      IntValue maxFunctionDefinitions, IntValue maxFunctionArguments) {
     51      DeleteSubroutine(random, symbolicExpressionTree, maxFunctionDefinitions.Value, maxFunctionArguments.Value);
    5552    }
    5653
    5754    public static bool DeleteSubroutine(
    5855      IRandom random,
    59       SymbolicExpressionTree symbolicExpressionTree,
    60       ISymbolicExpressionGrammar grammar,
    61       int maxTreeSize, int maxTreeHeight,
    62       int maxFunctionDefiningBranches, int maxFunctionArguments) {
     56      ISymbolicExpressionTree symbolicExpressionTree,
     57      int maxFunctionDefinitions, int maxFunctionArguments) {
    6358      var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>();
    6459
     
    6863      var selectedDefunBranch = functionDefiningBranches.SelectRandom(random);
    6964      // remove the selected defun
    70       int defunSubtreeIndex = symbolicExpressionTree.Root.SubTrees.IndexOf(selectedDefunBranch);
     65      int defunSubtreeIndex = symbolicExpressionTree.Root.IndexOfSubTree(selectedDefunBranch);
    7166      symbolicExpressionTree.Root.RemoveSubTree(defunSubtreeIndex);
    7267
     
    8580    }
    8681
    87     private static void DeletionByRandomRegeneration(IRandom random, SymbolicExpressionTree symbolicExpressionTree, DefunTreeNode selectedDefunBranch) {
     82    private static void DeletionByRandomRegeneration(IRandom random, ISymbolicExpressionTree symbolicExpressionTree, DefunTreeNode selectedDefunBranch) {
    8883      // find first invocation and replace it with a randomly generated tree
    8984      // can't find all invocations in one step because once we replaced a top level invocation
     
    9287                                from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>()
    9388                                where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName
    94                                 select new { Parent = node, ReplacedChildIndex = node.SubTrees.IndexOf(subtree), ReplacedChild = subtree }).FirstOrDefault();
     89                                select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).FirstOrDefault();
    9590      while (invocationCutPoint != null) {
    9691        // deletion by random regeneration
    97         SymbolicExpressionTreeNode replacementTree = null;
     92        ISymbolicExpressionTreeNode replacementTree = null;
    9893        var allowedSymbolsList = invocationCutPoint.Parent.GetAllowedSymbols(invocationCutPoint.ReplacedChildIndex).ToList();
    9994        var weights = allowedSymbolsList.Select(s => s.InitialFrequency);
     
    115110                              from subtree in node.SubTrees.OfType<InvokeFunctionTreeNode>()
    116111                              where subtree.Symbol.FunctionName == selectedDefunBranch.FunctionName
    117                               select new { Parent = node, ReplacedChildIndex = node.SubTrees.IndexOf(subtree), ReplacedChild = subtree }).FirstOrDefault();
     112                              select new { Parent = node, ReplacedChildIndex = node.IndexOfSubTree(subtree), ReplacedChild = subtree }).FirstOrDefault();
    118113      }
    119114    }
Note: See TracChangeset for help on using the changeset viewer.